Skip to content

[SPARK-60703][SQL] Compile the source plan of a DPP broadcast value projection as an AQE subquery - #60503

Open
rekbun wants to merge 1 commit into
apache:masterfrom
rekbun:SPARK-60703
Open

rekbun wants to merge 1 commit into
apache:masterfrom
rekbun:SPARK-60703

Conversation

@rekbun

@rekbun rekbun commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

PlanAdaptiveDynamicPruningFilters.projectedBroadcast now compiles the source plan of a broadcast value projection (SPARK-58265) with InsertAdaptiveSparkPlan.compileSubquery instead of QueryExecution.prepareExecutedPlan. AQE already compiles the build plan of a direct broadcast reuse this way (through SubqueryAdaptiveBroadcastExec), so the source plan is now always wrapped in an AdaptiveSparkPlanExec, as a subquery.

Why are the changes needed?

projectedBroadcast goes on only if it gets an AdaptiveSparkPlanExec back. prepareExecutedPlan runs InsertAdaptiveSparkPlan as for a top-level query, which wraps a plan only if it has an exchange, a distribution requirement or a subquery, unless spark.sql.adaptive.forceApply is set. The usual source plan, such as a filtered scan, has none of these. So with spark.sql.optimizer.dynamicPartitionPruning.broadcastProjection.enabled and AQE on, the DPP filter was planned as true and pruned nothing.

The AEOn DPP suites force-apply AQE, which hid this, and InjectRuntimeFilterSuite recorded the true filter as known behavior.

Does this PR introduce any user-facing change?

Yes. With the broadcast value projection enabled (off by default) and AQE on, these DPP filters now prune partitions. Results are unchanged.

How was this patch tested?

  • New test "SPARK-60703: project broadcast value rows when AQE is not force-applied" in DynamicPartitionPruningSuiteBase. With forceApply off, it checks the answer, the broadcast reuse, the projected subquery and the pruning values. It fails without the fix in the V1 and V2 AEOn suites.
  • Updated the SPARK-60702 test in InjectRuntimeFilterSuite to expect the projected filter under AQE too. It also fails without the fix.
  • Ran the DPP suites (V1, V2, AQE on and off, Hive), InjectRuntimeFilterSuite, DataSourceV2EnhancedRuntimePartitionFilterSuite, the V2 file source DPP suites and the TPC-DS and TPC-H plan stability suites.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)

…rojection as an AQE subquery

Under AQE, `PlanAdaptiveDynamicPruningFilters.projectedBroadcast` planned the source plan of a
broadcast value projection (SPARK-58265) with `QueryExecution.prepareExecutedPlan`, and went on
only if it got an `AdaptiveSparkPlanExec` back. Unless `spark.sql.adaptive.forceApply` is on,
`InsertAdaptiveSparkPlan` wraps a top-level plan only if it has an exchange, a distribution
requirement or a subquery. The usual source plan, such as a filtered scan, has none, so the DPP
filter was planned as `true` and pruned nothing. The AQE test suites force-apply AQE, which hid
it.

Compile the source plan with `InsertAdaptiveSparkPlan.compileSubquery`, as AQE does for the build
plan that a direct broadcast reuse starts from, so that it is always wrapped.

This branch has not been deployed

No deployments
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.

1 participant