Github user dongjoon-hyun commented on a diff in the pull request: https://github.com/apache/spark/pull/21850#discussion_r205172569 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala --- @@ -2813,4 +2813,16 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { checkAnswer(df, Seq(Row(3, 99, 1))) } } + + test("SPARK-24892: simplify `CaseWhen` to `If` when there is only one branch") { + withTable("t") { + Seq(Some(1), null, Some(3)).toDF("a").write.saveAsTable("t") + + val plan1 = sql("select case when a is null then 1 end col1 from t") + val plan2 = sql("select if(a is null, 1, null) col1 from t") + + checkAnswer(plan1, Row(null) :: Row(1) :: Row(null) :: Nil) + comparePlans(plan1.queryExecution.optimizedPlan, plan2.queryExecution.optimizedPlan) + } --- End diff -- Thank you for adding this higher level test, too.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org