-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve codebase readability and error messages by and consistently handle downcasting #3152
Comments
cc @avantgardnerio and @jimexist and @Dandandan |
I think this is a good first issue because it will be largely mechanical and will give potential contributors wide exposure to the codebase |
this is attractive 👍 let me try this |
Hi. While this issue is getting old, I might help but have some questions. . I will give
pub fn as_int32_array(array: &dyn Array) -> Result<&Int32Array> {
array.as_any().downcast_ref::<Int32Array>().ok_or(
DataFusionError::Execution(format!("Expected a Int32Array, got: {}", array.data_type()),
))
} To this: let arg0 = as_int32_array(&args[0])?; Is this the correct way? |
I think that is reasonable. Or perhaps something like |
Thanks @retikulum -- that looks good to me What I would suggest is doing this in a series of smaller PRs -- perhaps add a few functions like That way we can then get feedback from the wider community before you spend a large amount of your time changing the entire codebase |
This is exactly what I planned. Moreover, I will not get lost in the ocean. Thanks for feedback @alamb |
Float32Array
, Float64Array
, StringArray
#4244
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
It is a common code pattern in DataFusion to downcast an
ArrayRef
to a concrete arrow array type.There are actually at least three patterns to do so in the datafusion codebase https://github.com/apache/arrow-datafusion/search?l=Rust&q=downcast
I think this leads to
Pattern 1:
downcast_ref()
panic
s on errorPattern 2: use
as_XXX_array
functions from arrowpanic
s on errorPattern 3: check type and return an error:
Returns an error to the user (a better behavior I think)
Describe the solution you'd like
I would like to use one consistent pattern throughout the codebase. Specifically I propose functions that do the error checking / error message generation:
And then change all dynamic casts in the codebase:
Describe alternatives you've considered
Leave the status quo
Additional context
Inspired by @avantgardnerio 's suggestion https://github.com/apache/arrow-datafusion/pull/3110/files#r945847871 (but this is not the first time it has come up)
The text was updated successfully, but these errors were encountered: