Skip to content

[GLUTEN-12597][CORE] Migrate AggregateRel.Grouping to expression references (Substrait 0.98) - #12724

Open
nielspardon wants to merge 1 commit into
apache:mainfrom
nielspardon:feat/substrait-0.98-aggregate-grouping
Open

[GLUTEN-12597][CORE] Migrate AggregateRel.Grouping to expression references (Substrait 0.98)#12724
nielspardon wants to merge 1 commit into
apache:mainfrom
nielspardon:feat/substrait-0.98-aggregate-grouping

Conversation

@nielspardon

@nielspardon nielspardon commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Substrait 0.98 moved the grouping expressions out of the per-grouping Grouping.grouping_expressions (field 1) into a rel-level pool AggregateRel.grouping_expressions = 5 that each grouping set references by index through Grouping.expression_references = 2. This migrates Gluten's vendored proto, the JVM producer, and both native consumers in lockstep, as one step of the Substrait v0.23.00.98.0 proto rebase (#12597).

Gluten only ever emits a single grouping set with a flat list of grouping expressions — GROUPING SETS / CUBE / ROLLUP are expanded into an ExpandRel upstream, and both native consumers enforce at-most-one grouping. So the mapping is order-preserving: the flat list becomes the rel-level pool in declaration order, and the single grouping references every entry as [0, 1, ..., n-1]. Empty grouping (global aggregation) stays one empty grouping with zero references — no behavior change. AggregateRel stays at Rel-oneof field 3, so there is no oneof renumbering.

  • Proto: reserve Grouping field 1, add Grouping.expression_references = 2 and rel-level AggregateRel.grouping_expressions = 5 (vendored verbatim from 0.98).
  • Producer: AggregateRelNode populates the pool in declaration order and has the single grouping reference every entry by index.
  • Velox: SubstraitToVeloxPlan and SubstraitToVeloxPlanValidator resolve references against the pool; VeloxToSubstraitPlan (the Velox→Substrait reverse converter) emits pool + references.
  • ClickHouse: AggregateRelParser and ExpandRelParser read grouping keys through the pool via expression_references.

How was this patch tested?

  • New AggregateRelProtoSuite pins the producer contract (flat grouping list → rel-level pool + single grouping referencing [0, 1]; empty grouping → one empty grouping with zero references).
  • Migrated the static Substrait plan JSON fixtures to the pooled shape so protobuf JSON parsing (which rejects the now-reserved inline field) still loads them: the Velox q1_first_stage.json consumer fixture, the ClickHouse metrics-suite plans (covar_samp/covar_pop partial + final, tpch-q1/q2/q4), and the Velox benchmark plans (generic_q1, q17_joins).
  • Locally verified: protoc dup-field check; gluten-substrait builds and the new suite passes (mvn -Pspark-3.5); the Velox native backend compiles (consumer, validator, and reverse converter); clang-format (v15) clean on all changed C++ files.
  • Existing end-to-end group-by suites exercise the consumer resolution on both backends.

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

Generated-by: Claude Code (Claude Opus 4.8)

🤖 Generated with AI

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions github-actions Bot added CORE works for Gluten Core VELOX CLICKHOUSE labels Aug 7, 2026
…rences (Substrait 0.98)

Substrait 0.98 moved the grouping expressions out of the per-grouping
`Grouping.grouping_expressions` (field 1) into a rel-level pool
`AggregateRel.grouping_expressions` (field 5) that each grouping set references
by index through `Grouping.expression_references` (field 2). This migrates the
vendored proto, the JVM producer, and both native consumers in lockstep.

Gluten only ever emits a single grouping set with a flat list of grouping
expressions (GROUPING SETS / CUBE / ROLLUP are expanded into an ExpandRel
upstream, and both native consumers enforce at-most-one grouping), so the
mapping is order-preserving: the flat list becomes the pool in declaration order
and the single grouping references every entry as [0, 1, ..., n-1]. Empty
grouping (global aggregation) stays one empty grouping with zero references.

- Proto: reserve Grouping field 1, add Grouping.expression_references=2 and
  rel-level AggregateRel.grouping_expressions=5 (verbatim 0.98).
- Producer: AggregateRelNode populates the pool and the single grouping's
  references.
- Velox: SubstraitToVeloxPlan + SubstraitToVeloxPlanValidator resolve references
  against the pool; VeloxToSubstraitPlan (the reverse converter) emits pool +
  references.
- ClickHouse: AggregateRelParser and ExpandRelParser read grouping keys through
  the pool via expression_references.
- Migrate the static Substrait plan JSON fixtures to the pooled shape: the Velox
  q1_first_stage.json consumer fixture, the ClickHouse metrics-suite plans
  (covar_samp/covar_pop partial + final, tpch-q1/q2/q4), the orphaned
  native_write_plan_1_spark33.json, and the Velox benchmark plans (generic_q1,
  q17_joins). protobuf JSON parsing rejects unknown fields, so any fixture still
  on the inline (now-reserved) shape would fail to load.
- Add AggregateRelProtoSuite pinning the producer contract.

Part of apache#12597

Generated-by: Claude Code (Claude Opus 4.8)
@nielspardon
nielspardon force-pushed the feat/substrait-0.98-aggregate-grouping branch from e9a2bb6 to a5eab42 Compare August 7, 2026 12:47
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@nielspardon
nielspardon marked this pull request as ready for review August 7, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLICKHOUSE CORE works for Gluten Core VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant