felipepessoto commented on code in PR #13674:
URL: https://github.com/apache/gluten/pull/13674#discussion_r4744304409
##########
backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/GlutenOptimisticTransaction.scala:
##########
@@ -73,6 +92,27 @@ class GlutenOptimisticTransaction(delegate:
OptimisticTransaction)
val partitioningColumns = getPartitioningColumns(partitionSchema, output)
+ // As in the Delta 4.x write gate, check the normalized output so
generated columns are included.
+ // Partition-only values live in directory names rather than Parquet data
columns.
+ val dataOutput = output.filterNot(partitioningColumns.contains)
Review Comment:
Please check the normalized file fields for explicit `parquet.field.id`
metadata too. Column mapping is not required for Spark to write field IDs. I
streamed a BIGINT with field ID 41 into a table with column mapping off.
Delta's writer preserved 41; the native writer committed the file without it.
Name-based Delta reads still passed, but a Spark Parquet read requesting that
same ID under a different column name returned `0` for the vanilla file and
failed on the native file because it has no field IDs. The 4.x gate already
falls back on `ParquetUtils.hasFieldIds(fileSchema)`.
##########
backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/GlutenOptimisticTransaction.scala:
##########
@@ -73,6 +92,27 @@ class GlutenOptimisticTransaction(delegate:
OptimisticTransaction)
val partitioningColumns = getPartitioningColumns(partitionSchema, output)
+ // As in the Delta 4.x write gate, check the normalized output so
generated columns are included.
+ // Partition-only values live in directory names rather than Parquet data
columns.
+ val dataOutput = output.filterNot(partitioningColumns.contains)
+ val hasDateData = dataOutput.exists {
+ field => SchemaUtils.typeExistsRecursively(field.dataType)(_ == DateType)
+ }
+ val hasTimestampData = dataOutput.exists {
+ field => SchemaUtils.typeExistsRecursively(field.dataType)(_ ==
TimestampType)
+ }
+ val conf = spark.sessionState.conf
+ val needsRebase = (hasDateData || hasTimestampData) &&
+
!conf.getConf(SQLConf.PARQUET_REBASE_MODE_IN_WRITE).equalsIgnoreCase("CORRECTED")
+ // Velox only writes microsecond timestamps and never rebases dates or
timestamps. Let Delta
+ // write INT96 (using its separate int96RebaseModeInWrite policy) and
TIMESTAMP_MILLIS.
+ val unsupportedTimestampEncoding = hasTimestampData &&
+ conf.parquetOutputTimestampType !=
SQLConf.ParquetOutputTimestampType.TIMESTAMP_MICROS
+ if (needsRebase || unsupportedTimestampEncoding) {
+ logInfo("Writing with vanilla Delta to preserve datetime encoding and
rebase policies.")
+ return super.writeFiles(inputData, writeOptions, isOptimize,
additionalConstraints)
Review Comment:
Nonblocking: this calls Delta's `writeFiles` after we've already called
`normalizeData`, so fallback normalizes the batch again. For generated columns,
Delta's `selectFromStreamingDataFrame` forces physical planning. I counted two
such plans for one generated-DATE `LEGACY` micro-batch with the wrapper, versus
one without it. It still commits only once. Using the normalized output to
choose the file writer, as the 4.x path does, would avoid repeating this work
on every fallback batch.
##########
backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/GlutenOptimisticTransaction.scala:
##########
@@ -73,6 +92,27 @@ class GlutenOptimisticTransaction(delegate:
OptimisticTransaction)
val partitioningColumns = getPartitioningColumns(partitionSchema, output)
+ // As in the Delta 4.x write gate, check the normalized output so
generated columns are included.
+ // Partition-only values live in directory names rather than Parquet data
columns.
+ val dataOutput = output.filterNot(partitioningColumns.contains)
+ val hasDateData = dataOutput.exists {
+ field => SchemaUtils.typeExistsRecursively(field.dataType)(_ == DateType)
+ }
+ val hasTimestampData = dataOutput.exists {
+ field => SchemaUtils.typeExistsRecursively(field.dataType)(_ ==
TimestampType)
Review Comment:
`TimestampType` doesn't include `TimestampNTZType`. I streamed `2024-01-02
03:04:05.123456` into an unpartitioned `TIMESTAMP_NTZ` column on Spark 3.5.5
with the default timestamp settings. Delta wrote `TIMESTAMP(MICROS,false)` and
read the row back. The native sink wrote `TIMESTAMP(MICROS,true)`, committed
the Delta version and checkpoint, and a subsequent Spark Delta read failed with
`Unable to create Parquet converter for data type "timestamp_ntz"`. This isn't
an ancient-date case. Please send NTZ data columns (including nested fields) to
Delta's writer regardless of rebase mode, as the 4.x gate does, and check the
Spark read after the stream commits.
--
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]