-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support binary mathematical operators work with NULL
literals
#2610
Conversation
NULL
NULL
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.
Love it -- thank you @WinkerDu
Keep the code train moving 🚋
@@ -412,6 +412,15 @@ pub fn is_numeric(dt: &DataType) -> bool { | |||
} | |||
} | |||
|
|||
/// Determine if at least of one of lhs and rhs is numeric, and the other must be NULL or numeric | |||
fn both_numeric_or_null_and_numeric(lhs_type: &DataType, rhs_type: &DataType) -> bool { |
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.
👍
&ll, | ||
$RIGHT.try_into()?, | ||
)?)) | ||
match $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.
I wonder if you could use ScalarValue::is_null()
here rather than having to expand the macros out more
https://github.com/apache/arrow-datafusion/blob/master/datafusion/common/src/scalar.rs#L627
?
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.
nice catch!
@@ -282,7 +282,7 @@ fn mathematics_numerical_coercion( | |||
use arrow::datatypes::DataType::*; | |||
|
|||
// error on any non-numeric type |
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.
// error on any non-numeric type | |
// error on any not numeric/null type |
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.
LGTM after fix review.
Thanks @WinkerDu ❤️.
cc @alamb PTAL, thank you |
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.
NULL
NULL
literals
Thanks @WinkerDu and @jackwener -- 🤗 |
…he#2610) * binary mathematical operator with NULL * code clean
Which issue does this PR close?
Closes #2609 .
Rationale for this change
There is bug when binary mathematical operators
+
,-
,*
,/
,%
work with literalNULL
To reproduce
Postgres works like
What changes are included in this PR?
mathematics_numerical_coercion
inbinary_rule.rs
, make it work well on condition that at most one side of lhs or rhs isNULL
compute_op_scalar
macro inbinary.rs
to produceNULL
array when scalar value isNULL
Are there any user-facing changes?
No.