cloud-fan commented on a change in pull request #32987:
URL: https://github.com/apache/spark/pull/32987#discussion_r661476268



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/EquivalentExpressions.scala
##########
@@ -134,24 +154,18 @@ class EquivalentExpressions {
 
   // For some special expressions we cannot just recurse into all of its 
children, but we can
   // recursively add the common expressions shared between all of its children.
-  private def commonChildrenToRecurse(expr: Expression): Seq[Seq[Expression]] 
= expr match {
-    case i: If => Seq(Seq(i.trueValue, i.falseValue))
-    case c: CaseWhen =>
-      // We look at subexpressions in conditions and values of `CaseWhen` 
separately. It is
-      // because a subexpression in conditions will be run no matter which 
condition is matched
-      // if it is shared among conditions, but it doesn't need to be shared in 
values. Similarly,
-      // a subexpression among values doesn't need to be in conditions because 
no matter which
-      // condition is true, it will be evaluated.
-      val conditions = c.branches.tail.map(_._1)
-      // For an expression to be in all branch values of a CaseWhen statement, 
it must also be in
-      // the elseValue.
-      val values = if (c.elseValue.nonEmpty) {
-        c.branches.map(_._2) ++ c.elseValue
-      } else {
-        Nil
-      }
-      Seq(conditions, values)
-    case c: Coalesce => Seq(c.children.tail)
+  private def commonChildrenToRecurse(expr: Expression): Seq[Expression] = 
expr match {
+    case i: If => Seq(i.trueValue, i.falseValue)
+    case c: CaseWhen if c.elseValue.nonEmpty => c.branches.map(_._2) ++ 
c.elseValue
+    case _ => Nil
+  }
+
+  // Finds expressions that are conditionally evaluated, so that if they are 
definitely evaluated
+  // elsewhere, we can create a subexpression to optimize the conditional case.
+  private def conditionallyEvaluatedChildren(expr: Expression): 
Seq[Expression] = expr match {

Review comment:
       I feel it's a bit more overcomplicated: now we have childen, 
commonChildren, conditionallyEvaluatedChildren.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to