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 (CASE WHEN bool#7 THEN I am not null END <=> null) ->
Filter CASE WHEN bool#7 THEN (I am not null <=> null) END -> // After
PushFoldableIntoBranches
Filter CASE WHEN bool#7 THEN (I am not null <=> null) ELSE false END ->
Filter (bool#7 AND (I am not null <=> null)) ->
Filter (bool#7 AND false) ->
Filter false
```
After this pr:
```
Filter (CASE WHEN bool#7 THEN I am not null END <=> null)->
Filter CASE WHEN bool#7 THEN (I am not null <=> null) ELSE (null <=> null)
END -> // After PushFoldableIntoBranches
Filter CASE WHEN bool#7 THEN (I am not null <=> null) ELSE true END ->
Filter (NOT coalesce(bool#7, false) OR (I am not null <=> null)) ->
Filter (NOT coalesce(bool#7, false) OR false) ->
Filter NOT coalesce(bool#7, false) ->
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]