peter-toth commented on a change in pull request #33281:
URL: https://github.com/apache/spark/pull/33281#discussion_r667363148



##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/SubexpressionEliminationSuite.scala
##########
@@ -323,6 +323,34 @@ class SubexpressionEliminationSuite extends SparkFunSuite 
with ExpressionEvalHel
     assert(commonExprs.head.expr eq add3)
   }
 
+  test("SPARK-36073: SubExpr elimination should include common child exprs of 
conditional " +
+    "expressions") {
+    val add = Add(Literal(1), Literal(2))
+    val ifExpr1 = If(Literal(true), add, Literal(3))
+    val ifExpr3 = If(GreaterThan(add, Literal(4)), Add(ifExpr1, add), 
Multiply(ifExpr1, add))
+
+    val equivalence = new EquivalentExpressions
+    equivalence.addExprTree(ifExpr3)

Review comment:
       This test actually proves that the new `updateExprTree(stats.expr, 
localEquivalenceMap, -stats.useCount)` approach fixes a bug as well.
   Before this PR `equivalence.getAllExprStates(1)` didn't return anything 
because the `notChild` filter at 
https://github.com/apache/spark/pull/33281/files#diff-4d8c210a38fc808fef3e5c966b438591f225daa3c9fd69359446b94c351aa11eL90-L92
 filtered out all child expressions (including `add`) of the common expression 
`ifExpr1`. But it should filter out only its children "defined by" 
`childrenToRecurse()` and `commonChildrenToRecurse()`. This new approach in the 
PR, that removes `ifExpr1` from `localEquivalenceMap`, keeps `add` in 
`localEquivalenceMap` and then adds `add` to `map` (in the 2nd iteration of the 
loop) and so `add` is will have useCount = 2 in the end.




-- 
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