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 5ca9ea5549 [VL][Delta] Fall back native write for column-mapped tables 
on Spark 3.5 (#13383)
5ca9ea5549 is described below

commit 5ca9ea55495d61951edfab1e6b1a805bfb812171
Author: Mohammad Linjawi <[email protected]>
AuthorDate: Wed Nov 25 22:09:58 2026 +0300

    [VL][Delta] Fall back native write for column-mapped tables on Spark 3.5 
(#13383)
---
 .../sql/delta/GlutenOptimisticTransaction.scala    |  9 +++
 .../spark/sql/delta/DeltaNativeWriteSuite.scala    | 87 ++++++++++++++++++++++
 docs/backends/velox/get-started/VeloxDelta.md      | 21 ++----
 3 files changed, 104 insertions(+), 13 deletions(-)

diff --git 
a/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/GlutenOptimisticTransaction.scala
 
b/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/GlutenOptimisticTransaction.scala
index 8e53d53b2c..dac007eadf 100644
--- 
a/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/GlutenOptimisticTransaction.scala
+++ 
b/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/GlutenOptimisticTransaction.scala
@@ -49,6 +49,15 @@ class GlutenOptimisticTransaction(delegate: 
OptimisticTransaction)
       writeOptions: Option[DeltaOptions],
       isOptimize: Boolean,
       additionalConstraints: Seq[Constraint]): Seq[FileAction] = {
+    // Delta writes Parquet field IDs for both name and id column mapping, and 
Iceberg
+    // compatibility requires column mapping. The Velox writer drops field 
metadata, so its files
+    // would carry no field IDs, which Spark's reader rejects under id mapping.
+    if (metadata.columnMappingMode != NoMapping) {
+      logInfo(
+        "Parquet field IDs for column mapping are not written by the Velox 
writer; " +
+          "falling back to the vanilla Delta write path.")
+      return super.writeFiles(inputData, writeOptions, isOptimize, 
additionalConstraints)
+    }
     hasWritten = true
 
     val spark = inputData.sparkSession
diff --git 
a/backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
 
b/backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
index 41260daad9..1cab51e3f8 100644
--- 
a/backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
+++ 
b/backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
@@ -28,11 +28,18 @@ import 
org.apache.spark.sql.delta.files.GlutenDeltaFileFormatWriter
 import org.apache.spark.sql.delta.schema.InvariantViolationException
 import org.apache.spark.sql.delta.sources.DeltaSQLConf
 import org.apache.spark.sql.delta.test.DeltaSQLCommandTest
+import org.apache.spark.sql.delta.util.DeltaFileOperations
 import org.apache.spark.sql.execution.SparkPlan
 import org.apache.spark.sql.execution.command.ExecutedCommandExec
 import 
org.apache.spark.sql.execution.datasources.v2.{GlutenDeltaLeafRunnableCommand, 
GlutenDeltaLeafV2CommandExec, GlutenDeltaRunnableCommand}
 import org.apache.spark.sql.internal.SQLConf
 
+import org.apache.parquet.hadoop.ParquetFileReader
+import org.apache.parquet.hadoop.metadata.ParquetMetadata
+import org.apache.parquet.hadoop.util.HadoopInputFile
+
+import scala.collection.JavaConverters._
+
 class DeltaNativeWriteSuite extends DeltaSQLCommandTest {
 
   import testImplicits._
@@ -98,6 +105,36 @@ class DeltaNativeWriteSuite extends DeltaSQLCommandTest {
     deltaLog.update().allFiles.collect().toSet
   }
 
+  private def footers(path: String): Seq[(AddFile, ParquetMetadata)] = {
+    val deltaLog = DeltaLog.forTable(spark, path)
+    val hadoopConf = deltaLog.newDeltaHadoopConf()
+    files(deltaLog).toSeq.map {
+      file =>
+        val reader = ParquetFileReader.open(
+          HadoopInputFile.fromPath(DeltaFileOperations.absolutePath(path, 
file.path), hadoopConf))
+        try {
+          file -> reader.getFooter
+        } finally {
+          reader.close()
+        }
+    }
+  }
+
+  // Vanilla Spark writes with parquet-mr; the Velox writer does not.
+  private def writtenByVelox(footer: ParquetMetadata): Boolean =
+    !footer.getFileMetaData.getCreatedBy.startsWith("parquet-mr")
+
+  private def appendTenRows(path: String): Unit = {
+    spark
+      .range(10)
+      .selectExpr("id", "CAST(id AS STRING) AS value")
+      .coalesce(1)
+      .write
+      .format("delta")
+      .mode("append")
+      .save(path)
+  }
+
   private def collectOptimizeMetrics(df: DataFrame): OptimizeMetrics = {
     val metrics = df.select("metrics.*").as[OptimizeMetrics].collect()
     assert(metrics.length == 1, s"Expected one OPTIMIZE result row, got 
${metrics.length}")
@@ -288,6 +325,56 @@ class DeltaNativeWriteSuite extends DeltaSQLCommandTest {
     }
   }
 
+  test("a table without column mapping is written natively") {
+    withNativeWriteOffloadConf {
+      withTempDir {
+        dir =>
+          val path = dir.getCanonicalPath
+          sql(s"CREATE TABLE delta.`$path` (id BIGINT, value STRING) USING 
delta")
+          appendTenRows(path)
+
+          val written = footers(path)
+          assert(written.nonEmpty)
+          written.foreach {
+            case (file, footer) =>
+              assert(writtenByVelox(footer), s"${file.path}: 
${footer.getFileMetaData}")
+          }
+      }
+    }
+  }
+
+  for (mode <- Seq("name", "id")) {
+    test(s"$mode column mapping falls back and writes Parquet field IDs") {
+      withNativeWriteOffloadConf {
+        withTempDir {
+          dir =>
+            val path = dir.getCanonicalPath
+            sql(
+              s"CREATE TABLE delta.`$path` (id BIGINT, value STRING) USING 
delta " +
+                s"TBLPROPERTIES ('delta.columnMapping.mode' = '$mode')")
+            appendTenRows(path)
+
+            val written = footers(path)
+            assert(written.nonEmpty)
+            written.foreach {
+              case (file, footer) =>
+                assert(!writtenByVelox(footer), s"${file.path}: 
${footer.getFileMetaData}")
+                assert(
+                  
footer.getFileMetaData.getSchema.getFields.asScala.forall(_.getId != null),
+                  s"${file.path}: ${footer.getFileMetaData.getSchema}")
+            }
+            // Spark's reader matches columns by field ID under id mapping, 
and fails on files
+            // without them.
+            withSQLConf(GlutenConfig.GLUTEN_ENABLED.key -> "false") {
+              assert(
+                spark.read.format("delta").load(path).collect().toSet ==
+                  (0 until 10).map(i => Row(i.toLong, i.toString)).toSet)
+            }
+        }
+      }
+    }
+  }
+
   private def appendRows(path: String, rows: (java.lang.Long, String)*): Unit 
= {
     rows.toDF("id", "s").write.format("delta").mode("append").save(path)
   }
diff --git a/docs/backends/velox/get-started/VeloxDelta.md 
b/docs/backends/velox/get-started/VeloxDelta.md
index 883261352a..8802476e01 100644
--- a/docs/backends/velox/get-started/VeloxDelta.md
+++ b/docs/backends/velox/get-started/VeloxDelta.md
@@ -157,7 +157,7 @@ UPDATE t SET name = 'b' WHERE id = 2;
 
 On Spark 3.5 or 4.x, set 
`spark.gluten.sql.columnar.backend.velox.delta.enableNativeWrite=true` to have 
Velox write the data files of the commands marked Offload in [Write 
commands](#write-commands). Velox writes the files of this UPDATE. Seen on 4.1. 
On 3.5 and 4.0 this is from code. On Spark 4.x, also apply [ANSI mode on Spark 
4.x](#ansi-mode-on-spark-4x).
 
-On Spark 3.5, native write does not check the codec, the path scheme or the 
partition column types before it runs. Unsupported values make the task fail or 
write wrong files. On Spark 4.x, the checks in [Native write on Spark 
4.x](#native-write-on-spark-4x) send most of those writes to Delta's writer. 
Read [Write problems](#write-problems) before turning it on.
+On Spark 3.5, native write sends column-mapped tables, including UniForm 
tables, to Delta's writer, since Delta Lake writes Parquet field IDs for them 
(from code). It does not check the codec, the path scheme or the partition 
column types before it runs. Unsupported values make the task fail or write 
wrong files. On Spark 4.x, the checks in [Native write on Spark 
4.x](#native-write-on-spark-4x) send most of those writes to Delta's writer. 
Read [Write problems](#write-problems) before tur [...]
 
 ### Native write on Spark 4.x
 
@@ -338,14 +338,14 @@ 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 | 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/ [...]
+| Column mapping, name mode | Offload, also on Spark 3.4 | Fallback | Delta 
Lake writes Parquet field IDs, which the Velox writer does not, so Delta's 
writer writes the files. From code. |
+| Column mapping, id mode | Fallback, including Spark 3.4 | Fallback, as in 
name mode. From code. | Spark matches columns by Parquet field ID even with 
Gluten enabled. Id-mode files written natively on Spark 3.5 before 
[#13383](https://github.com/apache/gluten/pull/13383) have no field IDs and 
fail in Spark's reader. See [Write problems](#write-problems). Native field-ID 
reads remain unsupported 
([#12241](https://github.com/apache/gluten/issues/12241)). |
 | 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. |
 | Row tracking | Offload, Exception for `_metadata.base_row_id` filters, 
ResultMismatch for `_metadata.row_id` when older files lack base row IDs | 
Offload | Seen on 4.1. See [Read problems](#read-problems). |
 | Liquid clustering | Offload | PartialOffload | Reads use the same native 
scan as other tables. Native commands write to clustered tables. `OPTIMIZE`, 
which clusters the data, uses Delta's writer. All three are from code. |
-| UniForm (IcebergCompatV1, V2) | | ResultMismatch on Spark 3.5, Exception 
when partitioned. Fallback on Spark 4.x. | The write statuses are from code. No 
test reads a UniForm table. |
+| UniForm (IcebergCompatV1, V2) | | Fallback | Iceberg compatibility requires 
column mapping. The write status is from code. No test reads a UniForm table. |
 | Type widening | Offload, Exception for DATE to TIMESTAMP_NTZ data columns | 
Offload. Writes to FLOAT or DOUBLE partition columns and some TIMESTAMP_NTZ 
writes failed (seen on 4.1). Spark 4.x now sends those writes to Delta's writer 
(from code). | Seen on 4.1. Spark 3.5 and 4.0 are not covered. Delta Lake 3.3.2 
on Spark 3.5 allows only TINYINT to SMALLINT to INT. |
 | TIMESTAMP_NTZ | PartialOffload, also on Spark 3.4 | Offload on Spark 3.5, 
Exception for some writes. Fallback on Spark 4.x. Both are from code. | See 
[DataType](#datatype). |
 | Variant, including shredding | Fallback | Fallback | Spark 4.x. From code. 
See [DataType](#datatype). |
@@ -386,7 +386,7 @@ Delta data files are Parquet, and Gluten reads them with 
Velox's Parquet reader.
 | Compression | snappy (default), gzip, zstd (always level 3), lz4 (Hadoop 
framing), none. From code. Other codecs fall back on Spark 4.x; for Spark 3.5, 
see [Write problems](#write-problems). |
 | Row groups | Sized by `spark.gluten.sql.columnar.parquet.write.blockSize` 
and `spark.gluten.sql.native.parquet.write.blockRows`. `parquet.*` settings are 
ignored. From code. |
 | TIMESTAMP | INT64 microseconds. On Spark 3.5, 
`spark.sql.parquet.outputTimestampType` is ignored, and Delta Lake's writer 
uses INT96 by default. On Spark 4.x, writes with TIMESTAMP columns fall back 
unless that setting is `TIMESTAMP_MICROS`. Spark reads both. From code. |
-| Parquet field IDs | Not written. On Spark 3.5 this includes column-mapped 
and UniForm tables. On Spark 4.x, writes that need field IDs fall back. Both 
are from code. See [Write problems](#write-problems). |
+| Parquet field IDs | Not written. Writes to column-mapped and UniForm tables 
fall back. On Spark 4.x, so do writes of other columns with `parquet.field.id` 
metadata. From code. |
 | Spark schema footer entry | `org.apache.spark.sql.parquet.row.metadata` is 
not written ([#13288](https://github.com/apache/gluten/issues/13288)). Seen on 
4.1. |
 | Nested field names | Lowercased below the top level when 
`spark.sql.caseSensitive=false`. Spark and Gluten match them 
case-insensitively. A case-sensitive reader can miss them. From code. |
 | Page index | Always written. From code. |
@@ -444,16 +444,11 @@ 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, from code. Spark 4.x falls back: 
seen on 4.1 for custom file systems, from code for a 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. 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 | |
+| Spark's reader fails on id-mode files written natively on Spark 3.5 before 
[#13383](https://github.com/apache/gluten/pull/13383), which have no Parquet 
field IDs, 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. New writes fall back to Delta's writer, which does 
not repair these files. With `sp [...]
 | 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 | |
 | A partitioned write fails in Velox's `PartitionIdGenerator` when a TIMESTAMP 
or TIMESTAMP_NTZ partition value has sub-millisecond digits. | Exception | 3.5, 
from code. On Spark 4.x, TIMESTAMP_NTZ writes fall back, and TIMESTAMP only 
with `outputTimestampType=TIMESTAMP_MICROS` and 
`delta.writePartitionColumnsToParquet=false` (from code) | |
 | A generated partition column such as `DATE_FORMAT(ts, 'yyyy-MM')` stores 
`12345-07` for the year 12345. Spark stores `+12345-07`. Not checked with 
native write off. | ResultMismatch | Seen on 4.1 | |
@@ -606,10 +601,10 @@ 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 | 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.columnMapping.mode | none | Name-mode reads offload; id-mode reads 
fall back to Spark. Native writes fall back (from code). For id-mode files 
written natively on Spark 3.5 before this fallback, 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. | 
⚠️ |
+| delta.universalFormat.enabledFormats | (empty) | Native writes fall back. 
From code. | ⚠️ |
 | delta.enableIcebergCompatV2 | (unset) | Same as 
`delta.universalFormat.enabledFormats`. | ⚠️ |
 | delta.autoOptimize.optimizeWrite | (unset) | Native writes run the optimized 
write shuffle in Velox. From code. | ✅ |
 | delta.autoOptimize.autoCompact | (unset) | Compacts natively written tables. 
Seen on 4.1. | ✅ |


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to