This is an automated email from the ASF dual-hosted git repository.
wenchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 442f9083c0cb [SPARK-54905][SQL] Simplify foreachWithSubqueries
implementation in QueryPlan
442f9083c0cb is described below
commit 442f9083c0cb4e07abc85bf803f933f8cb7cd762
Author: Yihong He <[email protected]>
AuthorDate: Thu Jan 8 03:06:38 2026 +0800
[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]>
---
.../scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala
index 7801cd347f7d..ddb6e3349d80 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala
@@ -623,11 +623,9 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]]
* A variant of [[foreach]] which considers plan nodes inside subqueries as
well.
*/
def foreachWithSubqueries(f: PlanType => Unit): Unit = {
- def actualFunc(plan: PlanType): Unit = {
- f(plan)
- plan.subqueries.foreach(_.foreachWithSubqueries(f))
- }
- foreach(actualFunc)
+ f(this)
+ subqueries.foreach(_.foreachWithSubqueries(f))
+ children.foreach(_.foreachWithSubqueries(f))
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]