You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/12/16 01:38:29 UTC
[GitHub] [spark] wangyum commented on a change in pull request #30790: [SPARK-33798][SQL] Simplify EqualTo(CaseWhen/If, Literal) always false
wangyum commented on a change in pull request #30790:
URL: https://github.com/apache/spark/pull/30790#discussion_r543813194
##########
File path: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/SimplifyConditionalSuite.scala
##########
@@ -199,4 +199,97 @@ class SimplifyConditionalSuite extends PlanTest with ExpressionEvalHelper with P
If(Factorial(5) > 100L, b, nullLiteral).eval(EmptyRow))
}
}
+
+ test("SPARK-33798: simplify EqualTo(If, Literal) always false") {
+ val a = EqualTo(UnresolvedAttribute("a"), Literal(100))
+ val ifExp = If(a === Literal(1), Literal(2), Literal(3))
+
+ assertEquivalent(EqualTo(ifExp, Literal(4)), FalseLiteral)
+ assertEquivalent(EqualTo(ifExp, Literal(3)), EqualTo(ifExp, Literal(3)))
+ assertEquivalent(EqualTo(ifExp, Literal("4")), FalseLiteral)
+ assertEquivalent(EqualTo(ifExp, Literal("3")), EqualTo(ifExp, Literal(3)))
+
+ // Do not simplify if it contains non foldable expressions.
+ assertEquivalent(EqualTo(ifExp, NonFoldableLiteral(true)),
+ EqualTo(ifExp, NonFoldableLiteral(true)))
+ val nonFoldable = If(NonFoldableLiteral(true), Literal(1), Literal(2))
+ assertEquivalent(EqualTo(nonFoldable, Literal(1)), EqualTo(nonFoldable, Literal(1)))
+
+ // Do not simplify if it contains non-deterministic expressions.
+ val nonDeterministic = If(LessThan(Rand(1), Literal(0.5)), Literal(1), Literal(1))
+ assert(!nonDeterministic.deterministic)
+ assertEquivalent(EqualTo(nonDeterministic, Literal(-1)), EqualTo(nonDeterministic, Literal(-1)))
+
+ // null check, SPARK-33798 will not change these behaviors.
+ assertEquivalent(
+ EqualTo(If(FalseLiteral, Literal(null, IntegerType), Literal(1)), Literal(1)),
+ TrueLiteral)
+ assertEquivalent(
+ EqualTo(If(TrueLiteral, Literal(null, IntegerType), Literal(1)), Literal(1)),
+ Literal(null, BooleanType))
+ assertEquivalent(
+ EqualTo(If(FalseLiteral, Literal(null, IntegerType), Literal(null, IntegerType)), Literal(1)),
+ Literal(null, BooleanType))
+
+ assertEquivalent(
+ EqualTo(If(FalseLiteral, Literal(1), Literal(2)), Literal(null, IntegerType)),
+ Literal(null, BooleanType))
+ assertEquivalent(
+ EqualTo(If(TrueLiteral, Literal(1), Literal(2)), Literal(null, IntegerType)),
+ Literal(null, BooleanType))
Review comment:
SPARK-33798 will not change these behaviors.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org