-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix comparison of decimal array with null scalar #3567
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
Merged
alamb
merged 1 commit into
apache:master
from
kmitchener:3487-fix-decimal-array-comparison-with-null-scalar
Sep 22, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,13 +120,33 @@ impl std::fmt::Display for BinaryExpr { | |
| } | ||
| } | ||
|
|
||
| macro_rules! compute_decimal_op_dyn_scalar { | ||
| ($LEFT:expr, $RIGHT:expr, $OP:ident, $OP_TYPE:expr) => {{ | ||
| let ll = $LEFT.as_any().downcast_ref::<Decimal128Array>().unwrap(); | ||
| if let ScalarValue::Decimal128(Some(_), _, _) = $RIGHT { | ||
| Ok(Arc::new(paste::expr! {[<$OP _decimal_scalar>]}( | ||
| ll, | ||
| $RIGHT.try_into()?, | ||
| )?)) | ||
| } else { | ||
| // when the $RIGHT is a NULL, generate a NULL array of $OP_TYPE type | ||
| Ok(Arc::new(new_null_array($OP_TYPE, $LEFT.len()))) | ||
| } | ||
| }}; | ||
| } | ||
|
|
||
| macro_rules! compute_decimal_op_scalar { | ||
| ($LEFT:expr, $RIGHT:expr, $OP:ident, $DT:ident) => {{ | ||
| let ll = $LEFT.as_any().downcast_ref::<$DT>().unwrap(); | ||
| Ok(Arc::new(paste::expr! {[<$OP _decimal_scalar>]}( | ||
| ll, | ||
| $RIGHT.try_into()?, | ||
| )?)) | ||
| let ll = $LEFT.as_any().downcast_ref::<Decimal128Array>().unwrap(); | ||
| if let ScalarValue::Decimal128(Some(_), _, _) = $RIGHT { | ||
| Ok(Arc::new(paste::expr! {[<$OP _decimal_scalar>]}( | ||
| ll, | ||
| $RIGHT.try_into()?, | ||
| )?)) | ||
| } else { | ||
| // when the $RIGHT is a NULL, generate a NULL array of LEFT's datatype | ||
| Ok(Arc::new(new_null_array($LEFT.data_type(), $LEFT.len()))) | ||
| } | ||
| }}; | ||
| } | ||
|
|
||
|
|
@@ -642,7 +662,7 @@ macro_rules! binary_array_op_dyn_scalar { | |
|
|
||
| let result: Result<Arc<dyn Array>> = match right { | ||
| ScalarValue::Boolean(b) => compute_bool_op_dyn_scalar!($LEFT, b, $OP, $OP_TYPE), | ||
| ScalarValue::Decimal128(..) => compute_decimal_op_scalar!($LEFT, right, $OP, Decimal128Array), | ||
| ScalarValue::Decimal128(..) => compute_decimal_op_dyn_scalar!($LEFT, right, $OP, $OP_TYPE), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ you are starting to figure out the thicket that is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah :) and what a pleasure it is |
||
| ScalarValue::Utf8(v) => compute_utf8_op_dyn_scalar!($LEFT, v, $OP, $OP_TYPE), | ||
| ScalarValue::LargeUtf8(v) => compute_utf8_op_dyn_scalar!($LEFT, v, $OP, $OP_TYPE), | ||
| ScalarValue::Binary(v) => compute_binary_op_dyn_scalar!($LEFT, v, $OP, $OP_TYPE), | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we assert here that
$RIGHTis still a decimal ? As written the code could convertScalarValue::Int8(Some(4))into NULL, for exampleBut I don't know if such a
ScalarValuecould be passedThere 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 don't think we need to. Those 2 decimal macros are used only in 1 place each and include "decimal" in the name -- it'd be a clear mistake to use it for any other datatype. This area could use some refactoring, but I wanted to get this in and the kernels moved to arrow-rs then maybe revisit this whole module (famous last words, right?).
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.
famous last words maybe, but a reasonable plan nonetheless ;)