cloud-fan commented on a change in pull request #33284:
URL: https://github.com/apache/spark/pull/33284#discussion_r670986145



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala
##########
@@ -435,6 +435,28 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]]
     subqueries ++ subqueries.flatMap(_.subqueriesAll)
   }
 
+  /**
+   * Returns a copy of this node where the given partial function has been 
recursively applied
+   * first to this node's children, then this node's subqueries, and finally 
this node itself
+   * (post-order). When the partial function does not apply to a given node, 
it is left unchanged.
+   */
+  def transformUpWithSubqueries(f: PartialFunction[PlanType, PlanType]): 
PlanType = {
+    val g: PartialFunction[PlanType, PlanType] = new PartialFunction[PlanType, 
PlanType] {
+      override def isDefinedAt(x: PlanType): Boolean = true
+
+      override def apply(plan: PlanType): PlanType = {
+        val transformed = plan transformExpressionsUp {
+          case planExpression: PlanExpression[PlanType] =>
+            val newPlan = planExpression.plan.transformUpWithSubqueries(f)
+            planExpression.withNewPlan(newPlan)
+        }
+        f.applyOrElse[PlanType, PlanType](transformed, identity)
+      }
+    }
+
+    transformUp(g)

Review comment:
       nit:
   ```
   transformUp { case plan =>
     val transformed = plan transformExpressionsUp {
       case planExpression: PlanExpression[PlanType] =>
         val newPlan = planExpression.plan.transformUpWithSubqueries(f)
         planExpression.withNewPlan(newPlan)
     }
     f.applyOrElse[PlanType, PlanType](transformed, identity)
   }
   ```




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