Skip to content

[GLUTEN-12597][CORE] Migrate nested loop joins from CrossRel to NestedLoopJoinRel (Substrait 0.98) - #12700

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

[GLUTEN-12597][CORE] Migrate nested loop joins from CrossRel to NestedLoopJoinRel (Substrait 0.98)#12700
nielspardon wants to merge 1 commit into
apache:mainfrom
nielspardon:feat/substrait-0.98-inc3-cross-to-nlj

Conversation

@nielspardon

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

One increment of the Substrait proto rebase (v0.23.0 → 0.98.0), tracked by #12597.

Substrait 0.98 splits Gluten's overloaded CrossRel — which carried both expression and type — into a pure-cartesian CrossRel plus a new NestedLoopJoinRel (expression=4, type=5) with a paired JoinType enum. This PR adopts that split across the vendored proto, the JVM producer, and both native consumers, in lockstep:

  • Proto (algebra.proto): reduce CrossRel to the pure-cartesian shape; add NestedLoopJoinRel verbatim from 0.98 (including the new LEFT_MARK/RIGHT_MARK join types). The new rel is parked at a temporary Rel-oneof field number; the final oneof-reconciliation increment relocates it to the official nested_loop_join = 18. Field numbers are codegen-transparent for Gluten's coupled build (single proto source, transient plans, producer + both consumers regenerate and ship together → no wire-compat constraint).
  • Producer (JVM): CrossRelNodeNestedLoopJoinRelNode, RelBuilder.makeNestedLoopJoinRel, SubstraitUtil.toNestedLoopJoinSubstrait, and all callers (CartesianProductExecTransformer, BroadcastNestedLoopJoinExecTransformer, JoinUtils, StorageJoinBuilder).
  • Velox consumer: SubstraitToVeloxPlan and SubstraitToVeloxPlanValidator dispatch and parse NestedLoopJoinRel instead of CrossRel.
  • ClickHouse consumer: CrossRelParser, CHUtil, and BroadcastJoinBuilder re-point to nested_loop_join / NestedLoopJoinRel_JoinType (class/file names kept to minimize churn).

The NestedLoopJoinRel.JoinType enum reorders the anti/semi/single values relative to the old CrossRel.JoinType fork, but Gluten's producers only ever emit INNER/OUTER/LEFT/LEFT_SEMI — whose proto numbers (1/2/3/5) are identical in both — and both consumers only handle those same values, so the split is semantically neutral for Gluten's code paths.

Part of #12597.

How was this patch tested?

  • New SubstraitUtilJoinTypeSuite locks the semantic-neutrality invariant: the Spark → NestedLoopJoinRel.JoinType mapping, the stable proto numbers (INNER=1/OUTER=2/LEFT=3/LEFT_SEMI=5), the unsupported-type → UNRECOGNIZED fallback, and ordinal() == getNumber() for every declared enum value (the raw-ordinal-over-JNI path that StorageJoinBuilder relies on).
  • Built locally: the JVM producer (gluten-substrait, spark-3.5) and the Velox native backend both compile cleanly; the new suite passes.

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

Generated-by: Claude Code (Claude Opus 4.8)

🤖 Generated with AI

@nielspardon
nielspardon force-pushed the feat/substrait-0.98-inc3-cross-to-nlj branch from 9dae337 to acb01ba Compare August 5, 2026 09:01
@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

1 similar comment
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

…dLoopJoinRel (Substrait 0.98)

Substrait 0.98 splits Gluten's overloaded CrossRel (which carried both
`expression` and `type`) into a pure-cartesian CrossRel plus a new
NestedLoopJoinRel (expression=4, type=5) with a paired JoinType enum. This
increment of the proto rebase adopts that split across the vendored proto, the
JVM producer, and both native consumers in lockstep.

The NestedLoopJoinRel.JoinType enum reorders the anti/semi/single values
relative to the old CrossRel.JoinType fork, but Gluten only ever emits and
consumes INNER/OUTER/LEFT/LEFT_SEMI, whose proto numbers (1/2/3/5) are identical
in both, so the split is semantically neutral for Gluten's code paths.

The new rel takes its official Substrait 0.98 Rel-oneof number
nested_loop_join = 18. Fields 18 and 19 were held by write and top_n in
Gluten's fork, so both are moved to their own final 0.98 numbers (write = 19,
top_n = 23) to free the slot. Field numbers are codegen-transparent for
Gluten's coupled build (single proto source, transient plans, producer + both
consumers regenerate and ship together), so these moves are purely mechanical.
The remaining fork-order rels and the not-yet-added 0.98 relations are
reconciled in the final oneof reconciliation increment.

Part of apache#12597.

Generated-by: Claude Code (Claude Opus 4.8)
@nielspardon
nielspardon force-pushed the feat/substrait-0.98-inc3-cross-to-nlj branch from acb01ba to 887aa5b Compare August 5, 2026 12:26
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@nielspardon

Copy link
Copy Markdown
Contributor Author

The three failing checks all failed at dependency-download / tool-install steps — not in the actual build, test, or format logic. This run hit a bad network window for the hosted runners:

  • format-check (Cpp Code Format Check): apt failed during Install tools with E: Failed to fetch .../linux-libc-dev_5.15.0-187.197_amd64.deb 404 Not Found. The clang-format check step never ran. (The Scala Code Format Check passed.)
  • CH CMake Format Check: failed at the Install tools step (apt/pip download).
  • spark-test-spark35 (3): curl (7) Couldn't connect to server while downloading Maven 3.9.16 from Maven Central, before any test ran.

Everything else is green — both native backends build (Velox + ClickHouse), the full JVM producer, all join-bearing Spark groups, and the entire TPC-H/DS matrix. Could a committer kindly re-run these three failed jobs? Thanks!

🤖 Generated with AI

Generated-by: Claude Code (Claude Opus 4.8)

@nielspardon
nielspardon marked this pull request as ready for review August 7, 2026 05:43

@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

CLICKHOUSE CORE works for Gluten Core VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants