Github user dongjoon-hyun commented on a diff in the pull request:
https://github.com/apache/spark/pull/21850#discussion_r204556169
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
---
@@ -414,6 +414,12 @@ object SimplifyConditionals extends Rule[LogicalPlan]
with PredicateHelper {
// these branches can be pruned away
val (h, t) = branches.span(_._1 != TrueLiteral)
CaseWhen( h :+ t.head, None)
+
+ case CaseWhen(branches, elseValue) if branches.length == 1 =>
+ val cond = branches.head._1
+ val trueValue = branches.head._2
+ val falseValue = elseValue.getOrElse(Literal(null,
trueValue.dataType))
+ If(cond, trueValue, falseValue)
--- End diff --
Can we simplify more like the following pattern?
```scala
- case CaseWhen(branches, elseValue) if branches.length == 1 =>
- val cond = branches.head._1
- val trueValue = branches.head._2
- val falseValue = elseValue.getOrElse(Literal(null,
trueValue.dataType))
- If(cond, trueValue, falseValue)
+ case e @ CaseWhen((cond, branchValue) :: Nil, elseValue) =>
+ If(cond, branchValue, elseValue.getOrElse(Literal(null,
e.dataType)))
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]