← Back to Pull requests

fix: preserve inherited AQE stage links on Comet operators #7357

Open
unknown opened this pull request with 376 lines diff across 4 files
View on GitHub
unknown unknown commented on Oct 30, 2026 23:09 UTC
Author

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(*) and COUNT(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 setLogicalLink here 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 ColumnarToRowTransition type, 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 CometExecRuleSuite and 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 LogicalPlanTagInSparkPlanSuite passed 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.

  • Without recognizing a Comet row transition inside the scan subtree, TPC-DS q9 visits a filter carrying only an inherited link and fails the direct-tag assertion.

  • On a filtered Parquet scan with the row transition at the root, the transition has no direct tag and its child has the direct Filter tag. Checking the child passes.
  • Diff: 376 lines (+282 / -94) across 4 files Reviewer: sunchao Review duration: 2120m
    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
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.9% (MEDIUM) · Higher = larger blast radius
    42.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.5% · Safe to merge
    24.5%