wangyum commented on a change in pull request #34580:
URL: https://github.com/apache/spark/pull/34580#discussion_r749259469



##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/PushFoldableIntoBranchesSuite.scala
##########
@@ -356,4 +356,27 @@ class PushFoldableIntoBranchesSuite
       EqualTo(CaseWhen(Seq(('a > 10, Literal(0))), Literal(1)), Literal(1)),
       Not('a > 10 <=> TrueLiteral))
   }
+
+  test("SPARK-37270: Fix push foldable into CaseWhen branches if elseValue is 
empty") {
+    assertEquivalent(
+      IsNull(CaseWhen(Seq(('a > 10, Literal(0))), Literal(1))),
+      FalseLiteral)
+    assertEquivalent(
+      IsNull(CaseWhen(Seq(('a > 10, Literal(0))))),
+      !('a > 10 <=> true))
+
+    assertEquivalent(
+      CaseWhen(Seq(('a > 10, Literal(0))), Literal(1)) <=> Literal(null, 
IntegerType),

Review comment:
       This is an example:
   ```scala
   spark.sql("CREATE TABLE t1(bool boolean, number int) using parquet")
   spark.sql("INSERT INTO t1 VALUES(false, 1)")
   
   spark.sql(
     """
       |SELECT *
       |FROM   (SELECT *,
       |               CASE
       |                 WHEN bool THEN 'I am not null'
       |               END AS conditions
       |        FROM   t1) t
       |WHERE  conditions <=> NULL
       |""".stripMargin).show
   ```
   
   
   Before this pr:
   ```
   Filter isnull(CASE WHEN bool#7 THEN I am not null END) ->
   Filter CASE WHEN bool#7 THEN isnull(I am not null) END -> // After 
PushFoldableIntoBranches
   Filter (bool#7 AND isnull(I am not null)) ->
   Filter (bool#7 AND false) ->
   Filter false
   ```
   
   After this pr:
   ```
   Filter isnull(CASE WHEN bool#7 THEN I am not null END) -> 
   Filter CASE WHEN bool#7 THEN isnull(I am not null) ELSE isnull(null) END -> 
// After PushFoldableIntoBranches
   Filter CASE WHEN bool#7 THEN false ELSE isnull(null) END -> 
   Filter CASE WHEN bool#7 THEN false ELSE true END -> 
   Filter NOT (bool#7 <=> true)
   ```




-- 
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.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to