pedrumj2 opened a new pull request, #13779:
URL: https://github.com/apache/gluten/pull/13779
## 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.This PR translates a gluten exception to Spark exception using the
established flow and avoid the custom exception assertion logic keeping a
consistent mechanism for handling gluten exceptions
| 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 #13647, #13685 and
facebookincubator/velox#20483
Conclusion can be found
[here](https://github.com/apache/gluten/pull/13639#issuecomment-7111475915)
## 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 85c89803ed2d050db4052f1813d76711ebe29fb8
```
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)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]