Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/21904#discussion_r206318942
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
---
@@ -416,6 +450,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 e @ CaseWhen(branches, _) if
pruneSeenBranches(branches).nonEmpty =>
+ e.copy(branches = pruneSeenBranches(branches).get)
+
+ case e @ CaseWhen(branches, _) if
combineAdjacentBranches(branches).nonEmpty =>
+ e.copy(branches = combineAdjacentBranches(branches).get)
--- End diff --
Maybe:
```scala
case e @ CaseWhen(branches, _) =>
val prunedBranches = pruneSeenBranches(branches).getOrElse(branches)
val newBranches =
combineAdjacentBranches(prunedBranches).getOrElse(prunedBranches)
if (newBranches.length < branches.length) {
e.copy(branches = newBranches)
} else {
e
}
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]