Repository navigation
[GLUTEN-11912][VL] Translate Velox assert_not_null errors to Spark's NOT_NULL_ASSERT_VIOLATION exception - #13780
Merged
zhztheplayer merged 1 commit intoNov 26, 2026
Conversation
|
Run Gluten Clickhouse CI on x86 |
pedrumj2
marked this pull request as ready for review
November 25, 2026 01:36
Contributor
Author
|
Hi @rui-mo @zhztheplayer when you get the chance can you please take a look at this PR along with the PRs below. They follow our previous discussion around message based translation of Velox error messages:
Thanks again! |
zhztheplayer
approved these changes
Nov 25, 2026
…NOT_NULL_ASSERT_VIOLATION exception
## What changes are proposed in this pull request?
This PR translates a gluten exception to Spark exception:
1. Maintain consistency with how exceptions are surfaced to users.
2. We can avoid the ` .exclude("some function")` in tests
| Inserted value | Spark 4.2.0 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `1` into `INT NOT NULL` | Inserted | Inserted | Inserted |
| `NULL` into `INT NOT NULL` | `NOT_NULL_ASSERT_VIOLATION` | `GlutenException` | `NOT_NULL_ASSERT_VIOLATION` |
Please see the following discussions apache#13647, apache#13685 and facebookincubator/velox#20483
Conclusion can be found [here](apache#13639 (comment))
## How was this patch tested?
### Reproduction
1. Clone the repo and check out the base commit:
```bash
git clone https://github.com/apache/gluten.git
cd gluten
git checkout 85c8980
```
2. Build the native libraries and the Spark 4.2 bundle jar:
```bash
docker run --rm -v "$PWD":/work/gluten:z apache/gluten:centos-9-jdk8 bash -c '
source /opt/rh/gcc-toolset-12/enable
export VELOX_BUILD_SHARED=ON
cd /work/gluten
./dev/builddeps-veloxbe.sh --run_setup_script=OFF --build_arrow=OFF
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
./build/mvn clean install -Pbackends-velox -Pspark-4.2 -Pscala-2.13 -Pjava-17 -DskipTests
'
```
3. Fetch Spark 4.2.0:
```bash
curl -sSL https://archive.apache.org/dist/spark/spark-4.2.0/spark-4.2.0-bin-hadoop3.tgz | tar -xz
```
4. Write two queries that insert from a Parquet table into a NOT NULL column. Spark 4.2 checks NOT NULL on file source inserts only with [spark.sql.fileSource.insert.enforceNotNull](https://github.com/apache/spark/blob/v4.2.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala#L5170-L5176), and the queries turn off ANSI mode, which Gluten falls back to Spark for:
```bash
cat > fits.sql <<'EOF'
SET spark.sql.ansi.enabled=false;
SET spark.sql.fileSource.insert.enforceNotNull=true;
DROP TABLE IF EXISTS src;
DROP TABLE IF EXISTS t;
CREATE TABLE src USING parquet AS SELECT 1 AS i;
CREATE TABLE t (i INT NOT NULL) USING parquet;
INSERT INTO t SELECT i FROM src;
SELECT i FROM t;
EOF
cat > null.sql <<'EOF'
SET spark.sql.ansi.enabled=false;
SET spark.sql.fileSource.insert.enforceNotNull=true;
DROP TABLE IF EXISTS src;
DROP TABLE IF EXISTS t;
CREATE TABLE src USING parquet AS SELECT CAST(NULL AS INT) AS i;
CREATE TABLE t (i INT NOT NULL) USING parquet;
INSERT INTO t SELECT i FROM src;
EOF
```
5. Run each query with Gluten, and print the exception it fails with and Velox's reason, if any:
```bash
docker run --rm -v "$PWD":/work/gluten:z apache/gluten:centos-9-jdk8 bash -c '
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
cd /work/gluten
BUNDLE=$(ls package/target/gluten-velox-bundle-spark4.2_2.13-linux_amd64-*.jar)
for q in fits.sql null.sql; do
spark-4.2.0-bin-hadoop3/bin/spark-sql --master "local[2]" \
--jars "$BUNDLE" --driver-class-path "$BUNDLE" \
--conf spark.plugins=org.apache.gluten.GlutenPlugin \
--conf spark.memory.offHeap.enabled=true \
--conf spark.memory.offHeap.size=4g \
--conf spark.shuffle.manager=org.apache.spark.shuffle.sort.ColumnarShuffleManager \
-f "$q" 2>err.log
grep -m 1 -E "^org\.apache\.[a-z.]+\.[A-Za-z]+Exception: " err.log
grep -m 1 "^Reason:" err.log
done
'
```
On the base commit, the null fails with a [GlutenException](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-core/src/main/java/org/apache/gluten/exception/GlutenException.java#L19) that wraps Velox's error:
```
spark.sql.ansi.enabled false
spark.sql.fileSource.insert.enforceNotNull true
1
spark.sql.ansi.enabled false
spark.sql.fileSource.insert.enforceNotNull true
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: Null value appeared in non-nullable field
```
On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:
```
spark.sql.ansi.enabled false
spark.sql.fileSource.insert.enforceNotNull true
1
spark.sql.ansi.enabled false
spark.sql.fileSource.insert.enforceNotNull true
org.apache.spark.SparkRuntimeException: [NOT_NULL_ASSERT_VIOLATION] NULL value appeared in non-nullable field:
Reason: Null value appeared in non-nullable field
```
Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with the same exception:
```
spark.sql.ansi.enabled false
spark.sql.fileSource.insert.enforceNotNull true
1
spark.sql.ansi.enabled false
spark.sql.fileSource.insert.enforceNotNull true
org.apache.spark.SparkRuntimeException: [NOT_NULL_ASSERT_VIOLATION] NULL value appeared in non-nullable field:
```
Spark's message continues with the field, `i`, where Gluten's message has none:
```bash
grep -m 1 -A 2 "^org.apache.spark.SparkRuntimeException" err.log
```
```
org.apache.spark.SparkRuntimeException: [NOT_NULL_ASSERT_VIOLATION] NULL value appeared in non-nullable field:
i
If the schema is inferred from a Scala tuple/case class, or a Java bean, please try to use scala.Option[_] or other nullable types (such as java.lang.Integer instead of int/scala.Int). SQLSTATE: 42000
```
### Automated tests
Inside the `apache/gluten:centos-9-jdk8` image, with JDK 17 and `SPARK_ANSI_SQL_MODE=false`, which [Gluten's CI sets](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/.github/workflows/velox_backend_x86.yml#L72-L73), these suites pass on Spark 4.0:
```bash
SPARK_ANSI_SQL_MODE=false ./build/mvn -ntp -B clean test -Pspark-4.0 -Pscala-2.13 -Pjava-17 -Pbackends-velox -Pspark-ut -pl gluten-ut/spark40 -am -DargLine="-Dspark.test.home=/opt/shims/spark40/spark_home/" -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.spark.sql.GlutenRuntimeNullChecksV2Writes,org.apache.spark.sql.connector.GlutenDataSourceV2SQLSuiteV1Filter,org.apache.spark.sql.sources.GlutenInsertSuite,org.apache.spark.sql.connector.GlutenGroupBasedUpdateTableSuite,org.apache.spark.sql.connector.GlutenDeltaBasedMergeIntoTableSuite,org.apache.spark.sql.connector.GlutenDeltaBasedMergeIntoTableUpdateAsDeleteAndInsertSuite,org.apache.spark.sql.connector.GlutenGroupBasedMergeIntoTableSuite,org.apache.spark.sql.connector.GlutenDeltaBasedUpdateAsDeleteAndInsertTableSuite,org.apache.spark.sql.connector.GlutenDeltaBasedUpdateTableSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```
```
GlutenRuntimeNullChecksV2Writes:
…
- NOT NULL checks for atomic top-level fields (byName)
…
GlutenDataSourceV2SQLSuiteV1Filter:
…
- CreateTableAsSelect: nullable schema
…
GlutenInsertSuite:
…
- SPARK-24583 Wrong schema type in InsertIntoDataSourceCommand
…
GlutenDeltaBasedMergeIntoTableSuite:
…
- merge with NOT NULL checks
…
Tests: succeeded 567, failed 0, canceled 0, ignored 38, pending 0
All tests passed.
```
Spark 4.1 runs the same command with `-Pspark-4.1`, `gluten-ut/spark41` and `/opt/shims/spark41/spark_home/`:
```
Tests: succeeded 860, failed 0, canceled 0, ignored 38, pending 0
All tests passed.
```
Spark 4.2 runs it with `-Pspark-4.2`, `gluten-ut/spark42` and `/opt/shims/spark42/spark_home/`:
```
GlutenInsertSuite:
…
- SPARK-55716: V1 INSERT rejects null into NOT NULL column for file sources
…
GlutenGroupBasedMergeIntoTableSuite:
…
- merge with NOT NULL checks
…
GlutenDeltaBasedUpdateTableSuite:
…
- Gluten - update with constraint violation and transactional checks
…
Tests: succeeded 813, failed 0, canceled 0, ignored 41, pending 0
All tests passed.
```
On Spark 3.5, [GlutenRuntimeNullChecksV2Writes](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenRuntimeNullChecksV2Writes.scala#L28) passes with JDK 8:
```bash
./build/mvn -ntp -B clean test -Pspark-3.5 -Pbackends-velox -Pspark-ut -pl gluten-ut/spark35 -am -DargLine="-Dspark.test.home=/opt/shims/spark35/spark_home/" -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.spark.sql.GlutenRuntimeNullChecksV2Writes -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```
```
Tests: succeeded 8, failed 0, canceled 0, ignored 14, pending 0
All tests passed.
```
The change also compiles against Spark 3.4:
```bash
./build/mvn -ntp -B test-compile -Pbackends-velox -Pspark-ut -Pspark-3.4 -pl gluten-ut/spark34 -am
```
```
[INFO] BUILD SUCCESS
```
## Was this patch authored or co-authored using generative AI tooling?
Generated-by: Co-authored with Claude Code (claude-opus-5-5)
pedrumj2
force-pushed
the
gluten-11912-not-null-assert-violation
branch
from
November 26, 2026 05:01
e32b690 to
f13fcba
Compare
|
Run Gluten Clickhouse CI on x86 |
pedrumj2
added a commit
to pedrumj2/gluten
that referenced
this pull request
Nov 26, 2026
Merging `main` into this branch resolved its overlap with apache#13780 in `ColumnarBatchOutIterator.java` by dropping five lines: the closing brace of `translateToInvalidBitPositionException`, the `/**` that opens the Javadoc after it, the closing brace of the `bitPositionEx` check, and two blank lines. Without them the file does not compile. This commit puts them back, so the file is `main`'s version plus this pull request's additions. Generated-by: Co-authored with Claude Code (claude-opus-5-5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes are proposed in this pull request?
This PR translates a gluten exception to Spark exception:
.exclude("some function")in tests1intoINT NOT NULLNULLintoINT NOT NULLNOT_NULL_ASSERT_VIOLATIONGlutenExceptionNOT_NULL_ASSERT_VIOLATIONPlease see the following discussions #13647, #13685 and facebookincubator/velox#20483
Conclusion can be found here
How was this patch tested?
Reproduction
git clone https://github.com/apache/gluten.git cd gluten git checkout 85c89803ed2d050db4052f1813d76711ebe29fb8curl -sSL https://archive.apache.org/dist/spark/spark-4.2.0/spark-4.2.0-bin-hadoop3.tgz | tar -xzOn the base commit, the null fails with a GlutenException that wraps Velox's error:
On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:
Spark without Gluten, which is step 5's
spark-sqlcommand keeping only--master, fails with the same exception:Spark's message continues with the field,
i, where Gluten's message has none:grep -m 1 -A 2 "^org.apache.spark.SparkRuntimeException" err.logAutomated tests
Inside the
apache/gluten:centos-9-jdk8image, with JDK 17 andSPARK_ANSI_SQL_MODE=false, which Gluten's CI sets, these suites pass on Spark 4.0:Spark 4.1 runs the same command with
-Pspark-4.1,gluten-ut/spark41and/opt/shims/spark41/spark_home/:Spark 4.2 runs it with
-Pspark-4.2,gluten-ut/spark42and/opt/shims/spark42/spark_home/:On Spark 3.5, GlutenRuntimeNullChecksV2Writes passes with JDK 8:
The change also compiles against Spark 3.4:
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Co-authored with Claude Code (claude-opus-5-5)
Related issue: #11912