-
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
Numeric, String, Boolean comparisons with literal NULL
#2481
Conversation
cc @alamb @andygrove @yjshen @xudong963 |
stringify!($OP), | ||
))) | ||
// when the $RIGHT is a NULL, generate a NULL array of $OP_TYPE | ||
Ok(Arc::new(new_null_array($OP_TYPE, $LEFT.len()))) |
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 think we should respect
SortOptions
here for ScalaValue. - Question: how about the
NULL != column
case? Do we have an expression normalizer that asserts Nulls often coming as the right-hand operand for a binary comparison?
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.
@yjshen what do you mean SortOptions
? I don't think these expressions are used directly in ORDER BY clauses -- they are used instead for expressions like a < b
Adding some more tests in sql/expr.rs
for NULL < column
and NULL > column
sounds like a good idea.
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.
After checking Postgres and MySQL, I found I'm wrong on the expected behavior while comparing columns with NULL using <
>
..., they will return NULL in all cases. I was expecting to apply null first or null last while comparing column with NULL, so always true or always false at the first time.
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.
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 will spend some time writing the NULL != column
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.
Follow on PR: #2510 turns out there was a bug!
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.
stringify!($OP), | ||
))) | ||
// when the $RIGHT is a NULL, generate a NULL array of $OP_TYPE | ||
Ok(Arc::new(new_null_array($OP_TYPE, $LEFT.len()))) |
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.
@yjshen what do you mean SortOptions
? I don't think these expressions are used directly in ORDER BY clauses -- they are used instead for expressions like a < b
Adding some more tests in sql/expr.rs
for NULL < column
and NULL > column
sounds like a good idea.
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 @WinkerDu. I think the current behavior that always yields null while comparing with null is consistent with other systems, so no more efforts are required on this.
It would be nice to guarantee expression normalization exists and always have scalar value as the right operand after normalization. I think this goes beyond the scope of this PR and we could do it as follow-ups.
Thanks for your perseverance and nice work!
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.
stringify!($OP), | ||
))) | ||
// when the $RIGHT is a NULL, generate a NULL array of $OP_TYPE | ||
Ok(Arc::new(new_null_array($OP_TYPE, $LEFT.len()))) |
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 will spend some time writing the NULL != column
Which issue does this PR close?
Closes #1179 and #2482 .
Rationale for this change
This pr aims to solve Numeric, String, Boolean comparisons (Binary Expressions) with literal
NULL
For now, DF would fail when running the following SQLs:
What changes are included in this PR?
null_coercion
tocomparison_eq_coercion
andcomparison_order_coercion
NULL
scalar value comparing with array, likebinary_array_op_dyn_scalar
Are there any user-facing changes?
No.