Skip to content

Commit 442f908

Browse files
heyihongcloud-fan
authored andcommitted
[SPARK-54905][SQL] Simplify foreachWithSubqueries implementation in QueryPlan
### What changes were proposed in this pull request? This PR simplifies the foreachWithSubqueries method in QueryPlan.scala by: 1. Directly traversing both subqueries and children using the same traverse function 2. Replacing the indirect foreach(actualFunc) call with a direct traverse(this) call ### Why are the changes needed? The original implementation was unnecessarily complex, using foreach to traverse children implicitly while recursively calling foreachWithSubqueries for subqueries. The new implementation is simpler and more straightforward. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Existing tests for query plan traversal should cover this change. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Cursor 2.2.44 Closes #53681 from heyihong/SPARK-54905. Authored-by: Yihong He <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent 6df8d57 commit 442f908

File tree

1 file changed

+3
-5
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans

1 file changed

+3
-5
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,9 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]]
623623
* A variant of [[foreach]] which considers plan nodes inside subqueries as well.
624624
*/
625625
def foreachWithSubqueries(f: PlanType => Unit): Unit = {
626-
def actualFunc(plan: PlanType): Unit = {
627-
f(plan)
628-
plan.subqueries.foreach(_.foreachWithSubqueries(f))
629-
}
630-
foreach(actualFunc)
626+
f(this)
627+
subqueries.foreach(_.foreachWithSubqueries(f))
628+
children.foreach(_.foreachWithSubqueries(f))
631629
}
632630

633631
/**

0 commit comments

Comments
 (0)