Skip to content

[GLUTEN-12597][CORE] Migrate FetchRel offset/count to expressions (Substrait 0.98) - #12704

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

[GLUTEN-12597][CORE] Migrate FetchRel offset/count to expressions (Substrait 0.98)#12704
nielspardon wants to merge 1 commit into
apache:mainfrom
nielspardon:feat/substrait-0.98-fetchrel

Conversation

@nielspardon

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Substrait 0.98 replaced FetchRel's scalar int64 offset = 3 / int64 count = 4 with Expression offset_expr = 5 / Expression count_expr = 6. 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's only FetchRel producer (LimitExecTransformer) always supplies literal Long offset/count from Spark's Limit/Offset plans, so the change is mechanical: the producer wraps each value into an i64-literal Expression, and the consumers extract the literal back out — guarded by has_offset_expr()/has_count_expr(), falling back to 0 when unset (matching the 0.98 "offset unset is treated as 0" semantics). FetchRel stays at Rel-oneof field 3, so there is no oneof renumbering.

  • Proto: reserve fields 3/4, add offset_expr = 5 / count_expr = 6 (vendored verbatim from 0.98).
  • Producer: FetchRelNode wraps offset/count via ExpressionBuilder.makeLongLiteral(...).
  • Velox: SubstraitToVeloxPlan and SubstraitToVeloxPlanValidator read the literals via SubstraitParser::getLiteralValue<int64_t>; VeloxToSubstraitPlan (the Velox→Substrait reverse converter) writes i64-literal expressions.
  • ClickHouse: FetchRelParser and SortRelParser::parseLimit read the count_expr / offset_expr literals.

How was this patch tested?

  • New FetchRelProtoSuite pins the producer contract (offset/count land as i64 literal expressions).
  • 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 LIMIT/OFFSET suites exercise the consumer extraction 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

…bstrait 0.98)

Substrait 0.98 replaced FetchRel's scalar `int64 offset = 3` / `int64 count = 4`
with `Expression offset_expr = 5` / `Expression count_expr = 6`. This migrates the
vendored proto, the JVM producer, and both native consumers in lockstep.

Gluten's only FetchRel producer (LimitExecTransformer) always supplies literal
Long offset/count from Spark's Limit/Offset plans, so the producer wraps each into
an i64-literal Expression and the consumers extract the literal back out, guarded
by has_offset_expr()/has_count_expr() and falling back to 0 when unset (per the
0.98 "offset unset is treated as 0" semantics).

- Proto: reserve fields 3/4, add offset_expr=5/count_expr=6 (verbatim 0.98).
- Producer: FetchRelNode wraps offset/count via ExpressionBuilder.makeLongLiteral.
- Velox: SubstraitToVeloxPlan + SubstraitToVeloxPlanValidator read the literals via
  SubstraitParser::getLiteralValue<int64_t>; VeloxToSubstraitPlan (the reverse
  converter) writes i64-literal expressions.
- ClickHouse: FetchRelParser and SortRelParser::parseLimit read the count_expr /
  offset_expr literals.
- Add FetchRelProtoSuite pinning the producer contract.

Part of apache#12597

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

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@nielspardon
nielspardon marked this pull request as ready for review August 7, 2026 05:43
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.

2 participants