viirya commented on a change in pull request #33142:
URL: https://github.com/apache/spark/pull/33142#discussion_r661597406



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/EquivalentExpressions.scala
##########
@@ -135,33 +125,47 @@ 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 _: CodegenFallback => Nil
     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)
+      val conditions = if (c.branches.length > 1) {

Review comment:
       This fixed 
https://github.com/apache/spark/pull/30245#discussion_r660870034. 
   
   > The only drawback is, if there are common subexpressions among the 
conditions, they will always be counted as "appear twice" and gets codegened 
into methods.
   
   I just don't get this. You mean for `If(a + b > 1, 1, a + b + c > 1, 2, a + 
b + c > 2, 3)`, `a + b + c` will be counted twice and considered as common 
subexpression?




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to