sunchao commented on a change in pull request #29603:
URL: https://github.com/apache/spark/pull/29603#discussion_r480846770
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -465,6 +465,8 @@ object SimplifyConditionals extends Rule[LogicalPlan] with
PredicateHelper {
if cond.deterministic && trueValue.semanticEquals(falseValue) =>
trueValue
case If(cond, l @ Literal(null, _), FalseLiteral) if !cond.nullable =>
And(cond, l)
case If(cond, l @ Literal(null, _), TrueLiteral) if !cond.nullable =>
Or(Not(cond), l)
+ case If(cond, FalseLiteral, l @ Literal(null, _)) if !cond.nullable =>
And(Not(cond), l)
+ case If(cond, TrueLiteral, l @ Literal(null, _)) if !cond.nullable =>
Or(cond, l)
Review comment:
Hmm that will break each of these into two lines which may affect
readability, also I think given these are already `Literal(null, _)`, naming
the variable to `nullLiteral` doesn't add much value maybe?
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/SimplifyConditionalSuite.scala
##########
@@ -166,29 +166,37 @@ class SimplifyConditionalSuite extends PlanTest with
ExpressionEvalHelper with P
)
}
- test("simplify if when then clause is null and else clause is boolean") {
+ test("simplify if when one clause is null and another is boolean") {
val p = IsNull('a)
val nullLiteral = Literal(null, BooleanType)
assertEquivalent(If(p, nullLiteral, FalseLiteral), And(p, nullLiteral))
assertEquivalent(If(p, nullLiteral, TrueLiteral), Or(IsNotNull('a),
nullLiteral))
+ assertEquivalent(If(p, FalseLiteral, nullLiteral), And(IsNotNull('a),
nullLiteral))
+ assertEquivalent(If(p, TrueLiteral, nullLiteral), Or(IsNull('a),
nullLiteral))
Review comment:
Will do.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]