Github user dbtsai commented on a diff in the pull request:
https://github.com/apache/spark/pull/21852#discussion_r206266243
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
---
@@ -416,6 +416,23 @@ 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 e @ CaseWhen(branches, Some(elseValue)) if {
+ val values = branches.map(_._2) :+ elseValue
+ values.tail.forall(values.head.semanticEquals)
--- End diff --
I think what you suggested is the same as the implemented code in the PR,
and `elseValue.deterministic` is not required since it is checked in
`semanticEquals`.
Being said that, the whole condition can be replaced by
`branches.exists(_._2.semanticEquals(elseValue))`
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]