Skip to content

fix: keep AQE DPP for scans bridged by CometSparkToColumnarExec - #7761

Open
yihua wants to merge 3 commits into
apache:mainfrom
yihua:fix-dpp-bridged-scan
Open

yihua wants to merge 3 commits into
apache:mainfrom
yihua:fix-dpp-bridged-scan

Conversation

@yihua

@yihua yihua commented Nov 24, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Closes #4145.

Rationale for this change

When Comet bridges a scan into Arrow, the scan ends up in CometScanWrapper.originalPlan, which is not a child. convertSubqueryBroadcasts therefore never sees the DPP subquery in its partition or runtime filters. Under AQE, when the join goes native, Spark's PlanAdaptiveDynamicPruningFilters then replaces the pruning with true, and the scan reads every partition. Without AQE, the subquery keeps Spark's SubqueryBroadcastExec, which still prunes but cannot reuse the join's Comet broadcast. This applies to V1 file scans as well as the V2 case in the issue.

We hit it running TPC-DS 1TB on Hudi copy-on-write tables (S3, 10 executors of 16 cores, Spark 3.5). Comet bridges those scans because Hudi's file format is not Spark's Parquet format, so every fact scan read all 1,823 partitions. With the fix, Comet-mode scans prune like Spark's (the median catalog_sales scan reads 364). Before the fix, Comet mode was 1.57x slower than Spark over the 88 queries both completed. After it, the 103-query run took 1151 s against Spark's 1520 s. q25, q72 and q77 were 2.3x to 9x slower than Spark, and now take 24.9 s in total against Spark's 28.8 s.

What changes are included in this PR?

CometExecRule.transform also rewrites DPP subqueries inside a CometScanWrapper's originalPlan, and it keeps the wrapper's tags. The rewrite is limited to the wrapper rather than moved ahead of convertNode for every node, as #4145 suggests, so the other scan paths keep their current DPP handling. A transformAllExpressions pass would not reach originalPlan, since it is not a child.

How are these changes tested?

Two new CometExecSuite tests:

  • DPP: scan bridged by CometSparkToColumnarExec keeps DPP turns native scans off and Parquet conversion on, so the partitioned fact scan is bridged under a Comet broadcast hash join. With AQE on and off, it checks for one CometSubqueryBroadcastExec and that the scan reads 1 of 10 partitions. Without AQE, it also checks that the join's broadcast is reused.
  • DPP: V2 BatchScan bridged by CometSparkToColumnarExec keeps DPP does the same, with AQE on and off, for an InMemoryTableCatalog table bridged through spark.comet.sparkToColumnar, and checks that the scan returns 10 of the 100 fact rows.

Without the fix, every case finds no CometSubqueryBroadcastExec. On the default Spark 4.1 profile, all 57 tests pass in the DPP tests of CometExecSuite together with CometBroadcastBuildSideSuite. The two new tests also pass locally on the Spark 3.5, 4.0 and 4.2 profiles.

@github-actions github-actions Bot added the bug Something isn't working label Nov 24, 2026
@yihua
yihua force-pushed the fix-dpp-bridged-scan branch from 9349c50 to 18e48b4 Compare December 2, 2026 17:10
@yihua
yihua marked this pull request as ready for review December 2, 2026 17:10

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diagnosis holds. Spark's PlanAdaptiveDynamicPruningFilters only looks for a Spark BroadcastHashJoinExec in rootPlan (same code at v3.5.8, v4.0.1 and v4.1.1), and the outer transformUp never reaches a scan bridged at its own visit because CometScanWrapper is a leaf. Rewriting inside originalPlan is idempotent for nodes already rewritten, and the resulting CometSubqueryAdaptiveBroadcastExec on a plain Spark scan goes through the existing convertNonCometNodeDPP path. Without the fix, both tests fail at the CometSubqueryBroadcastExec count. The 10 removed lines are a comment only. The PR tier runs CometExecSuite on Spark 4.1 only, so run-all-spark-profiles would show whether the new plan-shape assertions also hold on 3.5, 4.0 and 4.2 (I did not run them). The CI (fork) failure was a Build Comet step in the first attempt of the Iceberg 1.11 job, and the rerun passed, so it is not tied to the diff.

Comment on lines +1446 to +1451
test("AQE DPP: V2 BatchScan bridged by CometSparkToColumnarExec keeps DPP") {
import testImplicits._
withSQLConf(
"spark.sql.catalog.testcat" -> classOf[InMemoryTableCatalog].getName,
"spark.sql.defaultCatalog" -> "testcat",
SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "true",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix also rewrites a non-AQE SubqueryBroadcastExec in a bridged BatchScanExec's runtimeFilters, but only the V1 test checks the non-AQE broadcast reuse. Looping over aqe <- Seq(true, false) here, with the same CometSubqueryBroadcastExec and ReusedExchangeExec checks as the V1 test, would cover V2 too. If the test name drops AQE, the cross-reference in the comment of AQE DPP: V2 BatchScan broadcast query stage creation order (SPARK-34637) needs the new name.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 91a215c: the V2 test now runs with AQE on and off, with the same non-AQE checks as the V1 test, and is renamed DPP: V2 BatchScan bridged by CometSparkToColumnarExec keeps DPP (the SPARK-34637 comment points to the new name). Both bridged tests also pass locally on the Spark 3.5, 4.0 and 4.2 profiles.

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @yihua, the PR goes into right direction, please check some nits!

@yihua

yihua commented Dec 3, 2026

Copy link
Copy Markdown
Author

Thank you @comphead for reviewing the PR! The comment is addressed.

@yihua
yihua force-pushed the fix-dpp-bridged-scan branch from 91a215c to d4560d9 Compare December 3, 2026 04:33
yihua added 3 commits December 4, 2026 11:09
A scan Comet bridges into Arrow sits in CometScanWrapper.originalPlan, which is not a child, so the SubqueryAdaptiveBroadcastExec in its partition filters was never wrapped. Spark's PlanAdaptiveDynamicPruningFilters then replaced the pruning with true and the scan read every partition. Rewrite DPP subqueries inside the wrapper's originalPlan too.
Run the bridged V1 scan test with AQE off as well, where the rewrite lets the DPP subquery reuse the join's Comet broadcast, and add a V2 BatchScan form of it (apache#4145). Update the SPARK-34637 V2 test comment that still described apache#4145 as open, and say in the helper's doc that the pruning is dropped only when the join goes native.
@yihua
yihua force-pushed the fix-dpp-bridged-scan branch from d4560d9 to 32831db Compare December 4, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AQE DPP SAB wrapping skipped when V2 scan is wrapped in CometSparkToColumnarExec

2 participants