-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Improve Error Handling and Readibility for downcasting Date32Array
#4004
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 Error Handling and Readibility for downcasting Date32Array
#4004
Conversation
alamb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @retikulum -- looks neat. I left some suggestions but basically this is the right track I think
what do you think @avantgardnerio ?
| DataType::Date32 => match as_date32_array($ARRAY) { | ||
| Ok(array) => Ok($FN(array)?), | ||
| Err(e) => Err(e), | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to make this even more concise like
| DataType::Date32 => match as_date32_array($ARRAY) { | |
| Ok(array) => Ok($FN(array)?), | |
| Err(e) => Err(e), | |
| }, | |
| DataType::Date32 => $FN(match as_date32_array($ARRAY)?), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find an appropriate way to implement this. It seems that it has to be wrapped around Ok or Err to return Result.
I 100% agree with the intent of the PR: even if they "never happen at run time" panics (and unwraps, etc) create cognitive load on the programmer to mentally statically prove that to themselves every time they look at the code, so we should just eliminate them to the extent possible. As far as implementation, as I become more proficient at Rust, I increasingly see the importance of like this being discoverable... is it possible to make this change in |
avantgardnerio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @alamb 's feedback, but the real blocker for me is the println! error swallowing.
datafusion/row/src/writer.rs
Outdated
| to.set_date32(col_idx, from.value(row_idx)); | ||
| match as_date32_array(from) { | ||
| Ok(from) => to.set_date32(col_idx, from.value(row_idx)), | ||
| Err(e) => println!("{}", e), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO logging here is worse than unwrapping. The function is called write_field_date32() and if a date32 wasn't written to something, abending is preferable to carrying on in an in-determinant state. (of course, returning an Err Result would be even more preferable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree I prefer "unwrap()" rather than println -- stdout may or may not be connected to something which would be noticed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems reasonable to me. I will fix it and be more careful in future PRs.
Thanks for great feedback @alamb . Your recommendations generally improve my style to write Rust. I will make necessary changes.
Hi @avantgardnerio. Thanks for the feedback and for joining the conversation. As far as I understand, We are on right track but we need to decide how to implement those changes. Also, this is discussed in #3152. @alamb what do you think about implementation? Should we continue creating functions in |
We are all learning this together! Thank you for all your contributions so far |
|
Since there were no more comments, I fixed the suggested parts. |
avantgardnerio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see several less panics in our code!
|
I agree -- we are making progress -- I figured I would merge this PR in and we can continue to improve the code as follow on PRs |
|
Benchmark runs are scheduled for baseline = bec3856 and contender = eb86b07. eb86b07 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
…pache#4004) * improve error messages for date32array * fix clippy errors - change ok_or to ok_or_else * changes after review
Which issue does this PR close?
Part of #3152.
Rationale for this change
It is very clear in the issue but there are different schemas while downcasting an ArrayRef to a related arrow array type. This is the first PR of improving downcasting to arrow array types. As it is seen, this PR is small but I am hoping to see what I am doing right and wrong.
What changes are included in this PR?
datafusion\common\src\cast.rsis created. Moreover, I think future downcasting functions will be written in it.Are there any user-facing changes?
I am not sure about it.