-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
[SPARK-33845][SQL][FOLLOWUP] fix SimplifyConditionals #30953
Conversation
(originalExpr, expectedExpr) <- exprs) { | ||
val inputRow = create_row(condVal, condNullableVal, aVal, bVal) | ||
val optimizedVal = evaluateWithoutCodegen(expectedExpr, inputRow) | ||
checkEvaluation(originalExpr, optimizedVal, inputRow) |
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.
Check result here to make sure there is no correctness issue.
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!
@@ -56,6 +55,12 @@ object ReplaceNullWithFalseInPredicate extends Rule[LogicalPlan] { | |||
case d @ DeleteFromTable(_, Some(cond)) => d.copy(condition = Some(replaceNullWithFalse(cond))) | |||
case u @ UpdateTable(_, _, Some(cond)) => u.copy(condition = Some(replaceNullWithFalse(cond))) | |||
case p: LogicalPlan => p transformExpressions { | |||
// For `EqualNullSafe` with a `TrueLiteral`, whether the other side is null or false has no | |||
// difference, as `null <=> true` and `false <=> true` both return false. | |||
case EqualNullSafe(left, TrueLiteral) => |
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.
The change is needed here to not fail the existing tests. When we convert If
to EqualNullSafe
, we should make sure the rule ReplaceNullWithFalseInPredicate
still applies.
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 would be great if someone can pull this out and open a separated PR/JIRA. Otherwise, I'll do it tomorrow.
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.
NullPropagation
should optimize EqualNullSafe(null, TrueLiteral)
to false too, isn't?
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 can, but not with And
, e.g. EqualNullSafe(col && null, true)
=> EqualNullSafe(col && false, true)
=> EqualNullSafe(false, true)
=> false
.
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.
Oh I see. Makes sense.
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.
Good catch!
Test build #133457 has finished for PR 30953 at commit
|
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.
+1, LGTM. Thank you, @cloud-fan and @viirya .
Merged to master.
Late LGTM. |
Thanks, LGTM |
good catch, late lgtm |
What changes were proposed in this pull request?
This is a followup of #30849, to fix a correctness issue caused by null value handling.
Why are the changes needed?
Fix a correctness issue.
If(null, true, false)
should return false, not true.Does this PR introduce any user-facing change?
Yes, but the bug only exist in the master branch.
How was this patch tested?
updated tests.