Hisoka-X commented on code in PR #41347:
URL: https://github.com/apache/spark/pull/41347#discussion_r1262394603


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/DeduplicateRelations.scala:
##########
@@ -117,37 +311,49 @@ object DeduplicateRelations extends Rule[LogicalPlan] {
           }
         }
 
-        val planWithNewSubquery = plan.transformExpressions {
-          case subquery: SubqueryExpression =>
-            val (renewed, changed) = 
renewDuplicatedRelations(existingRelations, subquery.plan)
-            if (changed) planChanged = true
-            subquery.withNewPlan(renewed)
-        }
+        val (newPlan, changed) = getNewPlanWithNewChildren(existingRelations, 
newChildren.toArray,
+          plan, planChanged)
+        planChanged |= changed
+        newPlan
+      } else {
+        plan
+      }
+      (newPlan, planChanged)
+  }
 
-        if (planChanged) {
-          if (planWithNewSubquery.childrenResolved) {
-            val planWithNewChildren = 
planWithNewSubquery.withNewChildren(newChildren.toSeq)
-            val attrMap = AttributeMap(
-              plan
-                .children
-                .flatMap(_.output).zip(newChildren.flatMap(_.output))
-                .filter { case (a1, a2) => a1.exprId != a2.exprId }
-            )
-            if (attrMap.isEmpty) {
-              planWithNewChildren
-            } else {
-              planWithNewChildren.rewriteAttrs(attrMap)
-            }
-          } else {
-            planWithNewSubquery.withNewChildren(newChildren.toSeq)
-          }
-        } else {
+  private def getNewPlanWithNewChildren(

Review Comment:
   you mean put `renewDuplicatedRelations` and `getNewPlanWithNewChildren` 
together? (Hard to do that, if child not only one, we could invoke 
renewDuplicatedRelations more than once to get children, then can invoke 
getNewPlanWithNewChildren)
   
   Or create inner method?



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