Skip to content

[GLUTEN-11912][VL] Translate Velox char/varchar length errors to Spark's exception - #13639

Merged
zhztheplayer merged 6 commits into
apache:mainfrom
pedrumj2:char-varchar-exceed-limit-length
Nov 24, 2026
Merged

zhztheplayer merged 6 commits into
apache:mainfrom
pedrumj2:char-varchar-exceed-limit-length

Conversation

@pedrumj2

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Spark fails an insert of a char or varchar value that is longer than its declared length with EXCEED_LIMIT_LENGTH, while the Velox backend failed it with a GlutenException carrying Velox's own message (CharVarcharUtils.cpp). With this change, the Velox backend fails with Spark's exception.

Inserted value Spark 3.5.5 without Gluten Gluten before this change Gluten after this change
'12345' into VARCHAR(5) Inserted Inserted Inserted
'123456' into VARCHAR(5) EXCEED_LIMIT_LENGTH GlutenException EXCEED_LIMIT_LENGTH
'123456' into CHAR(5) EXCEED_LIMIT_LENGTH GlutenException EXCEED_LIMIT_LENGTH

Part of #11912

How was this patch tested?

Reproduction

  1. Clone the repo and check out the base commit:
git clone https://github.com/apache/gluten.git
cd gluten
git checkout 31fb4dad58e7339ac4f4b820931d648160dc4746
  1. Build the native libraries and the bundle jar:
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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
  1. Fetch Spark 3.5.5:
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
  1. Write three queries that insert from a Parquet table:
cat > fits.sql <<'EOF'
DROP TABLE IF EXISTS src;
DROP TABLE IF EXISTS t;
CREATE TABLE src USING parquet AS SELECT '12345' AS s;
CREATE TABLE t (c VARCHAR(5)) USING parquet;
INSERT INTO t SELECT s FROM src;
SELECT c FROM t;
EOF
cat > varchar.sql <<'EOF'
DROP TABLE IF EXISTS src;
DROP TABLE IF EXISTS t;
CREATE TABLE src USING parquet AS SELECT '123456' AS s;
CREATE TABLE t (c VARCHAR(5)) USING parquet;
INSERT INTO t SELECT s FROM src;
EOF
cat > char.sql <<'EOF'
DROP TABLE IF EXISTS src;
DROP TABLE IF EXISTS t;
CREATE TABLE src USING parquet AS SELECT '123456' AS s;
CREATE TABLE t (c CHAR(5)) USING parquet;
INSERT INTO t SELECT s FROM src;
EOF
  1. Run each query with Gluten, and print the exception it fails with and Velox's reason, if any:
docker run --rm -v "$PWD":/work/gluten:z apache/gluten:centos-9-jdk8 bash -c '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  for q in fits.sql varchar.sql char.sql; do
    spark-3.5.5-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 "Job aborted" err.log | sed "s/.*executor driver): //"
    grep -m 1 "^Reason:" err.log
  done
'

On the base commit, both too-long values fail with a GlutenException that wraps Velox's error:

12345
org.apache.gluten.exception.GlutenException: org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: (6 vs. 5) Exceeds allowed length limitation: 5
org.apache.gluten.exception.GlutenException: org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: (6 vs. 5) Exceeds allowed length limitation: 5

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

12345
org.apache.spark.SparkRuntimeException: [EXCEED_LIMIT_LENGTH] Exceeds char/varchar type length limitation: 5.
Reason: (6 vs. 5) Exceeds allowed length limitation: 5
org.apache.spark.SparkRuntimeException: [EXCEED_LIMIT_LENGTH] Exceeds char/varchar type length limitation: 5.
Reason: (6 vs. 5) Exceeds allowed length limitation: 5

Spark without Gluten, which is step 5's spark-sql command keeping only --master, wraps the same exception in TASK_WRITE_FAILED:

12345
org.apache.spark.SparkException: [TASK_WRITE_FAILED] Task failed while writing rows to file:/work/gluten/spark-warehouse/t.
org.apache.spark.SparkException: [TASK_WRITE_FAILED] Task failed while writing rows to file:/work/gluten/spark-warehouse/t.
grep -m 1 "^Caused by: org.apache.spark.SparkRuntimeException" err.log
Caused by: org.apache.spark.SparkRuntimeException: [EXCEED_LIMIT_LENGTH] Exceeds char/varchar type length limitation: 5.

Automated tests

Inside the apache/gluten:centos-9-jdk8 image, the char/varchar suites pass on Spark 3.5:

./build/mvn -B clean install -Pbackends-velox -Pspark-3.5 -Pspark-ut -DskipTests -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
./build/mvn -B test -Pbackends-velox -Pspark-3.5 -Pspark-ut -pl gluten-ut/spark35 -DargLine="-Dspark.test.home=/opt/shims/spark35/spark_home/" -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.spark.sql.GlutenFileSourceCharVarcharTestSuite,org.apache.spark.sql.GlutenDSV2CharVarcharTestSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
GlutenFileSourceCharVarcharTestSuite:
…
- length check for input string values: nested in map key
…
- Gluten - length check for input string values: partitioned columns
- Gluten - char/varchar type values length check: partitioned columns of other types
…
Tests: succeeded 101, failed 0, canceled 0, ignored 2, pending 0
All tests passed.

On Spark 3.4, with the same two commands using -Pspark-3.4, gluten-ut/spark34 and /opt/shims/spark34/spark_home/:

GlutenFileSourceCharVarcharTestSuite:
…
- length check for input string values: nested in map key
…
- Gluten - length check for input string values: partitioned columns
- Gluten - char/varchar type values length check: partitioned columns of other types
…
Tests: succeeded 100, failed 0, canceled 0, ignored 2, pending 0
All tests passed.

On Spark 4.0, 4.1 and 4.2, with JDK 17 and SPARK_ANSI_SQL_MODE=false, which Gluten's CI sets:

./build/mvn -B clean install -Pbackends-velox -Pspark-4.0 -Pscala-2.13 -Pjava-17 -Pspark-ut -DskipTests -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
SPARK_ANSI_SQL_MODE=false ./build/mvn -B test -Pbackends-velox -Pspark-4.0 -Pscala-2.13 -Pjava-17 -Pspark-ut -pl gluten-ut/spark40 -DargLine="-Dspark.test.home=/opt/shims/spark40/spark_home/" -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.spark.sql.GlutenFileSourceCharVarcharTestSuite,org.apache.spark.sql.GlutenDSV2CharVarcharTestSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
GlutenFileSourceCharVarcharTestSuite:
…
- length check for input string values: nested in map key
…
Tests: succeeded 118, failed 0, canceled 1, ignored 0, pending 0
All tests passed.

Spark 4.1 runs the same commands with -Pspark-4.1, gluten-ut/spark41 and /opt/shims/spark41/spark_home/:

Tests: succeeded 118, failed 0, canceled 1, ignored 0, pending 0
All tests passed.

Spark 4.2 runs them with -Pspark-4.2, gluten-ut/spark42 and no -DargLine, adding GlutenResolveDefaultColumnsSuite to -DwildcardSuites:

GlutenResolveDefaultColumnsSuite:
…
- SPARK-57187: non-foldable default exceeding CHAR/VARCHAR length fails at INSERT time (explicit DEFAULT keyword)
…
Tests: succeeded 138, failed 0, canceled 1, ignored 0, pending 0
All tests passed.

The canceled test on Spark 4.0, 4.1 and 4.2 is SPARK-48792: Fix INSERT with partial column list to a table with char/varchar, which Spark cancels itself with an assume.

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

Generated-by: Co-authored with Claude Code (claude-opus-5-5)

Pedrum Jalali and others added 2 commits November 11, 2026 15:29
…k's exception

## What changes are proposed in this pull request?

