felipepessoto commented on code in PR #13674:
URL: https://github.com/apache/gluten/pull/13674#discussion_r4774262795


##########
docs/backends/velox/get-started/VeloxDelta.md:
##########
@@ -454,8 +454,8 @@ These need native write on, unless a row says otherwise. On 
Spark 4.x, many of t
 | 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 | |
 | The `compression` option set to brotli or lzo fails the write. So does 
`spark.sql.parquet.compression.codec` when the option is unset. The write fails 
even with the Hadoop codec class on the classpath. Without that class, Delta's 
writer fails too, and Spark does not ship it. | Exception | 3.5, from code. 
Spark 4.x falls back | |
 | The `compression` option or `spark.sql.parquet.compression.codec` set to 
lz4_raw writes Snappy data into a `.lz4raw.parquet` file. | ResultMismatch | 
3.5, from code. Spark 4.x falls back | |
-| `maxRecordsPerFile` on an unpartitioned write counts rows but writes whole 
batches. When the limit is smaller than a batch, the whole batch goes into one 
file. The other files opened for that batch are 0-byte files that are not valid 
Parquet. | ResultMismatch | 3.5, from code. Spark 4.x falls back | |
-| An unpartitioned native write whose first task gets no rows, for example a 
write of an empty DataFrame, leaves a 0-byte file that is not valid Parquet. 
Reading the table directory as plain Parquet can then fail with `is not a 
Parquet file (length is too low: 0)`. With statistics on, the file stays on 
disk until `VACUUM`. With `spark.databricks.delta.stats.collect=false`, Delta 
commits it. The last two sentences are from code. | ResultMismatch | 3.5 and 
4.x, seen on 4.1 | |
+| An unpartitioned write with a positive `maxRecordsPerFile` uses Delta's 
writer to enforce the file limit. Partitioned native writes split batches at 
file boundaries. | Fallback | 3.5 and 4.x, batch and streaming | |
+| An unpartitioned native write whose first task gets no rows, for example a 
write of an empty DataFrame, leaves a 0-byte file that is not valid Parquet. 
Reading the table directory as plain Parquet can then fail with `is not a 
Parquet file (length is too low: 0)`. With statistics on, the file stays on 
disk until `VACUUM`. With `spark.databricks.delta.stats.collect=false`, Delta 
commits it. The last two sentences are from code. | ResultMismatch | 3.5 and 
4.x; seen on 3.5 and 4.1 | |

Review Comment:
   Nonblocking: this still lists Spark 3.5 as producing a zero-byte file for an 
empty unpartitioned task, even though this PR now writes a valid Spark Parquet 
footer. Please narrow the warning to the versions still affected. The NTZ 
data-column and explicit Parquet field-ID rows above also need updating: the 
new 3.5 guard falls back to Delta’s writer for both, not just on 4.x. The 
partition-only behavior is separate.



##########
backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/GlutenParquetFileFormat.scala:
##########
@@ -70,12 +72,34 @@ class GlutenParquetFileFormat
       }
 
       override def newInstance(
-          path: String,
+          filePath: String,
           dataSchema: StructType,
           context: TaskAttemptContext): OutputWriter = {
-        GlutenFormatFactory("parquet")
-          .createOutputWriter(path, dataSchema, context, nativeConf)
+        new OutputWriter {
+          private var nativeWriter: OutputWriter = _
+          private var hasInput = false
 
+          override def write(row: InternalRow): Unit = {
+            // Do not create an empty file during abort if native 
initialization fails.
+            hasInput = true
+            if (nativeWriter == null) {
+              nativeWriter = GlutenFormatFactory("parquet")
+                .createOutputWriter(filePath, dataSchema, context, nativeConf)
+            }
+            nativeWriter.write(row)
+          }
+
+          override def close(): Unit = {
+            if (nativeWriter != null) {
+              nativeWriter.close()
+            } else if (!hasInput) {
+              // Velox leaves a zero-byte file when no rows arrive. Spark 
writes the empty footer.
+              emptyWriterFactory.newInstance(filePath, dataSchema, 
context).close()

Review Comment:
   This new empty-file path can leave one stream with two spellings for the 
same nested field. With `spark.sql.caseSensitive=false` and Delta stats off, I 
wrote `payload.CamelCase = 17` and then ran a second batch whose rows were all 
filtered out. The populated Velox file had `payload.camelcase`, while the empty 
Spark file created here had `payload.CamelCase`. Both were committed. Spark’s 
case-insensitive Parquet read with `mergeSchema=true` failed on those files 
with `COLUMN_ALREADY_EXISTS`; the same two batches through Delta’s writer 
merged successfully.
   
   Please make both writers preserve the declared spelling, or fall back for 
schemas where the writers would disagree. A nonempty batch followed by an empty 
one with a mixed-case nested field would cover this.



-- 
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]

Reply via email to