This is an automated email from the ASF dual-hosted git repository.
zhztheplayer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git
The following commit(s) were added to refs/heads/main by this push:
new a76bdf94dc [GLUTEN-12241][CORE] Fall back to Spark for Delta field-ID
reads (#13666)
a76bdf94dc is described below
commit a76bdf94dcf7284000877561633fc3c6ad60d9a2
Author: Felipe Pessoto <[email protected]>
AuthorDate: Mon Nov 23 07:53:11 2026 -0800
[GLUTEN-12241][CORE] Fall back to Spark for Delta field-ID reads (#13666)
---
.../util/delta-spark-ut/known-failures.txt | 2 -
.github/workflows/velox_backend_x86.yml | 10 +-
.../apache/gluten/execution/VeloxDeltaSuite.scala | 13 +-
docs/backends/velox/get-started/VeloxDelta.md | 20 +--
.../gluten/execution/DeltaScanTransformer.scala | 10 +-
.../org/apache/gluten/execution/DeltaSuite.scala | 155 ++++++++++++---------
.../sql/delta/GlutenDeltaColumnMappingSuite.scala | 114 +++++++++++++++
7 files changed, 235 insertions(+), 89 deletions(-)
diff --git a/.github/workflows/util/delta-spark-ut/known-failures.txt
b/.github/workflows/util/delta-spark-ut/known-failures.txt
index b0928a729e..1a9fb7d1dc 100644
--- a/.github/workflows/util/delta-spark-ut/known-failures.txt
+++ b/.github/workflows/util/delta-spark-ut/known-failures.txt
@@ -46,7 +46,6 @@
org.apache.spark.sql.delta.CloneTableScalaDeletionVectorSuite#shallow clone acro
org.apache.spark.sql.delta.CloneTableScalaSuite#shallow clone across file
systems
org.apache.spark.sql.delta.ConvertToDeltaSQLSuite#CONVERT keeps NaN rows for
finite-threshold predicate (NaN-excluding writer)
org.apache.spark.sql.delta.ConvertToDeltaScalaSuite#CONVERT keeps NaN rows for
finite-threshold predicate (NaN-excluding writer)
-org.apache.spark.sql.delta.DeltaColumnMappingSuite#explicit id matching
org.apache.spark.sql.delta.DeltaDataFrameHadoopOptionsSuite#SC-86916: Delta
log cache should respect options
org.apache.spark.sql.delta.DeltaDataFrameHadoopOptionsSuite#SC-86916:
checkpoint should pick up Hadoop file system options
org.apache.spark.sql.delta.DeltaDataFrameHadoopOptionsSuite#SC-86916:
invalidateCache should invalidate all DeltaLogs of the given path
@@ -66,7 +65,6 @@
org.apache.spark.sql.delta.DeltaParquetFileFormatWithPredicatePushdownSuite#read
org.apache.spark.sql.delta.DeltaParquetFileFormatWithPredicatePushdownSuite#read
DV metadata columns: with rowIndexFilterType=IF_NOT_CONTAINED, with vectorized
Parquet reader=false, with readColumnarBatchAsRows=true
org.apache.spark.sql.delta.DeltaParquetFileFormatWithPredicatePushdownSuite#read
DV metadata columns: with rowIndexFilterType=IF_NOT_CONTAINED, with vectorized
Parquet reader=true, with readColumnarBatchAsRows=false
org.apache.spark.sql.delta.DeltaParquetFileFormatWithPredicatePushdownSuite#read
DV metadata columns: with rowIndexFilterType=IF_NOT_CONTAINED, with vectorized
Parquet reader=true, with readColumnarBatchAsRows=true
-org.apache.spark.sql.delta.DeltaSinkIdColumnMappingSuite#partitioned writing
and batch reading - column mapping id mode
org.apache.spark.sql.delta.DeltaSinkNameColumnMappingSuite#partitioned writing
and batch reading - column mapping name mode
org.apache.spark.sql.delta.DeltaSuite#SC-8810: skipping deleted file still
throws on corrupted file
org.apache.spark.sql.delta.DeltaSuite#all operations with special characters
in path
diff --git a/.github/workflows/velox_backend_x86.yml
b/.github/workflows/velox_backend_x86.yml
index 3f8c362cd1..3d7906e433 100644
--- a/.github/workflows/velox_backend_x86.yml
+++ b/.github/workflows/velox_backend_x86.yml
@@ -1016,7 +1016,7 @@ jobs:
else
$PARALLEL_UT $MVN_CMD clean test -Pspark-3.5 -Pjava-17
-Pbackends-velox -Piceberg -Pdelta -Phudi -Ppaimon -Pspark-ut \
-DargLine="-Dspark.test.home=/opt/shims/spark35/spark_home/"
-DtagsToExclude="$TAGS_EXCLUDE" \
-
-DwildcardSuites="org.apache.spark.sql.GlutenSQL,org.apache.spark.sql.Gluten,org.apache.spark.sql.connector,org.apache.spark.sql.sources,org.apache.spark.sql.hive,org.apache.spark.sql.gluten,org.apache.spark.sql.shim,org.apache.spark.sql.delta.GlutenDeltaStats"
+
-DwildcardSuites="org.apache.spark.sql.GlutenSQL,org.apache.spark.sql.Gluten,org.apache.spark.sql.connector,org.apache.spark.sql.sources,org.apache.spark.sql.hive,org.apache.spark.sql.gluten,org.apache.spark.sql.shim,org.apache.spark.sql.delta.GlutenDeltaStats,org.apache.spark.sql.delta.GlutenDeltaColumnMappingSuite"
fi
- name: Upload test report
if: always()
@@ -1091,7 +1091,7 @@ jobs:
else
$PARALLEL_UT $MVN_CMD clean test -Pspark-3.5 -Pscala-2.13
-Pjava-17 -Pbackends-velox -Piceberg -Pdelta -Pspark-ut \
-DargLine="-Dspark.test.home=/opt/shims/spark35-scala-2.13/spark_home/"
-DtagsToExclude="$TAGS_EXCLUDE" \
-
-DwildcardSuites="org.apache.spark.sql.GlutenSQL,org.apache.spark.sql.Gluten,org.apache.spark.sql.connector,org.apache.spark.sql.sources,org.apache.spark.sql.hive,org.apache.spark.sql.gluten,org.apache.spark.sql.shim,org.apache.spark.sql.delta.GlutenDeltaStats"
+
-DwildcardSuites="org.apache.spark.sql.GlutenSQL,org.apache.spark.sql.Gluten,org.apache.spark.sql.connector,org.apache.spark.sql.sources,org.apache.spark.sql.hive,org.apache.spark.sql.gluten,org.apache.spark.sql.shim,org.apache.spark.sql.delta.GlutenDeltaStats,org.apache.spark.sql.delta.GlutenDeltaColumnMappingSuite"
fi
- name: Upload test report
if: always()
@@ -1475,7 +1475,7 @@ jobs:
else
$PARALLEL_UT $MVN_CMD clean test -Pspark-4.0 -Pscala-2.13
-Pjava-17 -Pbackends-velox -Pdelta -Ppaimon -Pspark-ut \
-DargLine="-Dspark.test.home=/opt/shims/spark40/spark_home/"
-DtagsToExclude="$TAGS_EXCLUDE" \
-
-DwildcardSuites="org.apache.spark.sql.GlutenSQL,org.apache.spark.sql.Gluten,org.apache.spark.sql.connector,org.apache.spark.sql.sources,org.apache.spark.sql.hive,org.apache.spark.sql.gluten,org.apache.spark.sql.shim,org.apache.spark.sql.delta.GlutenDeltaStats"
+
-DwildcardSuites="org.apache.spark.sql.GlutenSQL,org.apache.spark.sql.Gluten,org.apache.spark.sql.connector,org.apache.spark.sql.sources,org.apache.spark.sql.hive,org.apache.spark.sql.gluten,org.apache.spark.sql.shim,org.apache.spark.sql.delta.GlutenDeltaStats,org.apache.spark.sql.delta.GlutenDeltaColumnMappingSuite"
fi
- name: Upload test report
if: always()
@@ -1607,7 +1607,7 @@ jobs:
# Group 3: top-level sql, connector, sources, hive and remaining
tests (~205 classes)
$PARALLEL_UT $MVN_CMD clean test -Pspark-4.1 -Pscala-2.13
-Pjava-17 -Pbackends-velox -Pspark-ut -Pdelta \
-DargLine="-Dspark.test.home=/opt/shims/spark41/spark_home/"
-DtagsToExclude="$TAGS_EXCLUDE" \
-
-DwildcardSuites="org.apache.spark.sql.GlutenSQL,org.apache.spark.sql.Gluten,org.apache.spark.sql.connector,org.apache.spark.sql.sources,org.apache.spark.sql.hive,org.apache.spark.sql.gluten,org.apache.spark.sql.shim,org.apache.spark.sql.delta.GlutenDeltaStats"
+
-DwildcardSuites="org.apache.spark.sql.GlutenSQL,org.apache.spark.sql.Gluten,org.apache.spark.sql.connector,org.apache.spark.sql.sources,org.apache.spark.sql.hive,org.apache.spark.sql.gluten,org.apache.spark.sql.shim,org.apache.spark.sql.delta.GlutenDeltaStats,org.apache.spark.sql.delta.GlutenDeltaColumnMappingSuite"
fi
- name: Upload test report
if: always()
@@ -1743,7 +1743,7 @@ jobs:
# Group 3: top-level sql, connector, sources, hive and remaining
tests (~205 classes)
$PARALLEL_UT $MVN_CMD clean test -Pspark-4.2 -Pscala-2.13
-Pjava-17 -Pbackends-velox -Pspark-ut -Pdelta \
-DargLine="-Dspark.test.home=/opt/shims/spark42/spark_home/"
-DtagsToExclude="$TAGS_EXCLUDE" \
-
-DwildcardSuites="org.apache.spark.sql.GlutenSQL,org.apache.spark.sql.Gluten,org.apache.spark.sql.connector,org.apache.spark.sql.sources,org.apache.spark.sql.hive,org.apache.spark.sql.gluten,org.apache.spark.sql.shim,org.apache.spark.sql.delta.GlutenDeltaStats"
+
-DwildcardSuites="org.apache.spark.sql.GlutenSQL,org.apache.spark.sql.Gluten,org.apache.spark.sql.connector,org.apache.spark.sql.sources,org.apache.spark.sql.hive,org.apache.spark.sql.gluten,org.apache.spark.sql.shim,org.apache.spark.sql.delta.GlutenDeltaStats,org.apache.spark.sql.delta.GlutenDeltaColumnMappingSuite"
fi
- name: Upload test report
if: always()
diff --git
a/backends-velox/src-delta/test/scala/org/apache/gluten/execution/VeloxDeltaSuite.scala
b/backends-velox/src-delta/test/scala/org/apache/gluten/execution/VeloxDeltaSuite.scala
index 3ffee52b4b..64407fcaba 100644
---
a/backends-velox/src-delta/test/scala/org/apache/gluten/execution/VeloxDeltaSuite.scala
+++
b/backends-velox/src-delta/test/scala/org/apache/gluten/execution/VeloxDeltaSuite.scala
@@ -61,14 +61,17 @@ class VeloxDeltaSuite extends DeltaSuite {
|using delta
|tblproperties ("delta.columnMapping.mode" = "$mode")
|""".stripMargin)
- spark.sql(
- "insert into delta_cm_map select id, " +
- "map('a', named_struct('s', concat('v', cast(id % 7 as string)),
't', id), " +
- "'b', named_struct('s', 'x', 't', id * 2)) from range(0, 500)")
+ withSQLConf(vanillaSparkConfs(): _*) {
+ spark.sql(
+ "insert into delta_cm_map select id, " +
+ "map('a', named_struct('s', concat('v', cast(id % 7 as
string)), 't', id), " +
+ "'b', named_struct('s', 'x', 't', id * 2)) from range(0, 500)")
+ }
val pruningFlag =
"spark.gluten.sql.columnar.backend.velox.scanMapKeyPruningEnabled"
withSQLConf(pruningFlag -> "true", "spark.sql.adaptive.enabled" ->
"false") {
runQueryAndCompare(
- "select sum(m['a'].t), max(m['a'].s) from delta_cm_map where
m['a'].s = 'v3'") {
+ "select sum(m['a'].t), max(m['a'].s) from delta_cm_map where
m['a'].s = 'v3'",
+ noFallBack = mode != "id") {
df =>
val subfields = getExecutedPlan(df)
.collect { case scan: DeltaScanTransformer =>
scan.requiredMapSubfields }
diff --git a/docs/backends/velox/get-started/VeloxDelta.md
b/docs/backends/velox/get-started/VeloxDelta.md
index 37f47944fb..2029525705 100644
--- a/docs/backends/velox/get-started/VeloxDelta.md
+++ b/docs/backends/velox/get-started/VeloxDelta.md
@@ -233,7 +233,7 @@ Offload/Fallback
| Unpartitioned | Offload | Offload |
| Partitioned | Offload | Offload |
| Column mapping, name mode | Offload | Offload |
-| Column mapping, id mode | Offload, matched by physical name. Known
ResultMismatch cases: see [Read problems](#read-problems). | Offload, matched
by physical name. Known ResultMismatch cases: see [Read
problems](#read-problems). |
+| Column mapping, id mode | Fallback | Fallback |
| Files with deletion vectors | Fallback | Offload |
| Change data feed, no deletion vectors in range | Offload. PartialOffload
when the table allows deletion vectors and the range has `_change_data` files,
because those scans then fall back (from code). | Offload |
| Change data feed, deletion vectors in range | Fallback, PartialOffload when
a file scan inside Delta's change data feed scan reads no files with deletion
vectors and no `_change_data` files (from code) | Fallback, PartialOffload when
a file scan inside Delta's change data feed scan reads no files with deletion
vectors (from code) |
@@ -336,7 +336,7 @@ The Read column covers Spark 3.5 to 4.2. It covers Spark
3.4 only where the row
| Deletion vectors | Offload, Fallback on Spark 3.4 | PartialOffload |
Gluten's tests check the results of deletion vector DELETE and MERGE on Spark
3.5 and 4.0 with native write turned on. Delta writes the deletion vector
files, and MERGE writes its data files with Delta's writer (see [Write
commands](#write-commands)). Both are from code. See [Deletion
vectors](#deletion-vectors). |
| Change data feed | Offload, also on Spark 3.4. Ranges with deletion vectors
fall back. On Spark 3.4, scans of `_change_data` files also fall back when the
table allows deletion vectors (from code). | Offload | UPDATE and DELETE write
the `_change_data` files with Velox (from code). Change data feed reads of
their changes are correct (seen on 4.1). See [Change data
feed](#change-data-feed). |
| Column mapping, name mode | Offload, also on Spark 3.4 | ResultMismatch on
Spark 3.5, Fallback on Spark 4.x | On Spark 3.5, natively written files have no
Parquet field IDs. Spark 4.x sends these writes to Delta's writer. Both are
from code. See [Write problems](#write-problems). |
-| Column mapping, id mode | Offload, also on Spark 3.4. ResultMismatch when
matching by field ID would select no column (seen on 4.1) or a different column
(from code). | ResultMismatch on Spark 3.5, Exception when Spark's reader reads
the files. Fallback on Spark 4.x. Both are from code. | Gluten matches columns
by physical name. See [Known problems](#known-problems). |
+| Column mapping, id mode | Fallback, including Spark 3.4 | ResultMismatch on
Spark 3.5, Exception on subsequent reads. Fallback on Spark 4.x. Both are from
code. | Spark now matches columns by Parquet field ID even with Gluten enabled.
Spark 3.5 native writes omit these IDs, so files previously read by physical
name through Gluten now fail in Spark's reader. See [Write
problems](#write-problems). Native field-ID reads remain unsupported
([#12241](https://github.com/apache/gluten/issues/ [...]
| Identity columns | Offload | Offload | Seen on 4.1. High-water marks are
correct. The projection that generates identity values runs on Spark (from
code). |
| Generated columns | Offload | Offload | Seen on 4.1. No Gluten test covers
generated columns. Velox computes the generated values when it supports the
expression (from code). Partition filters derived from them reach the native
scan. `DATE_FORMAT` results for years above 9999 differ (see [Write
problems](#write-problems)). |
| CHECK constraints, NOT NULL | Offload | Offload | When every constraint of
the table is a NOT NULL on a top-level column, Gluten checks the Velox batches
for nulls before Velox writes them, with no conversion to rows. A CHECK
constraint, a generated column or a NOT NULL on a nested field makes Delta
check all the constraints on the JVM, row by row, before Velox writes the rows.
Both are from code. Gluten's tests cover NOT NULL on Spark 3.5 and 4.0. Seen on
4.1. |
@@ -415,8 +415,8 @@ The `mergeSchema` and `overwriteSchema` rows need native
write on Spark 3.5 or 4
| `overwriteSchema` with `save(path)` | Offload | Delta applies the change
before the write. From code. Delta Lake's `SchemaEnforcementWithPathSuite`
passes (seen on 4.1). |
| Schema evolution in SQL `INSERT` | PartialOffload | From code. |
| Schema evolution in `MERGE` | PartialOffload, Exception for some STRUCT map
key changes | The merged table contents match Delta Lake. Some STRUCT map key
changes fail in Velox (see [MERGE, UPDATE and DELETE
problems](#merge-update-and-delete-problems)). The two TIMESTAMP_NTZ widening
tests fail before the MERGE runs, in a setup write of TIMESTAMP_NTZ values.
Seen on 4.1. |
-| `RENAME COLUMN` with column mapping | Offload | Reads after top-level and
nested renames return correct results. After a top-level rename, partition
pruning and file skipping still work. |
-| `DROP COLUMN` with column mapping | Offload | The drop is a metadata-only
commit. Reads after the drop run in Velox. Both are from code. Delta Lake's
`DeltaDropColumnSuite` passes (seen on 4.1). |
+| `RENAME COLUMN` with column mapping | Offload in name mode, Fallback in id
mode | Reads after top-level and nested renames return correct results. After a
top-level rename, partition pruning and file skipping still work. |
+| `DROP COLUMN` with column mapping | Offload in name mode, Fallback in id
mode | The drop is a metadata-only commit. Reads after the drop run in Velox
for name mode and Spark for id mode. Both are from code. Delta Lake's
`DeltaDropColumnSuite` passes (seen on 4.1). |
| Type widening | Offload, Exception for DATE to TIMESTAMP_NTZ and for native
writes to FLOAT or DOUBLE partition columns | Seen on 4.1. See [Table
features](#table-features). |
| Parquet schema merging on read (`spark.sql.parquet.mergeSchema=true`) |
Fallback | This is Spark's Parquet read option. Delta Lake's `mergeSchema`
write option is a different setting, and it is Offload (see the first row).
With the read option on, every Parquet scan falls back, Delta scans included.
From code. |
@@ -427,7 +427,7 @@ The `mergeSchema` and `overwriteSchema` rows need native
write on Spark 3.5 or 4
| Problem | Status | Versions | Issue |
|---|---|---|---|
| A column default stored as `EXISTS_DEFAULT` metadata, for example after
`CONVERT TO DELTA`, reads as NULL for rows in files without that column. |
ResultMismatch | Seen on 4.1. #11494 reports the same bug for plain Parquet on
3.4 to 4.1. | [#11494](https://github.com/apache/gluten/issues/11494) |
-| In column mapping id mode, when field IDs no longer match the Parquet column
names, Gluten returns the column with the matching physical name. Delta Lake
returns NULL when no file column has that ID (seen on 4.1). It returns the
column the ID points to when another column has it (from code). |
ResultMismatch | 3.4 to 4.1. Seen on 4.1 for the NULL case, from code
otherwise. | [#12241](https://github.com/apache/gluten/issues/12241) |
+| Native scans do not support Delta column mapping id mode. These scans fall
back to Spark before physical schema translation, preserving missing-field and
redirected-field ID semantics instead of matching by physical name. | Fallback
| 3.4 to 4.2, from code |
[#12241](https://github.com/apache/gluten/issues/12241) |
| On a TIMESTAMP-partitioned table with six partition values from .1 to
.123456 seconds, `count(DISTINCT ts)` returns 3, as if the values were
truncated to milliseconds. Equality filters on the column still return the
right rows. | ResultMismatch | Seen on 4.1 | |
| Reading a data column widened from DATE to TIMESTAMP_NTZ fails on files
written before the change with `Converted type DATE is not allowed for
requested type TIMESTAMP UTC`. A partition column widened the same way reads
correctly. | Exception | Seen on 4.1 | |
| A query that selects only `_metadata.file_name` from a table with a BIGINT
data column named `file_name` reads the data column and fails with `Converted
type BIGINT is not allowed for requested type VARCHAR`. | Exception | Seen on
4.1 | |
@@ -441,12 +441,14 @@ The `mergeSchema` and `overwriteSchema` rows need native
write on Spark 3.5 or 4
These need native write on, unless a row says otherwise. On Spark 4.x, many of
these writes fall back to Delta's writer (see [Native write on Spark
4.x](#native-write-on-spark-4x)), and the Versions column says so.
+For Spark 3.5 id-mode tables, keep
`spark.gluten.sql.columnar.backend.velox.delta.enableNativeWrite=false` to
avoid writing new files without Parquet field IDs. This does not repair
affected files already written. The separate Spark 3.5 writer fallback is
tracked in [#13383](https://github.com/apache/gluten/pull/13383).
+
| Problem | Status | Versions | Issue |
|---|---|---|---|
| A write partitioned by a FLOAT or DOUBLE column fails with `Unsupported
partition type`. | Exception | 3.5, from code. Spark 4.x only with
`delta.writePartitionColumnsToParquet=false` (from code) |
[#13138](https://github.com/apache/gluten/issues/13138) |
| A write to a path scheme the native library cannot write fails at task time.
This covers custom Hadoop file systems, and S3, GCS, HDFS or ABFS in a build
without that connector. | Exception | 3.5 and 4.x, seen on 4.1 (custom file
system), from code (missing connector) |
[#4963](https://github.com/apache/gluten/issues/4963) |
-| Files written for a column mapping table, in name or id mode, have no
Parquet field IDs, which the Delta Lake protocol requires. Delta Lake and
Gluten read name-mode files by physical name. Readers that match by field ID
cannot. | ResultMismatch | 3.5, from code. Spark 4.x falls back | |
-| Spark's own reader fails on natively written id-mode files with `Spark read
schema expects field Ids, but Parquet file schema doesn't contain any field
Ids`. Spark uses this reader when a scan falls back or Gluten is off. With
`spark.sql.parquet.fieldId.read.ignoreMissing=true`, Spark skips this check and
returns NULL for the data columns of these files (from code). That setting is
not tested with these files. | Exception | 3.5, from code. Spark 4.x falls back
| |
+| Files written for a column mapping table, in name or id mode, have no
Parquet field IDs, which the Delta Lake protocol requires. Delta Lake and
Gluten read name-mode files by physical name. Id-mode scans now fall back to
Spark and require field IDs. | ResultMismatch | 3.5, from code. Spark 4.x falls
back | [#13383](https://github.com/apache/gluten/pull/13383) |
+| Spark's reader fails on natively written id-mode files with `Spark read
schema expects field Ids, but Parquet file schema doesn't contain any field
Ids`. Id-mode scans now always fall back, so this error occurs with Gluten
enabled too, including for files previously read natively by physical name.
With `spark.sql.parquet.fieldId.read.ignoreMissing=true`, Spark skips this
check and returns NULL for the data columns of these files (from code, not
tested with these files). It does not res [...]
| Files written for a UniForm table have no Parquet field IDs, so the Iceberg
metadata points at files without IDs. No error is raised. | ResultMismatch |
3.5, from code. Spark 4.x falls back |
[#12957](https://github.com/apache/gluten/pull/12957) |
| A write to a partitioned UniForm table fails with `The file schema type
should be equal with the input rowvector type`. | Exception | 3.5, from code.
Spark 4.x falls back | |
| Some writes of a TIMESTAMP_NTZ data column fail with `The file schema type
should be equal with the input rowvector type`. Delta Lake's type widening
tests fail this way when they write `CAST(value AS TIMESTAMP_NTZ)`. Delta
Lake's data skipping tests also write that cast and pass. | Exception | Seen on
4.1, from code on 3.5. Spark 4.x now falls back | |
@@ -499,7 +501,7 @@ For errors raised on the JVM, the message of the exception
raised in the task st
| spark.gluten.sql.native.writer.enabled | (unset) | Controls native writes of
non-Delta Parquet files. Unset means on. No effect on Delta writes (from code).
|
| spark.gluten.sql.columnar.backend.velox.enableTimestampNtzValidation | false
| When true, every operator whose input or output includes TIMESTAMP_NTZ falls
back. On Spark 4.x, native Delta writes with TIMESTAMP_NTZ columns use Delta's
writer either way. From code. |
| spark.gluten.sql.columnar.backend.velox.scanMapKeyPruningEnabled | false |
When true, Velox skips map keys a query does not look up, if the lookups sit in
filters and projections directly above the scan. Applies to Delta scans without
column mapping. On Spark 3.5 to 4.1 it also applies to files with deletion
vectors. Off for column-mapped tables. |
-| spark.gluten.sql.columnar.backend.velox.parquetUseColumnNames | true | Velox
matches Parquet columns by name. Id-mode column mapping tables are read by
physical name. When false, Velox matches Parquet columns by position, including
for tables without column mapping and id-mode tables. Name-mode tables are
still read by physical name. From code. |
+| spark.gluten.sql.columnar.backend.velox.parquetUseColumnNames | true | For
native scans without Delta column mapping, true matches Parquet columns by name
and false by position. Name-mode Delta tables always use physical names.
Id-mode Delta scans fall back to Spark and use field IDs regardless of this
option. From code. |
| spark.gluten.sql.fallbackUnexpectedMetadataParquet | false | When true,
Delta scans fall back if a sampled file is encrypted, carries legacy datetime
rebase metadata, uses LZO or BROTLI, or has variant annotations. LZ4_RAW also
counts on Spark 4.0 and 4.1. The variant check runs on Spark 4.1 only. The
sample is the first `spark.gluten.sql.fallbackUnexpectedMetadataParquet.limit`
files (default 10) under the table root. `_delta_log` files count. HDFS and S3
list files in name order, and [...]
| spark.gluten.sql.scan.fileSchemeValidation.enabled | true | Scans on a file
scheme Velox cannot read fall back. From code. |
@@ -601,7 +603,7 @@ A blank cell means unknown.
| --- | --- | --- | --- |
| delta.enableDeletionVectors | false | Velox applies deletion vectors in the
scan on Spark 3.5 to 4.2. On Spark 3.4, a read falls back when a file it
selects has a deletion vector. For other Spark 3.4 scans, see [Deletion
vectors](#deletion-vectors). | ✅ Spark 3.5 to 4.1 |
| delta.enableChangeDataFeed | false | Change data feed reads offload, except
ranges with deletion vectors. With native write on, Velox writes the
`_change_data` files of UPDATE and DELETE (from code). For MERGE, see [MERGE,
UPDATE and DELETE problems](#merge-update-and-delete-problems). | ⚠️ |
-| delta.columnMapping.mode | none | Reads offload. On Spark 4.x, native writes
fall back (from code). For id mode and for Spark 3.5 native writes, see [Known
problems](#known-problems). | ⚠️ |
+| delta.columnMapping.mode | none | Name-mode reads offload; id-mode reads
fall back to Spark. On Spark 4.x, native writes fall back (from code). For
Spark 3.5 native writes, see [Write problems](#write-problems). | ⚠️ |
| delta.enableRowTracking | false | Reads and native writes offload. Seen on
4.1. For `_metadata.base_row_id` filters and for `_metadata.row_id` when older
files lack base row IDs, see [Read problems](#read-problems). | ⚠️ |
| delta.enableTypeWidening | false | Most widenings read natively. Seen on
4.1. For DATE to TIMESTAMP_NTZ and for FLOAT or DOUBLE partition columns, see
[Known problems](#known-problems). | ⚠️ |
| delta.universalFormat.enabledFormats | (empty) | Native writes fall back on
Spark 4.x. For Spark 3.5, see [Write problems](#write-problems). From code. |
⚠️ |
diff --git
a/gluten-delta/src/main/scala/org/apache/gluten/execution/DeltaScanTransformer.scala
b/gluten-delta/src/main/scala/org/apache/gluten/execution/DeltaScanTransformer.scala
index 6165b70439..4b6da1b8d0 100644
---
a/gluten-delta/src/main/scala/org/apache/gluten/execution/DeltaScanTransformer.scala
+++
b/gluten-delta/src/main/scala/org/apache/gluten/execution/DeltaScanTransformer.scala
@@ -27,7 +27,7 @@ import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.expressions.{Attribute,
AttributeReference, Expression}
import org.apache.spark.sql.catalyst.plans.QueryPlan
import org.apache.spark.sql.connector.read.streaming.SparkDataStream
-import org.apache.spark.sql.delta.{DeltaParquetFileFormat, NameMapping,
NoMapping}
+import org.apache.spark.sql.delta.{DeltaParquetFileFormat, IdMapping,
NameMapping, NoMapping}
import org.apache.spark.sql.delta.files.{CdcAddFileIndex, TahoeFileIndex,
TahoeRemoveFileIndex}
import org.apache.spark.sql.delta.stats.PreparedDeltaFileIndex
import org.apache.spark.sql.execution.FileSourceScanExec
@@ -94,6 +94,13 @@ case class DeltaScanTransformer(
// files carry DVs. Normal (non-CDF) DV scans are unaffected: those apply
the DV natively through
// the per-file split-info handoff and never reach this guard.
override protected def doValidateInternal(): ValidationResult = {
+ // Delta adds Parquet field IDs during the post-transform schema rewrite,
after validation.
+ // Check the mapping mode here rather than relying on the generic scan's
hasFieldIds check.
+ relation.fileFormat match {
+ case format: DeltaParquetFileFormat if format.columnMappingMode ==
IdMapping =>
+ return
ValidationResult.failed(DeltaScanTransformer.ID_MAPPING_UNSUPPORTED)
+ case _ =>
+ }
if (cdfFilesHaveDeletionVectors) {
return
ValidationResult.failed(DeltaScanTransformer.DELETION_VECTOR_UNSUPPORTED)
}
@@ -282,6 +289,7 @@ case class DeltaScanTransformer(
object DeltaScanTransformer {
val DELETION_VECTOR_UNSUPPORTED = "Deletion vector is not supported in
native."
+ val ID_MAPPING_UNSUPPORTED = "Delta column mapping mode 'id' is not
supported in native scans."
def apply(scanExec: FileSourceScanExec): DeltaScanTransformer = {
new DeltaScanTransformer(
diff --git
a/gluten-delta/src/test/scala/org/apache/gluten/execution/DeltaSuite.scala
b/gluten-delta/src/test/scala/org/apache/gluten/execution/DeltaSuite.scala
index 51accc7705..9f34a668a5 100644
--- a/gluten-delta/src/test/scala/org/apache/gluten/execution/DeltaSuite.scala
+++ b/gluten-delta/src/test/scala/org/apache/gluten/execution/DeltaSuite.scala
@@ -24,7 +24,7 @@ import org.apache.spark.scheduler.{SparkListener,
SparkListenerEvent}
import org.apache.spark.sql.{DataFrame, GlutenDeltaTestUtils, Row}
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.delta.DeltaLog
-import org.apache.spark.sql.execution.SparkPlanInfo
+import org.apache.spark.sql.execution.{FileSourceScanExec, SparkPlanInfo}
import
org.apache.spark.sql.execution.ui.{SparkListenerSQLAdaptiveExecutionUpdate,
SparkListenerSQLExecutionStart}
import org.apache.spark.sql.types._
import org.apache.spark.util.SparkVersionUtil
@@ -61,15 +61,15 @@ abstract class DeltaSuite extends
WholeStageTransformerSuite {
|create table delta_cm1 (id int, name string) using delta
|tblproperties ("delta.columnMapping.mode"= "id")
|""".stripMargin)
- spark.sql(s"""
- |insert into delta_cm1 values (1, "v1"), (2, "v2")
- |""".stripMargin)
- val df1 = runQueryAndCompare("select * from delta_cm1") { _ => }
- checkLengthAndPlan(df1, 2)
+ withSQLConf(vanillaSparkConfs(): _*) {
+ spark.sql(s"""
+ |insert into delta_cm1 values (1, "v1"), (2, "v2")
+ |""".stripMargin)
+ }
+ val df1 = runColumnMappingQuery("select * from delta_cm1", "id")
checkAnswer(df1, Row(1, "v1") :: Row(2, "v2") :: Nil)
- val df2 = runQueryAndCompare("select name from delta_cm1 where id = 2")
{ _ => }
- checkLengthAndPlan(df2, 1)
+ val df2 = runColumnMappingQuery("select name from delta_cm1 where id =
2", "id")
checkAnswer(df2, Row("v2") :: Nil)
}
}
@@ -83,33 +83,43 @@ abstract class DeltaSuite extends
WholeStageTransformerSuite {
spark.sql(s"""
|insert into delta_cm2 values (1, "v1"), (2, "v2")
|""".stripMargin)
- val df1 = runQueryAndCompare("select * from delta_cm2") { _ => }
- checkLengthAndPlan(df1, 2)
+ val df1 = runColumnMappingQuery("select * from delta_cm2", "name")
checkAnswer(df1, Row(1, "v1") :: Row(2, "v2") :: Nil)
- val df2 = runQueryAndCompare("select name from delta_cm2 where id = 2")
{ _ => }
- checkLengthAndPlan(df2, 1)
+ val df2 = runColumnMappingQuery("select name from delta_cm2 where id =
2", "name")
checkAnswer(df2, Row("v2") :: Nil)
}
}
+ private def runColumnMappingQuery(query: String, mode: String): DataFrame = {
+ runQueryAndCompare(query, noFallBack = mode != "id") {
+ df =>
+ val plan = df.queryExecution.executedPlan
+ val nativeScans = collect(plan) { case scan: DeltaScanTransformer =>
scan }
+ val sparkScans = collect(plan) { case scan: FileSourceScanExec => scan
}
+ assert(nativeScans.nonEmpty == (mode != "id"), plan)
+ assert(sparkScans.nonEmpty == (mode == "id"), plan)
+ }
+ }
+
// Counts files Delta will read for `df`. Driven by
`PreparedDeltaFileIndex.inputFiles`, which
// is the post-pruning, post-stats-skipping file set computed by
`PrepareDeltaScan`. Useful for
// asserting that Delta's file index actually pruned, regardless of what
Gluten does later.
private def deltaInputFileCount(df: org.apache.spark.sql.DataFrame): Int =
df.inputFiles.length
- // Counts the partition directories selected by the executed scan after
Gluten's rewrite.
+ // Counts the partition directories selected by the native scan or its Spark
fallback.
// Backed by `selectedPartitions` ->
`relation.location.listFiles(partitionFilters, dataFilters)`,
// which is the exact call site of issue #10511: pre-fix, physical-named
partition filters
// could not match Delta's logical partition schema, so this returned all
directories. We use
// `getPartitionArray` rather than `getPartitions` because the latter
reflects post-coalesce
// splits (Velox may merge small files into one split, hiding the
per-partition count).
private def selectedPartitionCount(df: org.apache.spark.sql.DataFrame): Int
= {
- val scan = df.queryExecution.executedPlan.collect {
- case f: DeltaScanTransformer => f
+ collect(df.queryExecution.executedPlan) {
+ case scan: DeltaScanTransformer => scan.getPartitionArray.length
+ case scan: FileSourceScanExec =>
+ scan.relation.location.listFiles(scan.partitionFilters,
scan.dataFilters).length
}.head
- scan.getPartitionArray.length
}
// Regression for issue #10511: with column mapping, a partition column
filter must prune
@@ -124,35 +134,35 @@ abstract class DeltaSuite extends
WholeStageTransformerSuite {
|partitioned by (id)
|tblproperties ("delta.columnMapping.mode" = "$mode")
|""".stripMargin)
- // Use multiple inserts so each value lands in its own partition
directory & file.
- spark.sql("insert into delta_cm_part values (1, \"v1\")")
- spark.sql("insert into delta_cm_part values (2, \"v2\")")
- spark.sql("insert into delta_cm_part values (3, \"v3\")")
+ // Spark's writer preserves the field IDs required by id-mapped
reads.
+ withSQLConf(vanillaSparkConfs(): _*) {
+ // Use multiple inserts so each value lands in its own partition
directory & file.
+ spark.sql("insert into delta_cm_part values (1, \"v1\")")
+ spark.sql("insert into delta_cm_part values (2, \"v2\")")
+ spark.sql("insert into delta_cm_part values (3, \"v3\")")
+ }
// Equality on partition column. 1 of 3 partitions matches.
- val df1 = runQueryAndCompare("select name from delta_cm_part where
id = 2") { _ => }
- checkLengthAndPlan(df1, 1)
+ val df1 = runColumnMappingQuery("select name from delta_cm_part
where id = 2", mode)
checkAnswer(df1, Row("v2") :: Nil)
assert(deltaInputFileCount(df1) == 1, "Delta should prune to 1 file")
- assert(selectedPartitionCount(df1) == 1, "native scan should see 1
split")
+ assert(selectedPartitionCount(df1) == 1, "scan should select 1
partition")
// Range on partition column (the exact case from the bug report).
- val df2 = runQueryAndCompare("select name from delta_cm_part where
id > 2") { _ => }
- checkLengthAndPlan(df2, 1)
+ val df2 = runColumnMappingQuery("select name from delta_cm_part
where id > 2", mode)
checkAnswer(df2, Row("v3") :: Nil)
assert(deltaInputFileCount(df2) == 1)
assert(selectedPartitionCount(df2) == 1)
// IN list on partition column. 2 of 3 partitions match.
val df3 =
- runQueryAndCompare("select name from delta_cm_part where id in (1,
3)") { _ => }
- checkLengthAndPlan(df3, 2)
+ runColumnMappingQuery("select name from delta_cm_part where id in
(1, 3)", mode)
checkAnswer(df3, Row("v1") :: Row("v3") :: Nil)
assert(deltaInputFileCount(df3) == 2)
assert(selectedPartitionCount(df3) == 2)
// No filter -- baseline: all 3 partitions read.
- val dfAll = runQueryAndCompare("select name from delta_cm_part") { _
=> }
+ val dfAll = runColumnMappingQuery("select name from delta_cm_part",
mode)
assert(deltaInputFileCount(dfAll) == 3)
assert(selectedPartitionCount(dfAll) == 3)
}
@@ -166,22 +176,24 @@ abstract class DeltaSuite extends
WholeStageTransformerSuite {
|using delta partitioned by (region, id)
|tblproperties ("delta.columnMapping.mode" = "$mode")
|""".stripMargin)
- spark.sql("insert into delta_cm_part_multi values (1, \"us\",
\"v1\")")
- spark.sql("insert into delta_cm_part_multi values (2, \"us\",
\"v2\")")
- spark.sql("insert into delta_cm_part_multi values (1, \"eu\",
\"v3\")")
- spark.sql("insert into delta_cm_part_multi values (2, \"eu\",
\"v4\")")
-
- val df = runQueryAndCompare(
- "select name from delta_cm_part_multi where region = 'us' and id >
1") { _ => }
- checkLengthAndPlan(df, 1)
+ withSQLConf(vanillaSparkConfs(): _*) {
+ spark.sql("insert into delta_cm_part_multi values (1, \"us\",
\"v1\")")
+ spark.sql("insert into delta_cm_part_multi values (2, \"us\",
\"v2\")")
+ spark.sql("insert into delta_cm_part_multi values (1, \"eu\",
\"v3\")")
+ spark.sql("insert into delta_cm_part_multi values (2, \"eu\",
\"v4\")")
+ }
+
+ val df = runColumnMappingQuery(
+ "select name from delta_cm_part_multi where region = 'us' and id >
1",
+ mode)
checkAnswer(df, Row("v2") :: Nil)
assert(deltaInputFileCount(df) == 1, "Delta should prune to 1 file
with both filters")
assert(selectedPartitionCount(df) == 1)
// Filter on only one of two partition columns.
- val df2 = runQueryAndCompare(
- "select name from delta_cm_part_multi where region = 'eu'") { _ =>
}
- checkLengthAndPlan(df2, 2)
+ val df2 = runColumnMappingQuery(
+ "select name from delta_cm_part_multi where region = 'eu'",
+ mode)
checkAnswer(df2, Row("v3") :: Row("v4") :: Nil)
assert(deltaInputFileCount(df2) == 2)
assert(selectedPartitionCount(df2) == 2)
@@ -195,15 +207,17 @@ abstract class DeltaSuite extends
WholeStageTransformerSuite {
|using delta partitioned by (id)
|tblproperties ("delta.columnMapping.mode" = "$mode")
|""".stripMargin)
- spark.sql("insert into delta_cm_part_data values (1, \"a\", 10), (1,
\"b\", 20)")
- spark.sql("insert into delta_cm_part_data values (2, \"c\", 30), (2,
\"d\", 40)")
- spark.sql("insert into delta_cm_part_data values (3, \"e\", 50), (3,
\"f\", 60)")
+ withSQLConf(vanillaSparkConfs(): _*) {
+ spark.sql("insert into delta_cm_part_data values (1, \"a\", 10),
(1, \"b\", 20)")
+ spark.sql("insert into delta_cm_part_data values (2, \"c\", 30),
(2, \"d\", 40)")
+ spark.sql("insert into delta_cm_part_data values (3, \"e\", 50),
(3, \"f\", 60)")
+ }
// Combined: partition pruning to id > 1 keeps 2 files; data
stats-skipping on age >= 50
// further drops the id=2 file (max age 40 < 50). Should leave 1
file.
- val df1 = runQueryAndCompare(
- "select name from delta_cm_part_data where id > 1 and age >= 50")
{ _ => }
- checkLengthAndPlan(df1, 2)
+ val df1 = runColumnMappingQuery(
+ "select name from delta_cm_part_data where id > 1 and age >= 50",
+ mode)
checkAnswer(df1, Row("e") :: Row("f") :: Nil)
assert(
deltaInputFileCount(df1) == 1,
@@ -211,9 +225,8 @@ abstract class DeltaSuite extends
WholeStageTransformerSuite {
// Data filter alone -- file-level stats skipping should resolve
column names.
// Only the id=2 file (age 30..40) matches age = 30.
- val df2 = runQueryAndCompare(
- "select name from delta_cm_part_data where age = 30") { _ => }
- checkLengthAndPlan(df2, 1)
+ val df2 =
+ runColumnMappingQuery("select name from delta_cm_part_data where
age = 30", mode)
checkAnswer(df2, Row("c") :: Nil)
assert(
deltaInputFileCount(df2) == 1,
@@ -228,18 +241,22 @@ abstract class DeltaSuite extends
WholeStageTransformerSuite {
|using delta partitioned by (id)
|tblproperties ("delta.columnMapping.mode" = "$mode")
|""".stripMargin)
- spark.sql("insert into delta_cm_part_null values (1, \"v1\")")
- spark.sql("insert into delta_cm_part_null values (2, \"v2\")")
- spark.sql("insert into delta_cm_part_null values (cast(null as int),
\"vn\")")
+ withSQLConf(vanillaSparkConfs(): _*) {
+ spark.sql("insert into delta_cm_part_null values (1, \"v1\")")
+ spark.sql("insert into delta_cm_part_null values (2, \"v2\")")
+ spark.sql("insert into delta_cm_part_null values (cast(null as
int), \"vn\")")
+ }
- val df1 = runQueryAndCompare(
- "select name from delta_cm_part_null where id is null") { _ => }
+ val df1 = runColumnMappingQuery(
+ "select name from delta_cm_part_null where id is null",
+ mode)
checkAnswer(df1, Row("vn") :: Nil)
assert(deltaInputFileCount(df1) == 1)
assert(selectedPartitionCount(df1) == 1)
- val df2 = runQueryAndCompare(
- "select name from delta_cm_part_null where id is not null") { _ =>
}
+ val df2 = runColumnMappingQuery(
+ "select name from delta_cm_part_null where id is not null",
+ mode)
checkAnswer(df2, Row("v1") :: Row("v2") :: Nil)
assert(deltaInputFileCount(df2) == 2)
assert(selectedPartitionCount(df2) == 2)
@@ -253,16 +270,18 @@ abstract class DeltaSuite extends
WholeStageTransformerSuite {
|using delta partitioned by (id)
|tblproperties ("delta.columnMapping.mode" = "$mode")
|""".stripMargin)
- spark.sql("insert into delta_cm_part_rename values (1, \"v1\")")
- spark.sql("insert into delta_cm_part_rename values (2, \"v2\")")
- spark.sql("insert into delta_cm_part_rename values (3, \"v3\")")
+ withSQLConf(vanillaSparkConfs(): _*) {
+ spark.sql("insert into delta_cm_part_rename values (1, \"v1\")")
+ spark.sql("insert into delta_cm_part_rename values (2, \"v2\")")
+ spark.sql("insert into delta_cm_part_rename values (3, \"v3\")")
+ }
// Rename the partition column. The physical name in storage stays
the same; only the
// logical name changes, so the logical-name-based partition filter
must still resolve.
spark.sql("alter table delta_cm_part_rename rename column id to pid")
- val df = runQueryAndCompare(
- "select name from delta_cm_part_rename where pid >= 2") { _ => }
- checkLengthAndPlan(df, 2)
+ val df = runColumnMappingQuery(
+ "select name from delta_cm_part_rename where pid >= 2",
+ mode)
checkAnswer(df, Row("v2") :: Row("v3") :: Nil)
assert(deltaInputFileCount(df) == 2)
assert(selectedPartitionCount(df) == 2)
@@ -276,16 +295,18 @@ abstract class DeltaSuite extends
WholeStageTransformerSuite {
|using delta
|tblproperties ("delta.columnMapping.mode" = "$mode")
|""".stripMargin)
- spark.sql("insert into delta_cm_data_rename values (1, 10, \"a\")")
- spark.sql("insert into delta_cm_data_rename values (2, 20, \"b\")")
- spark.sql("insert into delta_cm_data_rename values (3, 30, \"c\")")
+ withSQLConf(vanillaSparkConfs(): _*) {
+ spark.sql("insert into delta_cm_data_rename values (1, 10, \"a\")")
+ spark.sql("insert into delta_cm_data_rename values (2, 20, \"b\")")
+ spark.sql("insert into delta_cm_data_rename values (3, 30, \"c\")")
+ }
// Rename a data column. Filter pushdown must still match physical
column in parquet,
// and Delta's stats-based skipping must still resolve the logical
name `years`.
spark.sql("alter table delta_cm_data_rename rename column age to
years")
- val df = runQueryAndCompare(
- "select name from delta_cm_data_rename where years = 20") { _ => }
- checkLengthAndPlan(df, 1)
+ val df = runColumnMappingQuery(
+ "select name from delta_cm_data_rename where years = 20",
+ mode)
checkAnswer(df, Row("b") :: Nil)
assert(
deltaInputFileCount(df) == 1,
diff --git
a/gluten-ut/spark35/src-delta/test/scala/org/apache/spark/sql/delta/GlutenDeltaColumnMappingSuite.scala
b/gluten-ut/spark35/src-delta/test/scala/org/apache/spark/sql/delta/GlutenDeltaColumnMappingSuite.scala
new file mode 100644
index 0000000000..d1e82281ad
--- /dev/null
+++
b/gluten-ut/spark35/src-delta/test/scala/org/apache/spark/sql/delta/GlutenDeltaColumnMappingSuite.scala
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.delta
+
+import org.apache.gluten.config.GlutenConfig
+import org.apache.gluten.execution.DeltaScanTransformer
+import org.apache.gluten.utils.BackendTestUtils
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.{GlutenQueryTest, Row}
+import org.apache.spark.sql.catalyst.TableIdentifier
+import org.apache.spark.sql.execution.FileSourceScanExec
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types.{MetadataBuilder, StructType}
+
+class GlutenDeltaColumnMappingSuite extends GlutenQueryTest with
SharedSparkSession {
+ override protected def sparkConf: SparkConf = {
+ super.sparkConf
+ .set("spark.plugins", "org.apache.gluten.GlutenPlugin")
+ .set("spark.shuffle.manager",
"org.apache.spark.shuffle.sort.ColumnarShuffleManager")
+ .set("spark.default.parallelism", "1")
+ .set("spark.sql.shuffle.partitions", "1")
+ .set("spark.memory.offHeap.enabled", "true")
+ .set("spark.memory.offHeap.size", "1024MB")
+ .set("spark.ui.enabled", "false")
+ .set(GlutenConfig.GLUTEN_UI_ENABLED.key, "false")
+ .set("spark.sql.extensions", "io.delta.sql.DeltaSparkSessionExtension")
+ .set("spark.sql.catalog.spark_catalog",
"org.apache.spark.sql.delta.catalog.DeltaCatalog")
+ .set("spark.databricks.delta.snapshotPartitions", "1")
+ .set("spark.sql.parquet.fieldId.read.enabled", "true")
+ .set("spark.sql.parquet.fieldId.write.enabled", "true")
+ .set("spark.sql.adaptive.enabled", "false")
+ .set("spark.sql.ansi.enabled", "false")
+ }
+
+ Seq(false, true).foreach {
+ vectorized =>
+ test(s"Delta id mapping reads field IDs instead of physical names,
vectorized=$vectorized") {
+ assume(BackendTestUtils.isVeloxBackendLoaded())
+ withSQLConf("spark.sql.parquet.enableVectorizedReader" ->
vectorized.toString) {
+ withTable("delta_id_read") {
+ // Isolate the reader from Spark 3.5's native writer, which does
not preserve field IDs.
+ withSQLConf(GlutenConfig.GLUTEN_ENABLED.key -> "false") {
+ spark.sql("""
+ |CREATE TABLE delta_id_read (a STRING, b STRING)
USING delta
+ |TBLPROPERTIES ('delta.columnMapping.mode' = 'id')
+ |""".stripMargin)
+ spark.sql("INSERT INTO delta_id_read VALUES ('original',
'redirected')")
+ }
+ val log = DeltaLog.forTable(spark,
TableIdentifier("delta_id_read"))
+ val otherId = log.update().metadata.schema("b").metadata
+ .getLong(DeltaColumnMapping.COLUMN_MAPPING_METADATA_ID_KEY)
+ spark.sql("ALTER TABLE delta_id_read DROP COLUMN b")
+
+ Seq(100L -> Row(null), otherId -> Row("redirected")).foreach {
+ case (fieldId, expected) =>
+ val metadata = log.update().metadata
+ val field = metadata.schema("a")
+ val updated = field.copy(metadata = new MetadataBuilder()
+ .withMetadata(field.metadata)
+ .putLong(DeltaColumnMapping.COLUMN_MAPPING_METADATA_ID_KEY,
fieldId)
+ .build())
+ log.withNewTransaction {
+ txn =>
+ txn.commit(
+ Seq(metadata.copy(
+ schemaString = StructType(Seq(updated)).json,
+ configuration = metadata.configuration +
+ (DeltaConfigs.COLUMN_MAPPING_MAX_ID.key ->
"10000"))),
+ DeltaOperations.ManualUpdate
+ )
+ }
+
+ val df = spark.sql("SELECT a FROM delta_id_read")
+ val scan = df.queryExecution.sparkPlan.collect {
+ case fileScan: FileSourceScanExec => fileScan
+ }.head
+ assert(
+ !scan.requiredSchema("a").metadata
+
.contains(DeltaColumnMapping.PARQUET_FIELD_ID_METADATA_KEY))
+ val validation = DeltaScanTransformer(scan).doValidate()
+ assert(!validation.ok())
+
assert(validation.reason().contains(DeltaScanTransformer.ID_MAPPING_UNSUPPORTED))
+ checkAnswer(df, Seq(expected))
+ assert(
+ collect(df.queryExecution.executedPlan) {
+ case _: DeltaScanTransformer => true
+ }.isEmpty,
+ df.queryExecution.executedPlan)
+ assert(
+ collect(df.queryExecution.executedPlan) {
+ case _: FileSourceScanExec => true
+ }.nonEmpty,
+ df.queryExecution.executedPlan)
+ }
+ }
+ }
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]