Skip to content

[spark] Let Spark 4.3 merge scalar subqueries over Paimon tables - #11425

Open
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:spark43-merge-subqueries-in-spark
Open

LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:spark43-merge-subqueries-in-spark

Conversation

@LuciferYang

@LuciferYang LuciferYang commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Fixes #11424.

On Spark 4.3, MergePaimonScalarSubqueries runs before Spark's MergeSubplans on every query, including ones that read no Paimon table. It is an old copy of Spark's rule without its later fixes: it returns a wrong sum for a CSV read, throws on some nested-subquery, struct and CTE queries, and the WithCTE it adds makes MergeSubplans skip the query.

Spark 4.3 merges DSv2 scans itself for tables that declare TableCapability.SCAN_MERGING (SPARK-40259). On 4.3 only, this PR uses the no-op rule from paimon-spark-common, and PaimonScanMerging declares SCAN_MERGING for a FileStoreTable unless its options enable query auth. With query auth, the catalog's row filters can depend on the columns read.

4.3 then no longer merges subqueries that read different columns of a query-auth table or the same pruned struct field. On Spark 3.3 to 4.2 the old rule still merges query-auth tables; #11427 fixes that.

Tests

Spark43ScanMergingTest in the 4.3 module:

  • Paimon subqueries that read different columns become one scan, on an append table, on a primary-key table with deletion vectors, and when only one side has a data filter. The two writes in that last case have disjoint ranges, so a pushed filter would change the sum.
  • A partition filter on one side only keeps two scans. A merged scan keeps the bucket filter both sides push.
  • Non-Paimon subqueries with different filters become one scan, the CSV reads stay apart, and the nested-subquery, struct and CTE queries return the right rows.
  • Data tables declare SCAN_MERGING; three system tables and query-auth tables do not.

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.

[Bug] [spark] MergePaimonScalarSubqueries breaks scalar subqueries on Spark 4.3

1 participant