maropu commented on a change in pull request #29643:
URL: https://github.com/apache/spark/pull/29643#discussion_r483387646



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala
##########
@@ -168,6 +170,85 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]] 
extends TreeNode[PlanT
     }.toSeq
   }
 
+
+  /**
+   * Rewrites this plan tree based on the given plan mappings from old plan 
nodes to new nodes.
+   * This method also updates all the related references in this plan tree 
accordingly, in case
+   * the replaced node has different output expr ID than the old node.
+   */
+  def rewriteWithPlanMapping(
+      planMapping: Map[PlanType, PlanType],
+      canGetOutput: PlanType => Boolean = _ => true): PlanType = {
+    def internalRewrite(plan: PlanType): (PlanType, Seq[(Attribute, 
Attribute)]) = {
+      if (planMapping.contains(plan)) {

Review comment:
       IIUC this check cannot correctly handle nested cases in `planMapping`; 
for example,
   ```
   Project
    +- Union
       :+- (1) Project 
       :   +- Union
       :   :  :+- (2) Project
       :   :
       :   +- Project
       :
       +- Project
          +- ...
   ```
   If the two nested `Project`s above, `(1)` and `(2)`,  are stored in 
`planMapping`, I think only the case `(1)` is matched in this condition then 
the case `(2)` is just ignored. So, I rewrote the logic a bit so that plans are 
replaced in a bottom-up way in the previous PR:
   
https://github.com/apache/spark/blob/1de272f98d0ff22d0dd151797f22b8faf310963a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala#L140-L144




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

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