Skip to content

[VL] Translate native cast failures into Spark exceptions - #13135

Draft
felipepessoto wants to merge 6 commits into
apache:mainfrom
felipepessoto:felipepessoto-native-cast-exceptions
Draft

felipepessoto wants to merge 6 commits into
apache:mainfrom
felipepessoto:felipepessoto-native-cast-exceptions

Conversation

@felipepessoto

@felipepessoto felipepessoto commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 96ea0d644590d7cc98008ec61b6a4ccf85814efd

Dimension Assessment Rationale
Change confidence 9/10 ↑ The mapper suite passed on five supported Spark versions; six driver cases distinguished Spark parse failures from native-only failures on Spark 3.5 and 4.1.
↑ The only change since the last hosted run removes five now-passing entries; all eight archived shards pass the strict gate with the updated baseline.
↓ Classification still depends on Velox’s reason format, and cast errors lack SQL query context.
Diagnosis confidence 9.5/10 ↑ Velox already raised the cast failures; the previous JNI fallback returned a generic exception.
↑ The prior mapper mislabeled valid Spark inputs and missed an ordinary quoted string; both regression tests failed before the fix.
Evidence fit 9.5/10 ↑ Hosted Delta CI executed all 16 batch and 16 streaming cast cases with no failures or skips. Five additional MERGE cases failed on the main nightly and passed on the PR.
↓ The fresh hosted run has not finished on this revision.

What changes are proposed in this pull request?

Depends on #13822. Velox identifies failures from built-in casts at the JNI return boundary. Gluten translates recognized overflow, decimal precision, and invalid string inputs into Spark exceptions with the native diagnostic as the cause. It preserves translated exceptions across nested iterators so Spark 4 can report them even before a shuffle.

For string-to-integral failures, Gluten uses Spark’s exact parser for the target type. If Spark accepts the value, the native failure stays visible rather than becoming CAST_INVALID_INPUT. Ordinary quoted text such as bad' to sleep is preserved; ambiguous target delimiters are not interpreted. Cast evaluation, legacy and TRY behavior are unchanged. Velox does not supply SQL query context.

How was this patch tested?

  • 29 C++ tests; on each of Spark 3.5 and 4.1, 18 real-JVM JNI tests (-Xcheck:jni), 23 Velox suite tests and 17 mapper tests. The mapper suite also passed on Spark 3.4, 4.0 and 4.2.
  • A driver-level check confirmed that four NUL/DEL boundary inputs retained the native failure, bad' to sleep matched Catalyst’s error, and a genuinely ambiguous input stayed untranslated.
  • All 32 targeted Delta 4.4.1 cast cases passed locally and in hosted CI. Shard 4 reported five additional now-passing multiple-match MERGE cases and zero new failures. Removing those five entries makes all eight archived shard reports pass the strict gate.

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

Generated-by: GitHub Copilot 1.0.106-8.unstable.r43360710077.gff3c476 (GPT-6 Astra, model ID: gpt-6-astra)

Generated-by: GitHub Copilot 1.0.115-7 (GPT-6.2 Astra, model ID: gpt-6.2-astra)

Generated-by: GitHub Copilot 1.0.115-7 (Claude Opus 5.5, model ID: claude-opus-5.5)

@github-actions github-actions Bot added CORE works for Gluten Core VELOX DOCS labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

3 similar comments
@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

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

2 similar comments
@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 github-actions Bot added the INFRA label Oct 31, 2026
@github-actions

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

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@felipepessoto

Copy link
Copy Markdown
Contributor Author

/delta-test

@github-actions

Copy link
Copy Markdown

🔄 Delta Spark UT started by @felipepessoto (~2.5 h). View run

@github-actions github-actions Bot added the INFRA label Nov 15, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions github-actions Bot added the BOLT label Nov 27, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

…the JNI boundary

Add JniExceptionMetadataRegistration, a scoped backend callback that describes a native
exception as a Java class name, a reason and a diagnostic. JNI_METHOD_END asks it only when no
Java exception is pending or carried, then constructs the class through its
(byte[] reason, byte[] diagnostic) constructor after releasing the registry lock. A Java
exception raised while constructing it stays pending; other failures keep the GlutenException
fallback. The unwrapper registration keeps its API and behavior and shares the same null,
duplicate and lifetime checks.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

felipepessoto and others added 4 commits November 26, 2026 22:30
…class

A provider exception that isn't a std::exception no longer escapes the JNI
boundary. It is logged, and the boundary keeps a pending Java throwable or
otherwise the GlutenException fallback with the original diagnostic. The
boundary also checks that the described class extends java.lang.Throwable
before running its constructor or JNI Throw, and keeps the same fallback
when it doesn't.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Velox registers a JNI exception metadata provider for USER/INVALID_ARGUMENT
errors that ExpressionExceptionProperties attribute to a built-in cast, so the
JNI boundary raises NativeCastException with the native reason and diagnostic.
ColumnarBatchOutIterator maps recognized overflow, decimal precision and
string-to-integral reasons to Spark's QueryExecutionErrors exceptions, with the
native error as the cause.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…h Catalyst

Return Spark exceptions from nested native iterators unchanged, so a cast error
raised before a shuffle stays the task's top-level exception and Spark 4
reports it instead of "Job aborted". Describe only reasons that start with
"Cannot cast ", so other errors raised while a cast runs, such as lazily
loading its input, keep the default handling.

Tests take their expected errors from Catalyst's ANSI cast and now run REAL
sources, infinities, exponent and negative values, integral to decimal, and
each integral string target natively.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Only attach CAST_INVALID_INPUT when the parser for the reported target rejects the value. Preserve other native failures and distinguish unescaped target headers from ordinary quoted text.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@felipepessoto
felipepessoto force-pushed the felipepessoto-native-cast-exceptions branch from 2aeda77 to bf54454 Compare November 27, 2026 07:08
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Delta shard 4 passed these multiple-match cases and reported no regressions. Replaying all eight hosted shard reports passes the strict gate with the five stale entries removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant