Skip to content

[VL] Preserve Java exceptions through native iterators - #13561

Merged
zhztheplayer merged 11 commits into
apache:mainfrom
felipepessoto:felipepessoto-velox-iterator-exception-preservation
Nov 26, 2026
Merged

zhztheplayer merged 11 commits into
apache:mainfrom
felipepessoto:felipepessoto-velox-iterator-exception-preservation

Conversation

@felipepessoto

@felipepessoto felipepessoto commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Preserve the original Java throwable when Velox reads a Java-backed iterator. The JNI input adapter wraps the failure before the driver can reduce it to text. Velox registers how to extract its native cause; ordinary JNI_METHOD_END follows it without a runtime or special iterator catch. Native callers keep their native exception.

Uses the JNI carrier from #13560. Combined reference: #13133.

How was this patch tested?

On the rebased revision, all 8 JNI iterator and 6 native Delta constraint cases passed on Spark 4.1 with JDK 17 and -Xcheck:jni. Native sources, dependency pins, and binary hashes were unchanged by the rebase.

Before the rebase, all 21 native tests passed after the cleanup guard was added. A separate check forced a missing registration and verified that the remaining callback was unaffected. Earlier checks included 14 core JNI JUnit tests, 20 Spark tests on each of 3.5 and 4.1, and throwable restoration across libgluten.so and libvelox.so. Disabling input wrapping made the partitioned NOT NULL regression fail specifically on Delta’s text-based reconstruction. GPU execution was not tested locally.

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

Generated-by: GitHub Copilot 1.0.106-8.unstable.r43566476370.g869eef3 (GPT-6.2 Astra, gpt-6.2-astra)

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@felipepessoto
felipepessoto force-pushed the felipepessoto-velox-iterator-exception-preservation branch from d2d3b37 to 9b3f41e Compare November 6, 2026 17:23
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@felipepessoto
felipepessoto force-pushed the felipepessoto-velox-iterator-exception-preservation branch from 9b3f41e to 895992a Compare November 6, 2026 22:21
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

malinjawi added a commit to malinjawi/incubator-gluten that referenced this pull request Nov 10, 2026
…Exec

Plan GlutenDeltaInvariantCheckerExec where Delta plans its row-based
DeltaInvariantCheckerExec, instead of wrapping the Velox writer's task
iterator. The writer no longer takes a checker.

When native code pulls the node's batches (the writer's sort on
partitioned writes, the optimized-write shuffle), it keeps only the
violation's text. The transaction then finds that text in the failure
and rethrows Delta's DeltaInvariantViolationException, until apache#13561
keeps Java exceptions across native code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zhztheplayer pushed a commit that referenced this pull request Nov 11, 2026
)

* [GLUTEN-10215][VL] Delta write: Offload top-level NOT NULL checks

* [GLUTEN-10215][VL] Address review of native NOT NULL checks

- Find nulls by decoding each constrained column and counting its nulls
  a word at a time, instead of trusting the cached null count: it can
  be stale, and on a dictionary or constant wrapping it misses the nulls
  of the wrapped values. The scan moves into
  VeloxColumnarBatch::firstNullColumnIndex, with unit tests.
- Fail the write if a native invariant checker reaches the WriteFilesExec
  branch of GlutenDeltaFileFormatWriter, which cannot apply it.
- Keep the checker's column ordinals and constraints in parallel arrays.
- Move GlutenDeltaInvariantChecker into the shared src-delta tree, so
  that every Delta version enforces the constraints the same way.
- Undo the reindentation of the spotless:off src-delta4 writer.
- Test the checker without a native library, and NOT NULL violations in
  data read from Parquet and with optimized writes.

* [GLUTEN-10215][VL] Test partitioned NOT NULL violations and update the Delta docs

A partitioned native write sorts the rows natively before writing them.
The native NOT NULL check runs after that sort, on the JVM, so violations
keep Delta's DeltaInvariantViolationException instead of being wrapped in
a GlutenException. Test it on Spark 3.5 and 4.x, including an empty string
partition value that Delta turns into a null, and update VeloxDelta.md,
which still described the row-based check for every NOT NULL write.

* [GLUTEN-10215][VL] Choose the native NOT NULL checker in one shared place

Both Delta transactions picked the checker with the same lines. Move them
into GlutenDeltaInvariantChecker.forWrite, which also keeps Delta's row
checker when spark.databricks.delta.constraints.convertEmptyToNullForStringPartitionCol
is off and the table has a string partition column. Delta then checks the
empty strings themselves, while the native checker would see the nulls the
writer turns them into, and would fail writes that Delta accepts.

* [GLUTEN-10215][VL] Trim the native NOT NULL tests

Move the NOT NULL tests into the existing DeltaNativeWriteSuite of each
Delta tree, which drops DeltaNativeWriteInvariantSuite and the helpers
it copied. Each tree keeps three tests:
- a native write with neither Delta's row checker nor C2R, and its
  violation, with and without optimized writes;
- CHECK constraints keep DeltaInvariantCheckerExec;
- violations on a partitioned table.

