cloud-fan commented on code in PR #49202:
URL: https://github.com/apache/spark/pull/49202#discussion_r1896527062


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RewriteWithExpression.scala:
##########
@@ -96,14 +96,17 @@ object RewriteWithExpression extends Rule[LogicalPlan] {
         val defs = w.defs.map(rewriteWithExprAndInputPlans(_, inputPlans, 
isNestedWith = true))
         val refToExpr = mutable.HashMap.empty[CommonExpressionId, Expression]
         val childProjections = 
Array.fill(inputPlans.length)(mutable.ArrayBuffer.empty[Alias])
+        val refsCount = child.collect { case r: CommonExpressionRef => r}

Review Comment:
   we should only collect references to the current `With`, not the nested 
`With`.
   ```suggestion
           val refsCount = child.collect { case r: CommonExpressionRef if 
defs.exists(_.id == r.id) => r}
   ```



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