Skip to content

fix: descend into QueryStageExec when detecting DPP scans for shuffle fallback#3981

Closed
andygrove wants to merge 1 commit intoapache:mainfrom
andygrove:fix-dpp-scan-detection-across-aqe
Closed

fix: descend into QueryStageExec when detecting DPP scans for shuffle fallback#3981
andygrove wants to merge 1 commit intoapache:mainfrom
andygrove:fix-dpp-scan-detection-across-aqe

Conversation

@andygrove
Copy link
Copy Markdown
Member

Which issue does this PR close?

Related to #3949.

Rationale for this change

`stageContainsDPPScan` in `CometShuffleExchangeExec` (introduced by #3879) uses a plain `s.child.exists(...)` walk to decide whether the shuffle subtree contains a DPP scan. Under AQE, once a child stage materializes, its subtree is replaced by a `ShuffleQueryStageExec` — a `LeafExecNode` whose `children` is `Seq.empty`. `.exists` cannot descend through it, so the DPP scan becomes invisible on the stage-prep pass.

The consequence: the same shuffle that correctly fell back to Spark at initial planning gets converted to Comet the second time the rule runs, because `stageContainsDPPScan` returns `false` once the inner stage has materialized. That flip produces plan-shape inconsistencies across the two passes — the suspected mechanism behind the `ColumnarToRowExec` canonicalization assertion in #3949.

What changes are included in this PR?

  • Walk the tree explicitly instead of relying on `exists`, and descend into `QueryStageExec.plan` so both passes see the same subtree.

How are these changes tested?

  • New `CometDppFallbackConsistencySuite` builds a DPP-shaped query, takes the real `ShuffleExchangeExec` out of the plan, wraps it in a real `ShuffleQueryStageExec` (the exact wrapper AQE produces when a stage materializes), and asserts that `columnarShuffleSupported` still falls back to Spark. Without this fix the outer wrapping flips the decision to Comet.
  • Existing `DPP fallback` and `DPP fallback avoids inefficient Comet shuffle (Inefficient DPP fallback for TPC-DS #3874)` tests in `CometExecSuite` still pass.

I have not been able to reproduce the full #3949 crash even with the flip demonstrated, so this PR is positioned as a correctness fix for the decision-stability invariant. It may or may not close #3949 on its own.

…-prep passes

stageContainsDPPScan used a plain s.child.exists(...) to find a FileSourceScanExec
with a PlanExpression partition filter. Under AQE, once a child stage
materializes, its subtree is replaced by a ShuffleQueryStageExec (a
LeafExecNode whose children is Seq.empty), and .exists cannot descend through
it. The DPP scan becomes invisible on the stage-prep pass, so the same shuffle
that correctly fell back to Spark at initial planning gets converted to Comet
the second time the rule runs — producing plan-shape inconsistencies across
the two passes.

Walk the tree explicitly and descend into QueryStageExec.plan so both passes
see the same subtree and reach the same decision.

Adds CometDppFallbackConsistencySuite which wraps the DPP shuffle in a real
ShuffleQueryStageExec (exactly the wrapper AQE produces) and asserts the
fallback decision stays the same.
@andygrove andygrove marked this pull request as draft April 17, 2026 17:28
@andygrove andygrove marked this pull request as ready for review April 17, 2026 17:29
@andygrove andygrove marked this pull request as draft April 17, 2026 17:31
@andygrove
Copy link
Copy Markdown
Member Author

better fix in #3982

@andygrove andygrove closed this Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[INTERNAL_ERROR] The "collect" action failed.

1 participant