Repository navigation
[GLUTEN-11912][VL] Translate Velox duplicate map key errors to Spark's DUPLICATED_MAP_KEY exception - #13784
Open
pedrumj2 wants to merge 1 commit into
Open
[GLUTEN-11912][VL] Translate Velox duplicate map key errors to Spark's DUPLICATED_MAP_KEY exception#13784pedrumj2 wants to merge 1 commit into
pedrumj2 wants to merge 1 commit into
Conversation
…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)
|
Run Gluten Clickhouse CI on x86 |
pedrumj2
marked this pull request as ready for review
November 25, 2026 01:37
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes are proposed in this pull request?
This PR translates a gluten exception to Spark exception:
.exclude("some function")in testsmap_from_arrays(array(1, 1), array(10, 20))DUPLICATED_MAP_KEYGlutenExceptionDUPLICATED_MAP_KEYmap_concat(map(1, 100), map(1, 200))DUPLICATED_MAP_KEYGlutenExceptionDUPLICATED_MAP_KEYPlease see the following discussions #13647, #13685 and facebookincubator/velox#20483
Conclusion can be found here
How was this patch tested?
Reproduction
git clone https://github.com/apache/gluten.git cd gluten git checkout 85c89803ed2d050db4052f1813d76711ebe29fb8curl -sSL https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz | tar -xzOn the base commit, both queries fail with a GlutenException that wraps Velox's error:
On this pull request's branch, rerunning steps 2 and 5 gives Spark's exception, with Velox's error kept as its cause:
Spark without Gluten, which is step 5's
spark-sqlcommand keeping only--master, fails with the same exception:Automated tests
Inside the
apache/gluten:centos-9-jdk8image, with JDK 17 andSPARK_ANSI_SQL_MODE=false, which Gluten's CI sets, GlutenDataFrameFunctionsSuite passes on Spark 4.0:Spark 4.1 runs the same command with
-Pspark-4.1,gluten-ut/spark41and/opt/shims/spark41/spark_home/:Spark 4.2 runs it with
-Pspark-4.2,gluten-ut/spark42and/opt/shims/spark42/spark_home/:On Spark 3.5 with JDK 8, which keeps its tests unchanged, the suite also passes:
On Spark 3.4, with
-Pspark-3.4,gluten-ut/spark34and/opt/shims/spark34/spark_home/: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=trueOn 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