Spark fails an insert of a char or varchar value that is longer than its declared length with [EXCEED_LIMIT_LENGTH](https://github.com/apache/spark/blob/v3.5.5/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/CharVarcharCodegenUtils.java#L31), while the Velox backend failed it with a [GlutenException](https://github.com/apache/gluten/blob/31fb4dad58e7339ac4f4b820931d648160dc4746/gluten-core/src/main/java/org/apache/gluten/exception/GlutenException.java) carrying Velox's own message ([CharVarcharUtils.cpp](https://github.com/IBM/velox/blob/6deac80271569277bf54b6d04547620c17438348/velox/functions/sparksql/CharVarcharUtils.cpp#L37-L38)). With this change, the Velox backend fails with Spark's exception.

| Inserted value | Spark 3.5.5 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `'12345'` into `VARCHAR(5)` | Inserted | Inserted | Inserted |
| `'123456'` into `VARCHAR(5)` | `EXCEED_LIMIT_LENGTH` | `GlutenException` | `EXCEED_LIMIT_LENGTH` |
| `'123456'` into `CHAR(5)` | `EXCEED_LIMIT_LENGTH` | `GlutenException` | `EXCEED_LIMIT_LENGTH` |

[apache#9107](apache#9107) moved Spark's char/varchar length check into Velox; before it, Spark ran the check and threw its own exception. Since then, Spark's tests for this error have been excluded, replaced with Gluten copies that look for Velox's text, or checked with an assertion that also accepts Velox's text, so CI did not catch the different exception. With this change, those tests run again on Spark 4.0, 4.1 and 4.2, and all but two of them run again on Spark 3.4 and 3.5. Code that matches on the EXCEED_LIMIT_LENGTH condition now gets it under Gluten, as it does in Spark.

[length check for input string values: partitioned columns](https://github.com/apache/spark/blob/v3.5.5/sql/core/src/test/scala/org/apache/spark/sql/CharVarcharTestSuite.scala#L332-L349) and [char/varchar type values length check: partitioned columns of other types](https://github.com/apache/spark/blob/v3.5.5/sql/core/src/test/scala/org/apache/spark/sql/CharVarcharTestSuite.scala#L1037-L1066) stay excluded on Spark 3.4 and 3.5. Spark expects the error of these partitioned inserts wrapped in [TASK_WRITE_FAILED](https://github.com/apache/spark/blob/v3.5.5/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormatWriter.scala#L419-L420), and Gluten throws it unwrapped. The Gluten copies of these two tests now check for Spark's exception instead of Velox's text.

On Spark 3.4, which has no error class for this, Gluten throws the [plain RuntimeException](https://github.com/apache/spark/blob/v3.4.4/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/CharVarcharCodegenUtils.java#L30) that Spark 3.4 throws.

Part of apache#11912

## 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 31fb4da
```

2. Build the native libraries and the 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write three queries that insert from a Parquet table:

```bash
cat > fits.sql <<'EOF'
DROP TABLE IF EXISTS src;
DROP TABLE IF EXISTS t;
CREATE TABLE src USING parquet AS SELECT '12345' AS s;
CREATE TABLE t (c VARCHAR(5)) USING parquet;
INSERT INTO t SELECT s FROM src;
SELECT c FROM t;
EOF
cat > varchar.sql <<'EOF'
DROP TABLE IF EXISTS src;
DROP TABLE IF EXISTS t;
CREATE TABLE src USING parquet AS SELECT '123456' AS s;
CREATE TABLE t (c VARCHAR(5)) USING parquet;
INSERT INTO t SELECT s FROM src;
EOF
cat > char.sql <<'EOF'
DROP TABLE IF EXISTS src;
DROP TABLE IF EXISTS t;
CREATE TABLE src USING parquet AS SELECT '123456' AS s;
CREATE TABLE t (c CHAR(5)) USING parquet;
INSERT INTO t SELECT s 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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  for q in fits.sql varchar.sql char.sql; do
    spark-3.5.5-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 "Job aborted" err.log | sed "s/.*executor driver): //"
    grep -m 1 "^Reason:" err.log
  done
'
```

On the base commit, both too-long values fail with a `GlutenException` that wraps Velox's error:

```
12345
org.apache.gluten.exception.GlutenException: org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: (6 vs. 5) Exceeds allowed length limitation: 5
org.apache.gluten.exception.GlutenException: org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: (6 vs. 5) Exceeds allowed length limitation: 5
```

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

```
12345
org.apache.spark.SparkRuntimeException: [EXCEED_LIMIT_LENGTH] Exceeds char/varchar type length limitation: 5.
Reason: (6 vs. 5) Exceeds allowed length limitation: 5
org.apache.spark.SparkRuntimeException: [EXCEED_LIMIT_LENGTH] Exceeds char/varchar type length limitation: 5.
Reason: (6 vs. 5) Exceeds allowed length limitation: 5
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, wraps the same exception in `TASK_WRITE_FAILED`:

```
12345
org.apache.spark.SparkException: [TASK_WRITE_FAILED] Task failed while writing rows to file:/work/gluten/spark-warehouse/t.
org.apache.spark.SparkException: [TASK_WRITE_FAILED] Task failed while writing rows to file:/work/gluten/spark-warehouse/t.
```

```bash
grep -m 1 "^Caused by: org.apache.spark.SparkRuntimeException" err.log
```

```
Caused by: org.apache.spark.SparkRuntimeException: [EXCEED_LIMIT_LENGTH] Exceeds char/varchar type length limitation: 5.
```

### Automated tests

Inside the `apache/gluten:centos-9-jdk8` image, the char/varchar suites pass on Spark 3.5:

```bash
./build/mvn -B clean install -Pbackends-velox -Pspark-3.5 -Pspark-ut -DskipTests -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
./build/mvn -B test -Pbackends-velox -Pspark-3.5 -Pspark-ut -pl gluten-ut/spark35 -DargLine="-Dspark.test.home=/opt/shims/spark35/spark_home/" -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.spark.sql.GlutenFileSourceCharVarcharTestSuite,org.apache.spark.sql.GlutenDSV2CharVarcharTestSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenFileSourceCharVarcharTestSuite:
…
- length check for input string values: nested in map key
…
- Gluten - length check for input string values: partitioned columns
- Gluten - char/varchar type values length check: partitioned columns of other types
…
Tests: succeeded 101, failed 0, canceled 0, ignored 2, pending 0
All tests passed.
```

On Spark 3.4, with the same two commands using `-Pspark-3.4`, `gluten-ut/spark34` and `/opt/shims/spark34/spark_home/`:

```
GlutenFileSourceCharVarcharTestSuite:
…
- length check for input string values: nested in map key
…
- Gluten - length check for input string values: partitioned columns
- Gluten - char/varchar type values length check: partitioned columns of other types
…
Tests: succeeded 100, failed 0, canceled 0, ignored 2, pending 0
All tests passed.
```

On Spark 4.0, 4.1 and 4.2, with JDK 17 and `SPARK_ANSI_SQL_MODE=false`, which [Gluten's CI sets](https://github.com/apache/gluten/blob/31fb4dad58e7339ac4f4b820931d648160dc4746/.github/workflows/velox_backend_x86.yml#L65-L66):

```bash
./build/mvn -B clean install -Pbackends-velox -Pspark-4.0 -Pscala-2.13 -Pjava-17 -Pspark-ut -DskipTests -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
SPARK_ANSI_SQL_MODE=false ./build/mvn -B test -Pbackends-velox -Pspark-4.0 -Pscala-2.13 -Pjava-17 -Pspark-ut -pl gluten-ut/spark40 -DargLine="-Dspark.test.home=/opt/shims/spark40/spark_home/" -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.spark.sql.GlutenFileSourceCharVarcharTestSuite,org.apache.spark.sql.GlutenDSV2CharVarcharTestSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenFileSourceCharVarcharTestSuite:
…
- length check for input string values: nested in map key
…
Tests: succeeded 118, failed 0, canceled 1, ignored 0, pending 0
All tests passed.
```

Spark 4.1 runs the same commands with `-Pspark-4.1`, `gluten-ut/spark41` and `/opt/shims/spark41/spark_home/`:

```
Tests: succeeded 118, failed 0, canceled 1, ignored 0, pending 0
All tests passed.
```

Spark 4.2 runs them with `-Pspark-4.2`, `gluten-ut/spark42` and no `-DargLine`, adding [GlutenResolveDefaultColumnsSuite](https://github.com/apache/gluten/blob/31fb4dad58e7339ac4f4b820931d648160dc4746/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/GlutenResolveDefaultColumnsSuite.scala) to `-DwildcardSuites`:

```
GlutenResolveDefaultColumnsSuite:
…
- SPARK-57187: non-foldable default exceeding CHAR/VARCHAR length fails at INSERT time (explicit DEFAULT keyword)
…
Tests: succeeded 138, failed 0, canceled 1, ignored 0, pending 0
All tests passed.
```

The canceled test on Spark 4.0, 4.1 and 4.2 is [SPARK-48792: Fix INSERT with partial column list to a table with char/varchar](https://github.com/apache/spark/blob/v4.0.2/sql/core/src/test/scala/org/apache/spark/sql/CharVarcharTestSuite.scala#L687), which Spark cancels itself with an `assume`.

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

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
@github-actions github-actions Bot added CORE works for Gluten Core VELOX labels Nov 13, 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

@pedrumj2

Copy link
Copy Markdown
Contributor Author

@rui-mo @philo-he if you get the chance would appreciate if you can take a look here.

This is more of a code clean up PR. I notice we have test exclusions and test overrides since the exceptions velox engine throws is different than that of spark:

.exclude("length check for input string values: nested in map key")

Wondering if this would be a direction the repository would want to take and ensure engine exceptions are translated back to spark exceptions. This would avoid the test overrides.

I saw the necessary hooks were enabled in https://github.com/apache/gluten/pull/11684/changes wondering if we'd want to expand on that

Thanks!

@pedrumj2
pedrumj2 marked this pull request as ready for review November 14, 2026 00:19

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

@pedrumj2, thanks for the PR!

Could we adapt the test checker instead? On Spark 4.x, all length checks go through assertLengthCheckFailure, so the Gluten suite can override it to accept any exception whose cause chain contains Velox's Exceeds allowed length limitation: <n>. Then the copied 4.x tests can be removed. On Spark 3.4 / 3.5, the checks are inline in each test, so I think we can keep the existing Gluten copies there. Since Spark 3.4 support will be removed soon (#13573), that leaves only the Spark 3.5 copies, which should be fine to keep.

The point is that a different exception type or message should be fine for users, as long as the query fails for the same reason and the message clearly explains it. Does this make sense?

@pedrumj2

pedrumj2 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

@pedrumj2, thanks for the PR!

Could we adapt the test checker instead? On Spark 4.x, all length checks go through assertLengthCheckFailure, so the Gluten suite can override it to accept any exception whose cause chain contains Velox's Exceeds allowed length limitation: <n>. Then the copied 4.x tests can be removed. On Spark 3.4 / 3.5, the checks are inline in each test, so I think we can keep the existing Gluten copies there. Since Spark 3.4 support will be removed soon (#13573), that leaves only the Spark 3.5 copies, which should be fine to keep.

The point is that a different exception type or message should be fine for users, as long as the query fails for the same reason and the message clearly explains it. Does this make sense?

Thanks for the review @philo-he

Could we adapt the test checker instead? On Spark 4.x, all length checks go through assertLengthCheckFailure, so the Gluten suite can override it to accept any exception whose cause chain contains Velox's Exceeds allowed length limitation: <n>

I can definitely follow with using the test checker. However I was thinking a bit more broadly how we can solve this test duplication overall. Seems to be common pattern.

My only concern is that with this approach we would rely on the spark repo to provide us with these test helpers. Please see this comment while they do add them from time to time, it seems overall they are reluctant to provide them consistently:

I think we shouldn't really change the test code for other projects to use .. but if this is the only one, one time thing should be fine.

The point is that a different exception type or message should be fine for users, as long as the query fails for the same reason and the message clearly explains it. Does this make sense?

I agree, this definitely make sense:

  • Option1: Have a gluten exception type with a different user facing message than Spark
  • Option2: Maintain same exception with Spark wrapped in a gluten exception

For my own understanding is option1 the direction the repo wants to take? I feel there might be some benefits to exploring option2 if folks are open to considering it? Do you think it would be worthwhile to have a broader discussion on this? I opened an issue here #13647

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

}

override def charVarcharLengthExceededError(limit: Int, cause: Throwable): RuntimeException =
GlutenQueryExecutionErrors.exceedMaxLimit(limit, cause)

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.

Why we need a new class GlutenQueryExecutionErrors here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking a look @zhztheplayer

Why we need a new class GlutenQueryExecutionErrors here?

TLDR: its to access package private class in Spark.

Spark calls exceedMaxLimit which belongs to QueryExceptionErrors which is a package private class inside package org.apache.spark.sql. It throws a SparkRuntimeException which is also another package private class inside org.apache.spark and can only be reached by classes inside those packages and their nested packages.

The Gluten shims are inside org.apache.gluten so they won't be able to access any of those classes. The goal with this extra class is to allow access to those package private methods.

But please let me know if there is a better approach here, thanks!

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

Hi @pedrumj2, thanks for working on this!

I think it would be helpful to have a broader discussion on the long-term direction before moving forward with this PR.

As highlighted in SPARK-46922, aligning exception behavior is not just about avoiding the need to rewrite certain UTs in Gluten, but also about ensuring that users receive the correct, unwrapped error messages.

With that in mind, I'm wondering whether message-based translation would be sufficient to reliably map exceptions thrown by Velox to the corresponding Spark error classes. The reliability of this approach would depend on the stability of Velox's error messages and whether they contain enough information to identify the correct Spark error class and its parameters.

Given this, we may need to extend Velox to expose Spark-compatible error codes, which Gluten could then translate into the appropriate Spark exceptions and error classes. This might provide a more robust and maintainable solution in the long run.

@Abhinav-Agarwal021 has more context on this and may want to initiate a broader discussion to help us align on the approach before moving forward.

@Abhinav-Agarwal021

Copy link
Copy Markdown

Thanks @rui-mo, I agree. Message matching works for a single fixed message, but it can't reliably pick the Spark error class or fill its parameters. For example, Velox's Arithmetic overflow: a + b doesn't say integer vs long, and division by zero is used for both DIVIDE_BY_ZERO and REMAINDER_BY_ZERO. A Velox rewording would also break the mapping without failing any Gluten test.

I've opened a design proposal for the runtime side: #13685. A matching Velox issue will follow for the Velox-side changes. In short:

  • Contract: Velox Spark functions (velox/functions/sparksql) raise errors with a Spark (condition, params) pair, using names from Spark's error-conditions.json. Shared Presto/Spark helpers don't name Spark classes, so Presto doesn't change.
  • Translation on the executor: Gluten's translateException turns the pair into the real Spark exception through a per-Spark-version shim that calls Spark's own QueryExecutionErrors factories. On Spark 4.x, DAGScheduler then passes it to the user unwrapped (SPARK-46922) instead of Job aborted due to stage failure. Anything it can't translate falls back to today's GlutenException.
  • Transport: start with a structured marker in the Velox reason (no core Velox or JNI change, and nothing extra on the success path or inside TRY). The same contract lets us move to a typed Velox exception later without touching raise sites or shims.
  • Scope: about 30 Spark error classes in phases, starting with ANSI arithmetic. This PR's EXCEED_LIMIT_LENGTH and [VL] Translate native cast failures into Spark exceptions #13135's cast classes fit directly into it.

It also covers the open questions, including whether PRs like this one should land now and migrate later. Feedback welcome there. cc @pedrumj2 @philo-he @zhztheplayer

@zhztheplayer

Copy link
Copy Markdown
Member

It also covers the open questions, including whether PRs like this one should land now and migrate later. Feedback welcome there.

@Abhinav-Agarwal021 Regarding this PR it self I don't think there's a clear need to hold off since it's following the current design of translateException API introduced in PR #11684. But the changes in shim layers do look a bit lengthy and might have alternative cleaner approaches.

cc @pedrumj2 Would you help check whether we can drop the shim changes and inline some reflection code in translateToCharVarcharLengthException for same purpose? Seems a big potential to shorten the PR.

Drop the SparkShims method and the GlutenQueryExecutionErrors helpers.
ColumnarBatchOutIterator now builds SparkRuntimeException reflectively
and falls back to the plain RuntimeException Spark 3.4 throws.

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@pedrumj2
pedrumj2 marked this pull request as draft November 19, 2026 21:15
Java code can call SparkRuntimeException's constructor from any package,
because its private[spark] modifier is enforced only by the Scala
compiler. On Spark 3.4, which has no EXCEED_LIMIT_LENGTH error class,
SparkVersionUtil.gteSpark35 selects the plain RuntimeException that
Spark 3.4 throws itself.

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Map.Map1 is Scala's one-entry immutable map, and Java can create it
directly, so the parameter map no longer goes through Map$.MODULE$. It
also removes the unchecked warnings javac reported on the Scala 2.13
builds, where Map.updated reaches Java as a raw Map.

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
@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

@pedrumj2
pedrumj2 force-pushed the char-varchar-exceed-limit-length branch from d1ab6b0 to 21eef10 Compare November 22, 2026 01: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

@pedrumj2
pedrumj2 marked this pull request as ready for review November 22, 2026 04:49
@pedrumj2
pedrumj2 marked this pull request as draft November 22, 2026 05:24
@pedrumj2
pedrumj2 deleted the char-varchar-exceed-limit-length branch November 24, 2026 17:57
pedrumj2 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…ption

## What changes are proposed in this pull request?

| Query | Spark 3.5.5 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `raise_error(s)`, where `s` is `'hello'` | `RuntimeException: hello` | `GlutenException` | `RuntimeException: hello` |
| `assert_true(a > b, 'a is not greater than b')`, where `a` is 1 and `b` is 2 | `RuntimeException: a is not greater than b` | `GlutenException` | `RuntimeException: a is not greater than b` |

- apache#13647 proposes translating Velox exceptions to Spark's.
- apache#13685 proposes carrying Spark error classes from Velox instead of matching Velox's message text.
- facebookincubator/velox#20483 proposes raising Spark error classes from Velox's Spark functions.
- Conclusion: keep translating by message text until the Velox changes are ready, per [apache#13639 (comment)](apache#13639 (comment)).

Part of apache#11912

## 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 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write two queries that raise an error from a Parquet table's values:

```bash
cat > raise_error.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT 'hello' AS s;
SELECT raise_error(s) FROM src;
EOF
cat > assert_true.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT 1 AS a, 2 AS b;
SELECT assert_true(a > b, 'a is not greater than b') 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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  for q in raise_error.sql assert_true.sql; do
    spark-3.5.5-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 "Job aborted" err.log | sed "s/.*executor driver): //"
    grep -m 1 "^Reason:" err.log
  done
'
```

On the base commit, both queries fail 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:

```
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: hello
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: a is not greater than b
```

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

```
java.lang.RuntimeException: hello
Reason: hello
java.lang.RuntimeException: a is not greater than b
Reason: a is not greater than b
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with the same exception:

```
java.lang.RuntimeException: hello
java.lang.RuntimeException: a is not greater than b
```

### 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), [GlutenColumnExpressionSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenColumnExpressionSuite.scala#L25) and [GlutenCachedTableSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenCachedTableSuite.scala#L29) 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.GlutenColumnExpressionSuite,org.apache.spark.sql.GlutenCachedTableSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenColumnExpressionSuite:
…
- raise_error
…
- assert_true
…
GlutenCachedTableSuite:
…
- SPARK-52684: Atomicity of cache table on error
…
Tests: succeeded 228, failed 0, canceled 0, ignored 4, pending 0
All tests passed.
```

On Spark 4.1 and 4.2, which run the same command with `-Pspark-4.1`, `gluten-ut/spark41` and `/opt/shims/spark41/spark_home/` or their 4.2 counterparts, the same tests pass. The one failure on each is [SPARK-52692: Support cache/uncache table with Time type](https://github.com/apache/spark/blob/v4.2.0/sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala#L1839), which fails the same way on the base commit with `[UNSUPPORTED_TIME_TYPE] The data type TIME is not supported`:

```
Tests: succeeded 254, failed 1, canceled 0, ignored 4, pending 0
```

```
Tests: succeeded 256, failed 1, canceled 0, ignored 4, pending 0
```

On Spark 3.5 with JDK 8, `GlutenColumnExpressionSuite` and [GlutenSQLQueryTestSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenSQLQueryTestSuite.scala#L61) pass:

```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.GlutenColumnExpressionSuite,org.apache.spark.sql.GlutenSQLQueryTestSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenColumnExpressionSuite:
…
- raise_error
…
- assert_true
…
GlutenSQLQueryTestSuite:
…
- misc-functions.sql
…
Tests: succeeded 363, failed 0, canceled 0, ignored 104, pending 0
All tests passed.
```

On Spark 3.4, with `-Pspark-3.4`, `gluten-ut/spark34` and `/opt/shims/spark34/spark_home/`, where [misc-functions.sql](https://github.com/apache/spark/blob/v3.4.4/sql/core/src/test/resources/sql-tests/inputs/misc-functions.sql) now runs from Spark's own files:

```
Tests: succeeded 372, failed 0, canceled 0, ignored 84, pending 0
All tests passed.
```

[ScalarFunctionsValidateSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala#L31) passes on every Spark version, shown here for 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 -pl backends-velox -am -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.gluten.functions.ScalarFunctionsValidateSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
Tests: succeeded 95, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
```

On Spark 4.1 and 4.2 it reports the same totals. On Spark 3.5, 94 tests succeed with no failures. On Spark 3.4, 92 tests succeed with no failures.

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

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
pedrumj2 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…s DUPLICATED_MAP_KEY exception

## What changes are proposed in this pull request?

| Query | Spark 3.5.5 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `map_from_arrays(array(1, 1), array(10, 20))` | `DUPLICATED_MAP_KEY` | `GlutenException` | `DUPLICATED_MAP_KEY` |
| `map_concat(map(1, 100), map(1, 200))` | `DUPLICATED_MAP_KEY` | `GlutenException` | `DUPLICATED_MAP_KEY` |

- apache#13647 proposes translating Velox exceptions to Spark's.
- apache#13685 proposes carrying Spark error classes from Velox instead of matching Velox's message text.
- facebookincubator/velox#20483 proposes raising Spark error classes from Velox's Spark functions.
- Conclusion: keep translating by message text until the Velox changes are ready, per [apache#13639 (comment)](apache#13639 (comment)).

Part of apache#11912

## 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 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write two queries that build a map with a duplicate key from a Parquet table:

```bash
cat > map_from_arrays.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT array(1, 1) AS k, array(10, 20) AS v;
SELECT map_from_arrays(k, v) FROM src;
EOF
cat > map_concat.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT map(1, 100) AS m1, map(1, 200) AS m2;
SELECT map_concat(m1, m2) 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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  for q in map_from_arrays.sql map_concat.sql; do
    spark-3.5.5-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 "Job aborted" err.log | sed "s/.*executor driver): //"
    grep -m 1 "^Reason:" err.log
  done
'
```

On the base commit, both queries fail 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:

```
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: Duplicate map key was found: 1
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: Duplicate map key 1 was found.
```

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

```
org.apache.spark.SparkRuntimeException: [DUPLICATED_MAP_KEY] Duplicate map key 1 was found, please check the input data. If you want to remove the duplicated keys, you can set "spark.sql.mapKeyDedupPolicy" to "LAST_WIN" so that the key inserted at last takes precedence.
Reason: Duplicate map key was found: 1
org.apache.spark.SparkRuntimeException: [DUPLICATED_MAP_KEY] Duplicate map key 1 was found, please check the input data. If you want to remove the duplicated keys, you can set "spark.sql.mapKeyDedupPolicy" to "LAST_WIN" so that the key inserted at last takes precedence.
Reason: Duplicate map key 1 was found.
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with the same exception:

```
org.apache.spark.SparkRuntimeException: [DUPLICATED_MAP_KEY] Duplicate map key 1 was found, please check the input data. If you want to remove the duplicated keys, you can set "spark.sql.mapKeyDedupPolicy" to "LAST_WIN" so that the key inserted at last takes precedence.
org.apache.spark.SparkRuntimeException: [DUPLICATED_MAP_KEY] Duplicate map key 1 was found, please check the input data. If you want to remove the duplicated keys, you can set "spark.sql.mapKeyDedupPolicy" to "LAST_WIN" so that the key inserted at last takes precedence.
```

### 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), [GlutenDataFrameFunctionsSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenDataFrameFunctionsSuite.scala#L26) passes 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.GlutenDataFrameFunctionsSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenDataFrameFunctionsSuite:
…
- map_concat function
…
- transform keys function - primitive data types
…
Tests: succeeded 146, failed 0, canceled 0, ignored 2, 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 146, failed 0, canceled 0, ignored 2, pending 0
All tests passed.
```

Spark 4.2 runs it with `-Pspark-4.2`, `gluten-ut/spark42` and `/opt/shims/spark42/spark_home/`:

```
Tests: succeeded 152, failed 0, canceled 0, ignored 10, pending 0
All tests passed.
```

On Spark 3.5 with JDK 8, which keeps its tests unchanged, the suite also passes:

```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.GlutenDataFrameFunctionsSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
Tests: succeeded 140, failed 0, canceled 0, ignored 4, pending 0
All tests passed.
```

On Spark 3.4, with `-Pspark-3.4`, `gluten-ut/spark34` and `/opt/shims/spark34/spark_home/`:

```
Tests: succeeded 120, failed 0, canceled 0, ignored 5, pending 0
All tests passed.
```

[ScalarFunctionsValidateSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala#L31) passes on every Spark version, shown here for 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 -pl backends-velox -am -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.gluten.functions.ScalarFunctionsValidateSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
Tests: succeeded 95, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
```

On Spark 4.1 and 4.2 it reports the same totals. On Spark 3.5, 94 tests succeed with no failures. On Spark 3.4, 92 tests succeed with no failures.

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

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
pedrumj2 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…NOT_NULL_ASSERT_VIOLATION exception

## What changes are proposed in this pull request?

| 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` |

- apache#13647 proposes translating Velox exceptions to Spark's.
- apache#13685 proposes carrying Spark error classes from Velox instead of matching Velox's message text.
- facebookincubator/velox#20483 proposes raising Spark error classes from Velox's Spark functions.
- Conclusion: keep translating by message text until the Velox changes are ready, per [apache#13639 (comment)](apache#13639 (comment)).

Part of apache#11912

## 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 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…exception

## What changes are proposed in this pull request?

| Query | Spark 3.5.5 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `getbit(11L, -1)` | `IllegalArgumentException` | `GlutenException` | `IllegalArgumentException` |
| `getbit(11L, 64)` | `IllegalArgumentException` | `GlutenException` | `IllegalArgumentException` |

- apache#13647 proposes translating Velox exceptions to Spark's.
- apache#13685 proposes carrying Spark error classes from Velox instead of matching Velox's message text.
- facebookincubator/velox#20483 proposes raising Spark error classes from Velox's Spark functions.
- Conclusion: keep translating by message text until the Velox changes are ready, per [apache#13639 (comment)](apache#13639 (comment)).

Part of apache#11912

## 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 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write two queries that read a bit outside a BIGINT from a Parquet table:

```bash
cat > negative.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT 11L AS x, -1 AS pos;
SELECT getbit(x, pos) FROM src;
EOF
cat > too_large.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT 11L AS x, 64 AS pos;
SELECT getbit(x, pos) 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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  for q in negative.sql too_large.sql; do
    spark-3.5.5-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 "Job aborted" err.log | sed "s/.*executor driver): //"
    grep -m 1 "^Reason:" err.log
  done
'
```

On the base commit, both queries fail 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:

```
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: (-1 vs. 0) The value of 'pos' argument must be greater than or equal to zero.
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: (64 vs. 64) The value of 'pos' argument must not exceed the number of bits in 'x' - 1.
```

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

```
java.lang.IllegalArgumentException: Invalid bit position: -1 is less than zero
Reason: (-1 vs. 0) The value of 'pos' argument must be greater than or equal to zero.
java.lang.IllegalArgumentException: Invalid bit position: 64 exceeds the bit upper limit
Reason: (64 vs. 64) The value of 'pos' argument must not exceed the number of bits in 'x' - 1.
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with the same exception:

```
java.lang.IllegalArgumentException: Invalid bit position: -1 is less than zero
java.lang.IllegalArgumentException: Invalid bit position: 64 exceeds the bit upper limit
```

### Automated tests

Inside the `apache/gluten:centos-9-jdk8` image, [GlutenSQLQueryTestSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenSQLQueryTestSuite.scala#L61) passes on Spark 3.5, running Spark's own [bitwise.sql](https://github.com/apache/spark/blob/v3.5.5/sql/core/src/test/resources/sql-tests/inputs/bitwise.sql):

```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.GlutenSQLQueryTestSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenSQLQueryTestSuite:
…
- bitwise.sql
…
Tests: succeeded 212, failed 0, canceled 0, ignored 104, pending 0
All tests passed.
```

[ScalarFunctionsValidateSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala#L31) passes on Spark 3.5:

```bash
./build/mvn -ntp -B clean test -Pspark-3.5 -Pbackends-velox -pl backends-velox -am -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.gluten.functions.ScalarFunctionsValidateSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
Tests: succeeded 94, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
```

The change also compiles against Spark 3.4 and 4.0:

```bash
./build/mvn -ntp -B test-compile -Pbackends-velox -Pspark-ut -Pspark-3.4 -pl gluten-ut/spark34 -am
./build/mvn -ntp -B test-compile -Pbackends-velox -Pspark-ut -Pspark-4.0 -Pscala-2.13 -Pjava-17 -pl gluten-ut/spark40 -am -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
[INFO] BUILD SUCCESS
[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 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…L_MAP_KEY exception

## What changes are proposed in this pull request?

| Query | Spark 3.5.5 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `map_from_arrays(array('a', NULL), array(1, 2))` | `NULL_MAP_KEY` | `GlutenException` | `NULL_MAP_KEY` |

- apache#13647 proposes translating Velox exceptions to Spark's.
- apache#13685 proposes carrying Spark error classes from Velox instead of matching Velox's message text.
- facebookincubator/velox#20483 proposes raising Spark error classes from Velox's Spark functions.
- Conclusion: keep translating by message text until the Velox changes are ready, per [apache#13639 (comment)](apache#13639 (comment)).

Part of apache#11912

## 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 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write a query that builds a map with a null key from a Parquet table:

```bash
cat > null_key.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT array('a', NULL) AS k, array(1, 2) AS v;
SELECT map_from_arrays(k, v) FROM src;
EOF
```

5. Run the 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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  spark-3.5.5-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 null_key.sql 2>err.log
  grep -m 1 "Job aborted" err.log | sed "s/.*executor driver): //"
  grep -m 1 "^Reason:" err.log
'
```

On the base commit, the query 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:

```
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: Cannot use null as map key!
```

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

```
org.apache.spark.SparkRuntimeException: [NULL_MAP_KEY] Cannot use null as map key.
Reason: Cannot use null as map key!
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with the same exception:

```
org.apache.spark.SparkRuntimeException: [NULL_MAP_KEY] Cannot use null as map key.
```

### Automated tests

Inside the `apache/gluten:centos-9-jdk8` image, [GlutenDataFrameFunctionsSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenDataFrameFunctionsSuite.scala#L25) passes on Spark 3.5:

```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.GlutenDataFrameFunctionsSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenDataFrameFunctionsSuite:
…
- map with arrays
…
Tests: succeeded 140, failed 0, canceled 0, ignored 3, pending 0
All tests passed.
```

On Spark 3.4, with `-Pspark-3.4`, `gluten-ut/spark34` and `/opt/shims/spark34/spark_home/`:

```
Tests: succeeded 120, failed 0, canceled 0, ignored 4, pending 0
All tests passed.
```

On Spark 4.0, 4.1 and 4.2, 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):

```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.GlutenDataFrameFunctionsSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenDataFrameFunctionsSuite:
…
- map with arrays
…
Tests: succeeded 146, failed 0, canceled 0, ignored 3, 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 146, failed 0, canceled 0, ignored 3, pending 0
All tests passed.
```

Spark 4.2 runs it with `-Pspark-4.2`, `gluten-ut/spark42` and `/opt/shims/spark42/spark_home/`:

```
Tests: succeeded 152, failed 0, canceled 0, ignored 11, pending 0
All tests passed.
```

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

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
pedrumj2 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…ithmeticException

## What changes are proposed in this pull request?

| Query | Spark 3.5.5 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `date_trunc('YEAR', timestamp_micros(-9223372036854775808))` | `ArithmeticException` | `GlutenException` | `ArithmeticException` |

- apache#13647 proposes translating Velox exceptions to Spark's.
- apache#13685 proposes carrying Spark error classes from Velox instead of matching Velox's message text.
- facebookincubator/velox#20483 proposes raising Spark error classes from Velox's Spark functions.
- Conclusion: keep translating by message text until the Velox changes are ready, per [apache#13639 (comment)](apache#13639 (comment)).

Part of apache#11912

## 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 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write a query that truncates the earliest timestamp, read from a Parquet table, to its year:

```bash
cat > date_trunc.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT -9223372036854775808L AS micros;
SELECT date_trunc('YEAR', timestamp_micros(micros)) FROM src;
EOF
```

5. Run the 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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  spark-3.5.5-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 date_trunc.sql 2>err.log
  grep -m 1 "Job aborted" err.log | sed "s/.*executor driver): //"
  grep -m 1 "^Reason:" err.log
'
```

On the base commit, the query 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:

```
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: long overflow
```

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

```
java.lang.ArithmeticException: long overflow
Reason: long overflow
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with the same exception:

```
java.lang.ArithmeticException: long overflow
```

### 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), [GlutenDateExpressionsSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenDateExpressionsSuite.scala#L39) passes on Spark 4.2:

```bash
SPARK_ANSI_SQL_MODE=false ./build/mvn -ntp -B clean test -Pspark-4.2 -Pscala-2.13 -Pjava-17 -Pbackends-velox -Pspark-ut -pl gluten-ut/spark42 -am -DargLine="-Dspark.test.home=/opt/shims/spark42/spark_home/" -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.spark.sql.catalyst.expressions.GlutenDateExpressionsSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenDateExpressionsSuite:
…
- TruncTimestamp of Long.MinValue overflows with ArithmeticException
…
Tests: succeeded 73, failed 0, canceled 0, ignored 11, pending 0
All tests passed.
```

The same suite passes on Spark 4.0 and 4.1, with `-Pspark-4.0`, `gluten-ut/spark40` and `/opt/shims/spark40/spark_home/`, or their 4.1 counterparts:

```
Tests: succeeded 61, failed 0, canceled 0, ignored 11, pending 0
All tests passed.
```

```
Tests: succeeded 65, failed 0, canceled 0, ignored 11, pending 0
All tests passed.
```

On Spark 3.5 and 3.4 with JDK 8, with `-Pspark-3.5`, `gluten-ut/spark35` and `/opt/shims/spark35/spark_home/`, or their 3.4 counterparts, it passes with the same totals on both:

```
Tests: succeeded 60, failed 0, canceled 0, ignored 11, pending 0
All tests passed.
```

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

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
pedrumj2 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 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 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…ption

## 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

| Query | Spark 3.5.5 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `raise_error(s)`, where `s` is `'hello'` | `RuntimeException: hello` | `GlutenException` | `RuntimeException: hello` |
| `assert_true(a > b, 'a is not greater than b')`, where `a` is 1 and `b` is 2 | `RuntimeException: a is not greater than b` | `GlutenException` | `RuntimeException: a is not greater than b` |

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 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write two queries that raise an error from a Parquet table's values:

```bash
cat > raise_error.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT 'hello' AS s;
SELECT raise_error(s) FROM src;
EOF
cat > assert_true.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT 1 AS a, 2 AS b;
SELECT assert_true(a > b, 'a is not greater than b') 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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  for q in raise_error.sql assert_true.sql; do
    spark-3.5.5-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 "Job aborted" err.log | sed "s/.*executor driver): //"
    grep -m 1 "^Reason:" err.log
  done
'
```

On the base commit, both queries fail 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:

```
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: hello
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: a is not greater than b
```

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

```
java.lang.RuntimeException: hello
Reason: hello
java.lang.RuntimeException: a is not greater than b
Reason: a is not greater than b
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with the same exception:

```
java.lang.RuntimeException: hello
java.lang.RuntimeException: a is not greater than b
```

### 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), [GlutenColumnExpressionSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenColumnExpressionSuite.scala#L25) and [GlutenCachedTableSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenCachedTableSuite.scala#L29) 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.GlutenColumnExpressionSuite,org.apache.spark.sql.GlutenCachedTableSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenColumnExpressionSuite:
…
- raise_error
…
- assert_true
…
GlutenCachedTableSuite:
…
- SPARK-52684: Atomicity of cache table on error
…
Tests: succeeded 228, failed 0, canceled 0, ignored 4, pending 0
All tests passed.
```

On Spark 4.1 and 4.2, which run the same command with `-Pspark-4.1`, `gluten-ut/spark41` and `/opt/shims/spark41/spark_home/` or their 4.2 counterparts, the same tests pass. The one failure on each is [SPARK-52692: Support cache/uncache table with Time type](https://github.com/apache/spark/blob/v4.2.0/sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala#L1839), which fails the same way on the base commit with `[UNSUPPORTED_TIME_TYPE] The data type TIME is not supported`:

```
Tests: succeeded 254, failed 1, canceled 0, ignored 4, pending 0
```

```
Tests: succeeded 256, failed 1, canceled 0, ignored 4, pending 0
```

On Spark 3.5 with JDK 8, `GlutenColumnExpressionSuite` and [GlutenSQLQueryTestSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenSQLQueryTestSuite.scala#L61) pass:

```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.GlutenColumnExpressionSuite,org.apache.spark.sql.GlutenSQLQueryTestSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenColumnExpressionSuite:
…
- raise_error
…
- assert_true
…
GlutenSQLQueryTestSuite:
…
- misc-functions.sql
…
Tests: succeeded 363, failed 0, canceled 0, ignored 104, pending 0
All tests passed.
```

On Spark 3.4, with `-Pspark-3.4`, `gluten-ut/spark34` and `/opt/shims/spark34/spark_home/`, where [misc-functions.sql](https://github.com/apache/spark/blob/v3.4.4/sql/core/src/test/resources/sql-tests/inputs/misc-functions.sql) now runs from Spark's own files:

```
Tests: succeeded 372, failed 0, canceled 0, ignored 84, pending 0
All tests passed.
```

[ScalarFunctionsValidateSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala#L31) passes on every Spark version, shown here for 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 -pl backends-velox -am -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.gluten.functions.ScalarFunctionsValidateSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
Tests: succeeded 95, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
```

On Spark 4.1 and 4.2 it reports the same totals. On Spark 3.5, 94 tests succeed with no failures. On Spark 3.4, 92 tests succeed with no failures.

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

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
pedrumj2 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…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

| Query | Spark 3.5.5 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `getbit(11L, -1)` | `IllegalArgumentException` | `GlutenException` | `IllegalArgumentException` |
| `getbit(11L, 64)` | `IllegalArgumentException` | `GlutenException` | `IllegalArgumentException` |

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 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write two queries that read a bit outside a BIGINT from a Parquet table:

```bash
cat > negative.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT 11L AS x, -1 AS pos;
SELECT getbit(x, pos) FROM src;
EOF
cat > too_large.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT 11L AS x, 64 AS pos;
SELECT getbit(x, pos) 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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  for q in negative.sql too_large.sql; do
    spark-3.5.5-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 "Job aborted" err.log | sed "s/.*executor driver): //"
    grep -m 1 "^Reason:" err.log
  done
'
```

On the base commit, both queries fail 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:

```
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: (-1 vs. 0) The value of 'pos' argument must be greater than or equal to zero.
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: (64 vs. 64) The value of 'pos' argument must not exceed the number of bits in 'x' - 1.
```

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

```
java.lang.IllegalArgumentException: Invalid bit position: -1 is less than zero
Reason: (-1 vs. 0) The value of 'pos' argument must be greater than or equal to zero.
java.lang.IllegalArgumentException: Invalid bit position: 64 exceeds the bit upper limit
Reason: (64 vs. 64) The value of 'pos' argument must not exceed the number of bits in 'x' - 1.
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with the same exception:

```
java.lang.IllegalArgumentException: Invalid bit position: -1 is less than zero
java.lang.IllegalArgumentException: Invalid bit position: 64 exceeds the bit upper limit
```

### Automated tests

Inside the `apache/gluten:centos-9-jdk8` image, [GlutenSQLQueryTestSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenSQLQueryTestSuite.scala#L61) passes on Spark 3.5, running Spark's own [bitwise.sql](https://github.com/apache/spark/blob/v3.5.5/sql/core/src/test/resources/sql-tests/inputs/bitwise.sql):

```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.GlutenSQLQueryTestSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenSQLQueryTestSuite:
…
- bitwise.sql
…
Tests: succeeded 212, failed 0, canceled 0, ignored 104, pending 0
All tests passed.
```

[ScalarFunctionsValidateSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala#L31) passes on Spark 3.5:

```bash
./build/mvn -ntp -B clean test -Pspark-3.5 -Pbackends-velox -pl backends-velox -am -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.gluten.functions.ScalarFunctionsValidateSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
Tests: succeeded 94, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
```

The change also compiles against Spark 3.4 and 4.0:

```bash
./build/mvn -ntp -B test-compile -Pbackends-velox -Pspark-ut -Pspark-3.4 -pl gluten-ut/spark34 -am
./build/mvn -ntp -B test-compile -Pbackends-velox -Pspark-ut -Pspark-4.0 -Pscala-2.13 -Pjava-17 -pl gluten-ut/spark40 -am -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
[INFO] BUILD SUCCESS
[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 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…L_MAP_KEY 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

| Query | Spark 3.5.5 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `map_from_arrays(array('a', NULL), array(1, 2))` | `NULL_MAP_KEY` | `GlutenException` | `NULL_MAP_KEY` |

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 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write a query that builds a map with a null key from a Parquet table:

```bash
cat > null_key.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT array('a', NULL) AS k, array(1, 2) AS v;
SELECT map_from_arrays(k, v) FROM src;
EOF
```

5. Run the 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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  spark-3.5.5-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 null_key.sql 2>err.log
  grep -m 1 "Job aborted" err.log | sed "s/.*executor driver): //"
  grep -m 1 "^Reason:" err.log
'
```

On the base commit, the query 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:

```
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: Cannot use null as map key!
```

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

```
org.apache.spark.SparkRuntimeException: [NULL_MAP_KEY] Cannot use null as map key.
Reason: Cannot use null as map key!
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with the same exception:

```
org.apache.spark.SparkRuntimeException: [NULL_MAP_KEY] Cannot use null as map key.
```

### Automated tests

Inside the `apache/gluten:centos-9-jdk8` image, [GlutenDataFrameFunctionsSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenDataFrameFunctionsSuite.scala#L25) passes on Spark 3.5:

```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.GlutenDataFrameFunctionsSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenDataFrameFunctionsSuite:
…
- map with arrays
…
Tests: succeeded 140, failed 0, canceled 0, ignored 3, pending 0
All tests passed.
```

On Spark 3.4, with `-Pspark-3.4`, `gluten-ut/spark34` and `/opt/shims/spark34/spark_home/`:

```
Tests: succeeded 120, failed 0, canceled 0, ignored 4, pending 0
All tests passed.
```

On Spark 4.0, 4.1 and 4.2, 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):

```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.GlutenDataFrameFunctionsSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenDataFrameFunctionsSuite:
…
- map with arrays
…
Tests: succeeded 146, failed 0, canceled 0, ignored 3, 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 146, failed 0, canceled 0, ignored 3, pending 0
All tests passed.
```

Spark 4.2 runs it with `-Pspark-4.2`, `gluten-ut/spark42` and `/opt/shims/spark42/spark_home/`:

```
Tests: succeeded 152, failed 0, canceled 0, ignored 11, pending 0
All tests passed.
```

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

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
pedrumj2 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…ithmeticException

## 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

| Query | Spark 3.5.5 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `date_trunc('YEAR', timestamp_micros(-9223372036854775808))` | `ArithmeticException` | `GlutenException` | `ArithmeticException` |

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 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write a query that truncates the earliest timestamp, read from a Parquet table, to its year:

```bash
cat > date_trunc.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT -9223372036854775808L AS micros;
SELECT date_trunc('YEAR', timestamp_micros(micros)) FROM src;
EOF
```

5. Run the 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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  spark-3.5.5-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 date_trunc.sql 2>err.log
  grep -m 1 "Job aborted" err.log | sed "s/.*executor driver): //"
  grep -m 1 "^Reason:" err.log
'
```

On the base commit, the query 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:

```
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: long overflow
```

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

```
java.lang.ArithmeticException: long overflow
Reason: long overflow
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with the same exception:

```
java.lang.ArithmeticException: long overflow
```

### 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), [GlutenDateExpressionsSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenDateExpressionsSuite.scala#L39) passes on Spark 4.2:

```bash
SPARK_ANSI_SQL_MODE=false ./build/mvn -ntp -B clean test -Pspark-4.2 -Pscala-2.13 -Pjava-17 -Pbackends-velox -Pspark-ut -pl gluten-ut/spark42 -am -DargLine="-Dspark.test.home=/opt/shims/spark42/spark_home/" -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.spark.sql.catalyst.expressions.GlutenDateExpressionsSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenDateExpressionsSuite:
…
- TruncTimestamp of Long.MinValue overflows with ArithmeticException
…
Tests: succeeded 73, failed 0, canceled 0, ignored 11, pending 0
All tests passed.
```

The same suite passes on Spark 4.0 and 4.1, with `-Pspark-4.0`, `gluten-ut/spark40` and `/opt/shims/spark40/spark_home/`, or their 4.1 counterparts:

```
Tests: succeeded 61, failed 0, canceled 0, ignored 11, pending 0
All tests passed.
```

```
Tests: succeeded 65, failed 0, canceled 0, ignored 11, pending 0
All tests passed.
```

On Spark 3.5 and 3.4 with JDK 8, with `-Pspark-3.5`, `gluten-ut/spark35` and `/opt/shims/spark35/spark_home/`, or their 3.4 counterparts, it passes with the same totals on both:

```
Tests: succeeded 60, failed 0, canceled 0, ignored 11, pending 0
All tests passed.
```

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

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
pedrumj2 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…Spark's INVALID_BITMAP_POSITION 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

| Position | Spark 3.5.5 without Gluten | Gluten before this pull request | Gluten after this pull request |
|---|---|---|---|
| 32768 | `SparkArrayIndexOutOfBoundsException` | `GlutenException` wrapping Velox's `(32768 vs. 32768) Bitmap position out of bounds` | `GlutenException` wrapping Spark's `SparkArrayIndexOutOfBoundsException` |
| -1 | `SparkArrayIndexOutOfBoundsException` | `GlutenException` wrapping Velox's `(-1 vs. 0) Bitmap position out of bounds` | `GlutenException` wrapping Spark's `SparkArrayIndexOutOfBoundsException` |

Please see the following discussions apache#13647, apache#13685 and facebookincubator/velox#20483

Conclusion can be found [here](apache#13639 (comment))

Fixes apache#12238

## 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 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write Spark's two test queries:

```bash
cat > out_of_bounds.sql <<'EOF'
SELECT bitmap_construct_agg(col) FROM VALUES (32768) AS tab(col);
EOF
cat > negative.sql <<'EOF'
SELECT bitmap_construct_agg(col) FROM VALUES (-1) AS tab(col);
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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  for q in out_of_bounds.sql negative.sql; do
    spark-3.5.5-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 "^Job aborted" err.log | sed "s/.*executor driver): //"
    grep -m 1 "^Reason:" err.log
  done
'
```

On the base commit, both queries fail 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:

```
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: (32768 vs. 32768) Bitmap position out of bounds
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: (-1 vs. 0) Bitmap position out of bounds
```

On this pull request's branch, rerunning steps 2 and 5 gives a `GlutenException` that wraps Spark's exception, with Velox's error kept as the cause of Spark's exception:

```
org.apache.gluten.exception.GlutenException: org.apache.spark.SparkArrayIndexOutOfBoundsException: [INVALID_BITMAP_POSITION] The 0-indexed bitmap position 32768 is out of bounds. The bitmap has 32768 bits (4096 bytes).
Reason: (32768 vs. 32768) Bitmap position out of bounds
org.apache.gluten.exception.GlutenException: org.apache.spark.SparkArrayIndexOutOfBoundsException: [INVALID_BITMAP_POSITION] The 0-indexed bitmap position -1 is out of bounds. The bitmap has 32768 bits (4096 bytes).
Reason: (-1 vs. 0) Bitmap position out of bounds
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with Spark's exception on its own:

```
org.apache.spark.SparkArrayIndexOutOfBoundsException: [INVALID_BITMAP_POSITION] The 0-indexed bitmap position 32768 is out of bounds. The bitmap has 32768 bits (4096 bytes).
org.apache.spark.SparkArrayIndexOutOfBoundsException: [INVALID_BITMAP_POSITION] The 0-indexed bitmap position -1 is out of bounds. The bitmap has 32768 bits (4096 bytes).
```

### Automated tests

Inside the `apache/gluten:centos-9-jdk8` image, [GlutenQueryExecutionErrorsSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/errors/GlutenQueryExecutionErrorsSuite.scala) and [GlutenBitmapExpressionsQuerySuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenBitmapExpressionsQuerySuite.scala#L28) pass on Spark 3.5:

```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.errors.GlutenQueryExecutionErrorsSuite,org.apache.spark.sql.GlutenBitmapExpressionsQuerySuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenQueryExecutionErrorsSuite:
…
- INVALID_BITMAP_POSITION: position out of bounds
…
- INVALID_BITMAP_POSITION: negative position
…
GlutenBitmapExpressionsQuerySuite:
…
- bitmap_construct_agg routes to native
…
Tests: succeeded 50, failed 0, canceled 0, ignored 3, pending 0
All tests passed.
```

On Spark 4.0, 4.1 and 4.2, the same suites pass 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):

```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.errors.GlutenQueryExecutionErrorsSuite,org.apache.spark.sql.GlutenBitmapExpressionsQuerySuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
…
- INVALID_BITMAP_POSITION: position out of bounds
…
- INVALID_BITMAP_POSITION: negative position
…
- bitmap_construct_agg routes to native
…
Tests: succeeded 64, failed 0, canceled 0, ignored 3, pending 0
All tests passed.
```

```bash
SPARK_ANSI_SQL_MODE=false ./build/mvn -ntp -B clean test -Pspark-4.1 -Pscala-2.13 -Pjava-17 -Pbackends-velox -Pspark-ut -pl gluten-ut/spark41 -am -DargLine="-Dspark.test.home=/opt/shims/spark41/spark_home/" -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.spark.sql.errors.GlutenQueryExecutionErrorsSuite,org.apache.spark.sql.GlutenBitmapExpressionsQuerySuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
…
- INVALID_BITMAP_POSITION: position out of bounds
…
- INVALID_BITMAP_POSITION: negative position
…
- bitmap_construct_agg routes to native
…
Tests: succeeded 68, failed 0, canceled 0, ignored 3, pending 0
All tests passed.
```

```bash
SPARK_ANSI_SQL_MODE=false ./build/mvn -ntp -B clean test -Pspark-4.2 -Pscala-2.13 -Pjava-17 -Pbackends-velox -Pspark-ut -pl gluten-ut/spark42 -am -DargLine="-Dspark.test.home=/opt/shims/spark42/spark_home/" -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.spark.sql.errors.GlutenQueryExecutionErrorsSuite,org.apache.spark.sql.GlutenBitmapExpressionsQuerySuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
…
- INVALID_BITMAP_POSITION: position out of bounds
…
- INVALID_BITMAP_POSITION: negative position
…
- bitmap_construct_agg routes to native
…
Tests: succeeded 68, failed 0, canceled 0, ignored 3, 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 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 24, 2026
…s DUPLICATED_MAP_KEY 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

| Query | Spark 3.5.5 without Gluten | Gluten before this change | Gluten after this change |
|---|---|---|---|
| `map_from_arrays(array(1, 1), array(10, 20))` | `DUPLICATED_MAP_KEY` | `GlutenException` | `DUPLICATED_MAP_KEY` |
| `map_concat(map(1, 100), map(1, 200))` | `DUPLICATED_MAP_KEY` | `GlutenException` | `DUPLICATED_MAP_KEY` |

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 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
  ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests
'
```

3. Fetch Spark 3.5.5:

```bash
curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xz
```

4. Write two queries that build a map with a duplicate key from a Parquet table:

```bash
cat > map_from_arrays.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT array(1, 1) AS k, array(10, 20) AS v;
SELECT map_from_arrays(k, v) FROM src;
EOF
cat > map_concat.sql <<'EOF'
DROP TABLE IF EXISTS src;
CREATE TABLE src USING parquet AS SELECT map(1, 100) AS m1, map(1, 200) AS m2;
SELECT map_concat(m1, m2) 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 '
  cd /work/gluten
  BUNDLE=$(ls package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-*.jar)
  for q in map_from_arrays.sql map_concat.sql; do
    spark-3.5.5-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 "Job aborted" err.log | sed "s/.*executor driver): //"
    grep -m 1 "^Reason:" err.log
  done
'
```

On the base commit, both queries fail 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:

```
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: Duplicate map key was found: 1
org.apache.gluten.exception.GlutenException: Exception: VeloxUserError
Reason: Duplicate map key 1 was found.
```

On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:

```
org.apache.spark.SparkRuntimeException: [DUPLICATED_MAP_KEY] Duplicate map key 1 was found, please check the input data. If you want to remove the duplicated keys, you can set "spark.sql.mapKeyDedupPolicy" to "LAST_WIN" so that the key inserted at last takes precedence.
Reason: Duplicate map key was found: 1
org.apache.spark.SparkRuntimeException: [DUPLICATED_MAP_KEY] Duplicate map key 1 was found, please check the input data. If you want to remove the duplicated keys, you can set "spark.sql.mapKeyDedupPolicy" to "LAST_WIN" so that the key inserted at last takes precedence.
Reason: Duplicate map key 1 was found.
```

Spark without Gluten, which is step 5's `spark-sql` command keeping only `--master`, fails with the same exception:

```
org.apache.spark.SparkRuntimeException: [DUPLICATED_MAP_KEY] Duplicate map key 1 was found, please check the input data. If you want to remove the duplicated keys, you can set "spark.sql.mapKeyDedupPolicy" to "LAST_WIN" so that the key inserted at last takes precedence.
org.apache.spark.SparkRuntimeException: [DUPLICATED_MAP_KEY] Duplicate map key 1 was found, please check the input data. If you want to remove the duplicated keys, you can set "spark.sql.mapKeyDedupPolicy" to "LAST_WIN" so that the key inserted at last takes precedence.
```

### 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), [GlutenDataFrameFunctionsSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenDataFrameFunctionsSuite.scala#L26) passes 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.GlutenDataFrameFunctionsSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
GlutenDataFrameFunctionsSuite:
…
- map_concat function
…
- transform keys function - primitive data types
…
Tests: succeeded 146, failed 0, canceled 0, ignored 2, 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 146, failed 0, canceled 0, ignored 2, pending 0
All tests passed.
```

Spark 4.2 runs it with `-Pspark-4.2`, `gluten-ut/spark42` and `/opt/shims/spark42/spark_home/`:

```
Tests: succeeded 152, failed 0, canceled 0, ignored 10, pending 0
All tests passed.
```

On Spark 3.5 with JDK 8, which keeps its tests unchanged, the suite also passes:

```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.GlutenDataFrameFunctionsSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
Tests: succeeded 140, failed 0, canceled 0, ignored 4, pending 0
All tests passed.
```

On Spark 3.4, with `-Pspark-3.4`, `gluten-ut/spark34` and `/opt/shims/spark34/spark_home/`:

```
Tests: succeeded 120, failed 0, canceled 0, ignored 5, pending 0
All tests passed.
```

[ScalarFunctionsValidateSuite](https://github.com/apache/gluten/blob/85c89803ed2d050db4052f1813d76711ebe29fb8/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala#L31) passes on every Spark version, shown here for 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 -pl backends-velox -am -Dtest=none -DfailIfNoTests=false -DwildcardSuites=org.apache.gluten.functions.ScalarFunctionsValidateSuite -Dspotless.check.skip=true -Dscalastyle.skip=true -Dcheckstyle.skip=true
```

```
Tests: succeeded 95, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
```

On Spark 4.1 and 4.2 it reports the same totals. On Spark 3.5, 94 tests succeed with no failures. On Spark 3.4, 92 tests succeed with no failures.

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

Generated-by: Co-authored with Claude Code (claude-opus-5-5)
pedrumj2 pushed a commit to pedrumj2/gluten that referenced this pull request Nov 26, 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CORE works for Gluten Core VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants