bhollis-dbx commented on code in PR #59283:
URL: https://github.com/apache/spark/pull/59283#discussion_r4290784139
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/EquivalentExpressions.scala:
##########
@@ -173,6 +172,29 @@ class EquivalentExpressions(
case other => other.children
}
+ private def alwaysEvaluatedDefinitions(withExpr: With): Seq[Expression] = {
+ val definitions = withExpr.defs.map(definition => definition.id ->
definition).toMap
+ val required = mutable.HashSet.empty[CommonExpressionId]
+ def collect(expression: Expression, shadowed: Set[CommonExpressionId]):
Unit = {
+ val alwaysEvaluated = skipForShortcut(expression)
+ if (alwaysEvaluated.containsPattern(COMMON_EXPR_REF)) {
+ alwaysEvaluated match {
+ case ref: CommonExpressionRef if !shadowed.contains(ref.id) =>
+ definitions.get(ref.id).foreach { definition =>
+ if (required.add(ref.id)) collect(definition.child, Set.empty)
+ }
+ case nested: With =>
+ val innerIds = shadowed ++ nested.defs.map(_.id)
+ childrenToRecurse(nested).foreach(collect(_, innerIds))
Review Comment:
Fixed in fc1ac8505. Definition discovery now walks each nested With body
once, following reached definitions in their enclosing scope instead of
recursively rediscovering them. Added a counted-work regression at depths 10
and 30; it fails before the fix and passes afterward, while preserving expected
common subexpressions.
--
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]