-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25402][SQL] Null handling in BooleanSimplification #22390
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
Conversation
| case TrueLiteral Or _ => TrueLiteral | ||
| case _ Or TrueLiteral => TrueLiteral | ||
|
|
||
| case a And b if Not(a).semanticEquals(b) => FalseLiteral |
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.
how about
case a And b if Not(a).semanticEquals(b) || a.semanticEquals(Not(b)) =>
If(IsNull(a), null, FalseLiteral)
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
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
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.
How about
case a And b if Not(a).semanticEquals(b) || a.semanticEquals(Not(b)) =>
if (!a.nullable && !b.nullable) {
FalseLiteral
} else {
If(IsNull(a), Literal.create(null, a.dataType), FalseLiteral)
}
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 it should be
case a And b if Not(a).semanticEquals(b) || a.semanticEquals(Not(b)) =>
if (!a.nullable && !b.nullable) {
FalseLiteral
} else if (a.nullable) {
If(IsNull(a), Literal.create(null, a.dataType), FalseLiteral)
} else {
If(IsNull(b), Literal.create(null, b.dataType), FalseLiteral)
}
But the current code should work. As the condition Not(a).semanticEquals(b) || a.semanticEquals(Not(b)) is satisfied, in current code it is impossible that a is not nullable and b is nullable.
gengliangwang
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.
Otherwise LGTM 👍
| testRelation.output, Seq(Row(1, 2, 3, "abc")) | ||
| ) | ||
|
|
||
| val testNotnullableRelation = LocalRelation('a.int.notNull, 'b.int.notNull, 'c.int.notNull, |
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.
Nit: testNotnullableRelation => testNotNullableRelation
| 'd.string.notNull, 'e.boolean.notNull, 'f.boolean.notNull, 'g.boolean.notNull, | ||
| 'h.boolean.notNull) | ||
|
|
||
| val testNotnullableRelationWithData = LocalRelation.fromExternalRows( |
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.
testNotnullableRelationWithData => testNotNullableRelationWithData
|
Test build #95923 has finished for PR 22390 at commit
|
|
Test build #95955 has finished for PR 22390 at commit
|
|
LGTM |
gengliangwang
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.
LGTM
adrian-ionescu
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.
LGTM
|
Test build #95976 has finished for PR 22390 at commit
|
|
retest this please. |
|
Test build #95981 has finished for PR 22390 at commit
|
## What changes were proposed in this pull request? This PR is to fix the null handling in BooleanSimplification. In the rule BooleanSimplification, there are two cases that do not properly handle null values. The optimization is not right if either side is null. This PR is to fix them. ## How was this patch tested? Added test cases Closes #22390 from gatorsmile/fixBooleanSimplification. Authored-by: gatorsmile <[email protected]> Signed-off-by: Wenchen Fan <[email protected]> (cherry picked from commit 79cc597) Signed-off-by: Wenchen Fan <[email protected]>
## What changes were proposed in this pull request? This PR is to fix the null handling in BooleanSimplification. In the rule BooleanSimplification, there are two cases that do not properly handle null values. The optimization is not right if either side is null. This PR is to fix them. ## How was this patch tested? Added test cases Closes #22390 from gatorsmile/fixBooleanSimplification. Authored-by: gatorsmile <[email protected]> Signed-off-by: Wenchen Fan <[email protected]> (cherry picked from commit 79cc597) Signed-off-by: Wenchen Fan <[email protected]>
|
thanks, merging to master/2.4/2.3! |
|
can you send a new PR for 2.2? thanks |
This PR is to fix the null handling in BooleanSimplification. In the rule BooleanSimplification, there are two cases that do not properly handle null values. The optimization is not right if either side is null. This PR is to fix them. Added test cases Closes apache#22390 from gatorsmile/fixBooleanSimplification. Authored-by: gatorsmile <[email protected]> Signed-off-by: Wenchen Fan <[email protected]> (cherry picked from commit 79cc597) Signed-off-by: Wenchen Fan <[email protected]>
## What changes were proposed in this pull request? This PR is to fix the null handling in BooleanSimplification. In the rule BooleanSimplification, there are two cases that do not properly handle null values. The optimization is not right if either side is null. This PR is to fix them. ## How was this patch tested? Added test cases Closes apache#22390 from gatorsmile/fixBooleanSimplification. Authored-by: gatorsmile <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
What changes were proposed in this pull request?
This PR is to fix the null handling in BooleanSimplification. In the rule BooleanSimplification, there are two cases that do not properly handle null values. The optimization is not right if either side is null. This PR is to fix them.
How was this patch tested?
Added test cases