Drop the Parquet-source test. VeloxColumnarBatchTest covers dictionary
encodings directly, and the end-to-end test could not ensure them.
Shorten the checker's doc comment, which repeated the PR description.

* [GLUTEN-10215][VL] Check NOT NULL in a columnar DeltaInvariantCheckerExec

Plan GlutenDeltaInvariantCheckerExec where Delta plans its row-based
DeltaInvariantCheckerExec, instead of wrapping the Velox writer's task
iterator. The writer no longer takes a checker.

When native code pulls the node's batches (the writer's sort on
partitioned writes, the optimized-write shuffle), it keeps only the
violation's text. The transaction then finds that text in the failure
and rethrows Delta's DeltaInvariantViolationException, until #13561
keeps Java exceptions across native code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [GLUTEN-10215][VL] Create the native NOT NULL checker in glutenPhysicalPlan

glutenPhysicalPlan already gets the constraints, so it now creates the
checker itself and its arguments are back to what they are on main.

The unwrap moves into a catch around the native write. It takes the
checker from the plan's GlutenDeltaInvariantCheckerExec and leaves
failures that Delta's InnerInvariantViolationException already handles
to Delta's catch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [GLUTEN-10215][VL] Make findViolation static

findViolation no longer needs the checker's constraints. It finds the
text of a NOT NULL violation in the failure, takes the column name from
it and rebuilds Delta's exception with the constructor Delta uses. Both
transactions call it directly, so the transaction no longer looks up the
checker in the plan.

NOT NULL violations from Delta's row checker whose text reaches the
driver only inside a GlutenException now keep Delta's exception type
too. CHECK violations still do not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Mohammad Linjawi <Mohammad.Linjawi@ibm.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@felipepessoto
felipepessoto force-pushed the felipepessoto-velox-iterator-exception-preservation branch from 895992a to d17fa5f Compare November 13, 2026 18:47
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

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

🔵 Needs a closer look

Cross-library lifetime handling, thread propagation, and GPU callbacks at the shared JNI boundary require human native/JVM integration validation beyond the supplied runtime evidence, which does not cover GPU execution.

No open issues 🎉

4 resolved since last review

Review effort: Balanced

felipepessoto and others added 10 commits November 24, 2026 13:08
Split layer 2 of apache#13133, depending on apache#13560. Preserve the Java carrier through Velox input streams and lazy output loading, with focused native, real-JVM, and Delta constraint regressions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep the bare Java throwable case and verify the exact direct cause. Also exercise an already-translated GlutenException and require the same wrapper object through nested iterators, matching the upstream no-rewrap policy.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use the backend input factory for both initial and later splits, so CPU and cuDF streams can read generic iterators without interpreting Java failures. Exercise both split paths with the original Spark throwable.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use the standard Velox test source directory and backend guard. The shared test module no longer needs a separate source root or Scalastyle configuration.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep native iterator reads native. Only the JNI hasNext and next entry points ask the backend to recover a Java callback from a failed read; other errors follow the existing JNI fallback. Cover lazy loading from a native caller and from both Java-facing reads.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Let the shared JNI return boundary restore a captured throwable or apply the native fallback. Velox returns the carrier from a failed output read instead of rethrowing it into a second catch; unrelated JNI calls keep their existing handling.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Restore AGENTS.md to the iterator PR base. The test-placement guidance is tracked separately in apache#13727.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Let the ordinary JNI return handler follow backend-specific and standard nested causes without a runtime. Scope each registered callback to its lifetime, preserve the native fallback, and verify that a Delta NOT NULL violation reconstructed from text cannot pass the regression.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Log a missing registration instead of passing the end iterator to erase. Normal scoped unregistration is unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@felipepessoto
felipepessoto force-pushed the felipepessoto-velox-iterator-exception-preservation branch from 1f3230b to df3e57e Compare November 24, 2026 21:16
Copilot AI balanced review requested due to automatic review settings November 24, 2026 21:16
@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.

🔵 Needs a closer look

Cross-DSO throwable ownership and backend callback lifetimes require human review and native/JVM runtime validation, especially for the explicitly unverified GPU path and library teardown safety.

No open issues 🎉

Review effort: Balanced

@zhztheplayer zhztheplayer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for iterating, only a nit left.

Comment thread cpp/velox/compute/VeloxBackend.cc Resolved
Put the library-lifetime registration in a backend-local helper, so the init sequence uses a register call without changing when the callback is installed or removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 18:55

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.

🟢 Approval recommended

No active review issues remain for the JNI exception-propagation changes.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@felipepessoto

Copy link
Copy Markdown
Contributor Author

@zhztheplayer the failing CI is a transient issue I opened this PR to address it: #13797

@zhztheplayer
zhztheplayer merged commit 73dae76 into apache:main Nov 26, 2026
48 checks passed
@felipepessoto
felipepessoto deleted the felipepessoto-velox-iterator-exception-preservation branch November 26, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BOLT CORE works for Gluten Core DOCS VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants