Skip to content

[GLUTEN-12566][CORE] Propagate keyGroupedPartitioning in BatchScanExecTransformer#12567

Open
wangyum wants to merge 3 commits into
apache:mainfrom
wangyum:fix-batchscan-canonicalize
Open

[GLUTEN-12566][CORE] Propagate keyGroupedPartitioning in BatchScanExecTransformer#12567
wangyum wants to merge 3 commits into
apache:mainfrom
wangyum:fix-batchscan-canonicalize

Conversation

@wangyum

@wangyum wangyum commented Jul 19, 2026

Copy link
Copy Markdown
Member

What changes are proposed in this pull request?

Fix three related bugs around keyGroupedPartitioning in BatchScanExecTransformer:

1. ScanTransformerFactory does not propagate keyGroupedPartitioning (main fix)

ScanTransformerFactory.createBatchScanTransformer() creates a BatchScanExecTransformer without passing keyGroupedPartitioning from the source BatchScanExec. This means Gluten's scan always reports UnknownPartitioning instead of KeyGroupedPartitioning, defeating SPJ (Storage Partitioned Joins) and inserting redundant shuffles.

IcebergScanTransformer and PaimonScanTransformer already pass keyGroupedPartitioning correctly — this fixes the same gap for regular file scans (Parquet, ORC, etc.).

2. doCanonicalize() does not normalize keyGroupedPartitioning

When two semantically identical scans have different expression IDs in their keyGroupedPartitioning expressions, the canonicalized plans are not equal, preventing AQE exchange reuse.

3. hashCode() does not include keyGroupedPartitioning — equals/hashCode contract violation

equals() compares keyGroupedPartitioning (via spjParams) but hashCode() omits it.

How was this patch tested?

Existing tests. The fix aligns ScanTransformerFactory with IcebergScanTransformer/PaimonScanTransformer (same getKeyGroupedPartitioning shim call), and aligns hashCode()/doCanonicalize() with the existing equals() behavior.

Closes #12566.


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

No

Copilot AI review requested due to automatic review settings July 19, 2026 16:46
@github-actions github-actions Bot added the CORE works for Gluten Core label Jul 19, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI 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.

Pull request overview

This PR fixes canonicalization and hashing behavior for BatchScanExecTransformer so that keyGroupedPartitioning is treated consistently with equality semantics, improving AQE plan/exchange reuse behavior when expression IDs differ.

Changes:

  • Normalize keyGroupedPartitioning during doCanonicalize() using QueryPlan.normalizeExpressions.
  • Include keyGroupedPartitioning in BatchScanExecTransformerBase.hashCode().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 69 to 73
runtimeFilters.filterNot(_ == DynamicPruningExpression(Literal.TrueLiteral)),
output),
keyGroupedPartitioning = keyGroupedPartitioning.map(
QueryPlan.normalizeExpressions(_, output)),
pushDownFilters = pushDownFilters.map(QueryPlan.normalizePredicates(_, output))
@wangyum
wangyum marked this pull request as draft July 20, 2026 00:25
@wangyum
wangyum force-pushed the fix-batchscan-canonicalize branch from eaea5ff to 89029fb Compare July 20, 2026 00:35
@wangyum wangyum changed the title [GLUTEN-12566][CORE] Fix BatchScanExecTransformer hashCode/canonicalize to include keyGroupedPartitioning [GLUTEN-12566][CORE] Propagate keyGroupedPartitioning in BatchScanExecTransformer Jul 20, 2026
@wangyum
wangyum force-pushed the fix-batchscan-canonicalize branch from 89029fb to f52a4da Compare July 20, 2026 01:09
@github-actions github-actions Bot added the VELOX label Jul 20, 2026
@wangyum
wangyum force-pushed the fix-batchscan-canonicalize branch from f52a4da to c3abbea Compare July 20, 2026 01:47
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@wangyum
wangyum force-pushed the fix-batchscan-canonicalize branch from c3abbea to 621b65f Compare July 20, 2026 02:58
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@wangyum
wangyum force-pushed the fix-batchscan-canonicalize branch from 621b65f to 5371721 Compare July 20, 2026 05:20
@github-actions github-actions Bot removed the VELOX label Jul 20, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

…upedPartitioning

ScanTransformerFactory.createBatchScanTransformer() does not pass
keyGroupedPartitioning from the original BatchScanExec to the
BatchScanExecTransformer, leaving it as None even when the source
BatchScanExec has SPJ (Storage Partitioned Join) partitioning. This
causes Gluten's BatchScanExecTransformer to report UnknownPartitioning
instead of KeyGroupedPartitioning, defeating SPJ and inserting
redundant shuffles.

IcebergScanTransformer and PaimonScanTransformer already pass
keyGroupedPartitioning correctly; this fixes the same gap for regular
file scans (Parquet, ORC, etc.) created via ScanTransformerFactory.

Additionally fix two related issues in BatchScanExecTransformer that
were masked by keyGroupedPartitioning always being None:

1. doCanonicalize() does not normalize keyGroupedPartitioning. When
   two semantically identical scans have different expression IDs in
   their keyGroupedPartitioning expressions, the canonicalized plans
   are not equal, preventing AQE exchange reuse.

2. hashCode() does not include keyGroupedPartitioning, violating the
   equals/hashCode contract (equals compares it via spjParams, but
   hashCode omits it).

Closes apache#12566.
@wangyum
wangyum force-pushed the fix-batchscan-canonicalize branch from 5371721 to a667fbb Compare July 20, 2026 06:13
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@wangyum
wangyum marked this pull request as ready for review July 20, 2026 08:43
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CORE works for Gluten Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BatchScanExecTransformer hashCode/canonicalize misses keyGroupedPartitioning

2 participants