Skip to content

[GLUTEN-11912][VL] Translate Velox raise_error errors to Spark's exception - #13783

Open
pedrumj2 wants to merge 1 commit into
apache:mainfrom
pedrumj2:gluten-11912-user-raised-exception
Open

pedrumj2 wants to merge 1 commit into
apache:mainfrom
pedrumj2:gluten-11912-user-raised-exception

Conversation

@pedrumj2

@pedrumj2 pedrumj2 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 #13647, #13685 and facebookincubator/velox#20483

Conclusion can be found here

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 85c89803ed2d050db4052f1813d76711ebe29fb8
  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 two queries that raise an error from a Parquet table's values:
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
  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 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 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, GlutenColumnExpressionSuite and GlutenCachedTableSuite pass on Spark 4.0:

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, 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 pass:

./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 now runs from Spark's own files:

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

ScalarFunctionsValidateSuite passes on every Spark version, shown here for Spark 4.0:

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)

Related issue: #11912

…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)
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

This branch has not been deployed

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

Labels

CORE works for Gluten Core VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant