Skip to content

[GLUTEN-12597][CORE] Migrate WriteRel to Substrait 0.98 (relocate bucket_spec; add create_mode/advanced_extension) - #12746

Open
nielspardon wants to merge 2 commits into
apache:mainfrom
nielspardon:feat/substrait-0.98-writerel
Open

[GLUTEN-12597][CORE] Migrate WriteRel to Substrait 0.98 (relocate bucket_spec; add create_mode/advanced_extension)#12746
nielspardon wants to merge 2 commits into
apache:mainfrom
nielspardon:feat/substrait-0.98-writerel

Conversation

@nielspardon

@nielspardon nielspardon commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Substrait 0.98 extended WriteRel: field 7 became RelCommon common, and it gained CreateMode create_mode = 8 and substrait.extensions.AdvancedExtension advanced_extension = 9, while the OutputMode value OUTPUT_MODE_MODIFIED_TUPLES was renamed to OUTPUT_MODE_MODIFIED_RECORDS. Gluten's local bucket_spec graft (#8386) sat on field 7 — exactly where 0.98 puts common. This migrates Gluten's vendored WriteRel to the 0.98 body and relocates the graft off the collision, as one step of the Substrait v0.23.00.98.0 proto rebase (#12597).

The graft moves to field 1000, adopting a "Gluten-local fields start at 1000" convention that keeps grafts clear of the range upstream allocates from, so a future upstream field cannot collide with them again. The enclosing Rel.write oneof tag stays at 18; reconciling the whole Rel oneof to upstream's numbers is a separate follow-up. All producer/consumer accessors are name-based (setBucketSpec), so the field renumber needs no source change; no producer or consumer source is touched.

  • Proto: vendor the 0.98 WriteRel body verbatim (common = 7, create_mode = 8, advanced_extension = 9, the CreateMode enum, OUTPUT_MODE_MODIFIED_RECORDS) and relocate BucketSpec bucket_spec from field 7 to 1000. The nested BucketSpec message is unchanged.
  • Docs: record the rebase and the 1000+ numbering convention in SubstraitModifications.md, noting that WriteRel.common still uses Gluten's pre-0.98 RelCommon copy and so cannot carry a full 0.98 common payload.

Gluten's WriteRel producer sets only table_schema, named_table (with advanced_extension), input, and bucket_spec; it never sets op, output, or common. The Velox and ClickHouse consumers read input, table_schema, bucket_spec, and named_table.advanced_extension — all by name — and ignore the renamed enum value (it appears only in generated code). So no producer or consumer source needs to change for the proto edits.

How was this patch tested?

  • New WriteRelProtoSuite pins the producer contract (named table, explicit schema, relocated bucket spec, and the never-set 0.98 fields at their defaults) and asserts the 0.98 field numbers on the descriptor — including bucket_spec = 1000 — plus the OUTPUT_MODE_MODIFIED_RECORDS rename. A renumber or enum-value rename is invisible to a round trip through the shared schema, so the descriptor assertions are the real guard.
  • Locally verified: protoc dup-field check (all imports resolve, no duplicate numbers); gluten-substrait builds with the proto codegen regenerated and the new suite passes (mvn -Pspark-3.5); scalastyle + spotless clean.
  • The Velox WriteRel consumer body is unchanged; a full local libvelox link is currently blocked by an unrelated Velox-EP skew in ConfigExtractor.cc, so the end-to-end bucketed-write path (Velox) and the ClickHouse WriteRel parser are exercised by CI, not locally. A green local run does not imply full backend coverage here.

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

Generated-by: Claude Code (Claude Opus 4.8)

🤖 Generated with AI

…ket_spec; add create_mode/advanced_extension)

Substrait 0.98 extended WriteRel: field 7 became `RelCommon common`, and it
gained `CreateMode create_mode = 8` and
`substrait.extensions.AdvancedExtension advanced_extension = 9`, while the
`OutputMode` value `OUTPUT_MODE_MODIFIED_TUPLES` was renamed to
`OUTPUT_MODE_MODIFIED_RECORDS`. Gluten's local `bucket_spec` graft (PR apache#8386)
sat on field 7, exactly where 0.98 puts `common`.

This vendors the 0.98 WriteRel body verbatim and relocates the graft off the
collision, adopting a "Gluten-local fields start at 1000" convention that
keeps grafts clear of the range upstream allocates from, so a future upstream
field cannot collide with them again. The enclosing `Rel.write` oneof tag
stays at 18; reconciling the whole `Rel` oneof to upstream's numbers is a
separate change.

All producer/consumer accessors are name-based (`setBucketSpec`,
`has_common`), so the field renumber needs no source change. The one source
edit is a guard on the Velox consumer.

- Proto: add `common=7`, `create_mode=8`, `advanced_extension=9` and the
  `CreateMode` enum (vendored verbatim from 0.98), rename the `OutputMode`
  value to `OUTPUT_MODE_MODIFIED_RECORDS`, and relocate `BucketSpec
  bucket_spec` from field 7 to 1000 (nested `BucketSpec` message unchanged).
- Velox: reject a `common.emit` mapping in the WriteRel handler, which the
  writer does not apply, mirroring the existing guard on other rels.
- Docs: record the WriteRel rebase and the 1000+ numbering convention in
  SubstraitModifications.md, noting that `WriteRel.common` uses Gluten's
  pre-0.98 `RelCommon` copy.
- Add WriteRelProtoSuite pinning the producer contract, the 0.98 field
  numbers (including `bucket_spec=1000`), and the `OutputMode` rename (a
  renumber or rename is invisible to a round trip through the shared schema).

Part of apache#12597

Generated-by: Claude Code (Claude Opus 4.8)
@github-actions github-actions Bot added CORE works for Gluten Core VELOX DOCS labels Aug 10, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@nielspardon
nielspardon marked this pull request as ready for review August 11, 2026 06:01
Comment thread cpp/velox/substrait/SubstraitToVeloxPlan.cc Outdated
WriteRelNode never sets WriteRel.common, so has_common() is always false
for Gluten-produced plans and the guard is dead code. Remove it per review;
it can be re-introduced if a common producer path is added later.

Part of apache#12597

Generated-by: Claude Code (Claude Opus 4.8)
@nielspardon
nielspardon requested a review from JkSelf August 12, 2026 09:16
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions github-actions Bot removed the VELOX label Aug 12, 2026

@JkSelf JkSelf 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.

LGTM.

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

Labels

CORE works for Gluten Core DOCS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants