fix: preserve inherited AQE stage links on Comet operators #7357
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.43) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 376 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.355
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #7357"
general
weight: 0.35
sunchao
Which issue does this PR close?
Addresses the inherited logical-link case in #6034. The broader audit remains open.
Rationale for this change
Spark’s adaptive query execution (AQE) can switch a join to broadcast when an aggregation makes the build side small enough. With a mixed
COUNT(*)andCOUNT(DISTINCT ...), the first shuffle can be above the broadcast threshold and the second well below it. Comet can lose the link to the second stage and keep a sort-merge join.What changes are included in this PR?
Keep the current AQE stage on a reused Comet operator when the link is direct, or when the inherited stage wraps the operator’s original logical node. Compare nodes by identity, including through nested stage wrappers. When restoring the original link, copy its direct and inherited tags on the operator itself. Calling Spark’s
setLogicalLinkhere promotes an inherited tag to a direct one and propagates it into children that can already belong to a newer stage.The three planner paths that copy logical links now use one helper. AQE restoration clears a stale tag when the original has none. A rebuilt projection or fallback keeps its own tag in that case.
Spark’s logical-link test recognizes Comet projections and filters in a scan subtree. Its two existing matches now use Spark’s
ColumnarToRowTransitiontype, so the test recognizes either implementation and checks the direct tag on the scan subtree root.How are these changes tested?
The SQL regression joins two synthetic ranges. Static broadcasting is disabled and AQE gets a 16 KiB broadcast threshold. On both stock Spark releases, only the planner rule changes between runs.
| Spark | Final join on Apache main | Final join with this PR | Correct result rows in both runs |
| --- | --- | --- | ---: |
| 3.5.9 | Sort-merge | Native broadcast hash | 16 of 16 |
| 4.1.3 | Sort-merge | Native broadcast hash | 16 of 16 |
Both plans started without a broadcast join. On Spark 3.5.9, the fixed plan’s first build shuffle reported 196,096 bytes and the second reported 1,280 bytes. The comparison measures plan selection and result parity.
The two link tests and the SQL regression failed with the main rule and passed with the fix on both releases. On the revised PR, the full
CometExecRuleSuiteand three AQE and exchange tests passed on Spark 3.5.9 and 4.1.3, with one Spark-4-only test skipped on 3.5.9. Spotless and Scalastyle passed for the changed Scala sources.All 150 cases in Spark’s
LogicalPlanTagInSparkPlanSuitepassed with the revised matcher on each supported version (3.4.3, 3.5.9, 4.0.4, 4.1.3, and 4.2.0). I also tested the two plan shapes separately.Filtertag. Checking the child passes.