Github user viirya commented on a diff in the pull request: https://github.com/apache/spark/pull/21852#discussion_r205309619 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala --- @@ -416,6 +416,21 @@ 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 list = branches.map(_._2) :+ elseValue + list.tail.forall(list.head.semanticEquals) + } => + // For non-deterministic conditions with side effect, we can not remove it. + // Since the output of all the branches are semantic equivalence, `elseValue` + // is picked for all the branches. + val newBranches = branches.map(_._1).filter(!_.deterministic).map(cond => (cond, elseValue)) --- End diff -- All conds must be deterministic, otherwise a non deterministic one not run before can be run after this rule.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org