cloud-fan commented on a change in pull request #30790:
URL: https://github.com/apache/spark/pull/30790#discussion_r544345329
##########
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 b = UnresolvedAttribute("b")
+ val ifExp = If(a, 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(If(a, b, Literal(2)), Literal(3)),
+ EqualTo(If(a, b, Literal(2)), Literal(3)))
+ val nonFoldable = If(NonFoldableLiteral(true), Literal(1), Literal(2))
Review comment:
`NonFoldableLiteral` is nothing special comparing to `'a == 100`, as
they are both non-foldable. I think we don't need to test with
`NonFoldableLiteral`
----------------------------------------------------------------
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]