-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-29162][SQL] Simplify NOT(IsNull(x)) and NOT(IsNotNull(x)) #25878
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
|
gentle ping @juliuszsompolski |
| Literal.create(null, e.dataType) | ||
|
|
||
| case n@Not(expr: IsNull) => IsNotNull(expr.child) | ||
| case n@Not(expr: IsNotNull) => IsNull(expr.child) |
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.
Why do you handle this in NullPropagation?
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.
Also, plz check the code style carefully?
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.
Also, plz check the code style carefully?
Sorry, forget to check this place...
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.
Why do you handle this in NullPropagation?
Don't found other better place, and it's also NULL expression problem.
Or add a new class?
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.
Yea, the @viirya suggestion looks nice to me.
|
ok to test |
|
Test build #111122 has finished for PR 25878 at commit
|
| } | ||
|
|
||
| case n @ Not(expr: IsNull) => IsNotNull(expr.child) | ||
| case n @ Not(expr: IsNotNull) => IsNull(expr.child) |
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.
you don't need n.
| } | ||
|
|
||
| private def assertFilter(originalExpr: Expression, | ||
| expectedExpr: Expression): Unit = { |
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.
indent is wrong.
| e.copy(branches = branches.take(i).map(branch => (branch._1, elseValue))) | ||
| } | ||
|
|
||
| case n @ Not(expr: IsNull) => IsNotNull(expr.child) |
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.
IsNull and IsNotNull are conditional expressions? Seems BooleanSimplification is more suitable.
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.
conditional
Reasonable, I focus too much on isnull/isnotnull expression。
| } | ||
| } | ||
|
|
||
| test("SPARK-29152: Simplify NOT(IsNull(x)) and NOT(IsNotNull(x))") { |
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: I personally think the SimplifyConditionalSuite test is enough for this fix.
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: I personally think the
SimplifyConditionalSuitetest is enough for this fix.
Yeah, seems end-to-end test in SQLQuerySuit is redundant
| } | ||
|
|
||
| test("simplify NOT(IsNull(x)) and NOT(IsNotNull(x))") { | ||
| assertFilter(Not(IsNotNull(UnresolvedAttribute("b"))), IsNull(UnresolvedAttribute("b"))) |
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.
We cannot use assertEquivalent here?
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.
We cannot use
assertEquivalenthere?
assertEquivalent use OneRowRelation, no column, so I add a testRelation.
I will remove it to BooleanSimplificationSuit .
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 @HyukjinKwon @viirya
| case Not(Not(e)) => e | ||
|
|
||
| case Not(expr: IsNull) => IsNotNull(expr.child) | ||
| case Not(expr: IsNotNull) => IsNull(expr.child) |
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. expr -> e.
case Not(e: IsNull) => IsNotNull(e.child)
case Not(e: IsNotNull) => IsNull(e.child)
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.
expr->e.
How about
case Not(IsNull(e)) => IsNotNull(e)
case Not(IsNotNull(e)) => IsNull(e)
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.
Better!
| test("simplify NOT(IsNull(x)) and NOT(IsNotNull(x))") { | ||
| checkCondition(Not(IsNotNull(UnresolvedAttribute("b"))), IsNull(UnresolvedAttribute("b"))) | ||
| checkCondition(Not(IsNull(UnresolvedAttribute("b"))), IsNotNull(UnresolvedAttribute("b"))) | ||
| } |
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.
@AngersZhuuuu . Since you are active contribution, I'd like to recommend to use DSL as possible as you can. (Please refer the other tests.)
test("simplify NOT(IsNull(x)) and NOT(IsNotNull(x))") {
checkCondition(Not(IsNotNull('e)), IsNull('e))
checkCondition(Not(IsNull('e)), IsNotNull('e))
}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.
@AngersZhuuuu . Since you are active contribution, I'd like to recommend to use DSL as possible as you can. (Please refer the other tests.)
First time use DSL, I will get to know DSL more
|
@AngersZhuuuu . Thank you for your contributions. I left two minor comments. Please address them. |
Thank you for your advise. All for better job. |
|
Test build #111131 has finished for PR 25878 at commit
|
|
Test build #111133 has finished for PR 25878 at commit
|
|
Test build #111142 has finished for PR 25878 at commit
|
Can you trigger restart test. Thanks . |
|
retest this please |
|
Test build #111156 has finished for PR 25878 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. Merged to master. Thank you all!
What changes were proposed in this pull request?
Rewrite
Why are the changes needed?
Make LogicalPlan more readable and useful for query canonicalization. Make same condition equal when judge query canonicalization equal
Does this PR introduce any user-facing change?
NO
How was this patch tested?
Newly added UTs.