sam-1112 opened a new pull request, #7753: URL: https://github.com/apache/datafusion-comet/pull/7753
## Which issue does this PR close? Closes #7048. ## Rationale for this change The native Parquet writer ignored `spark.sql.parquet.outputTimestampType` and `spark.sql.parquet.writeLegacyFormat`, and wrote `ARROW:schema` instead of Spark's `org.apache.spark.sql.parquet.row.metadata`. A reader of the file therefore saw different physical types, lost field metadata such as comments, and could infer `TIMESTAMP_NTZ` as `TIMESTAMP` when `spark.sql.parquet.inferTimestampNTZ.enabled=false`. This PR does not add an INT96 writer. [arrow-rs#12263](https://github.com/apache/arrow-rs/pull/12263) records why a new writer should not emit INT96: the Parquet spec says new writers must not write it, an Arrow timestamp already fits an INT64 `TIMESTAMP` of the same unit, INT96 is 12 bytes with no `DELTA_BINARY_PACKED` or `BYTE_STREAM_SPLIT`, and readers that do not know `INT96_TIMESTAMP_ORDER` cannot prune on its min/max statistics. Spark reads `TIMESTAMP(MICROS)` with `isAdjustedToUTC=true` as `TimestampType`, which arrow-rs already writes for `Timestamp(Microsecond, Some(tz))`. The default `INT96` setting therefore falls back to Spark, including for nested `TimestampType` columns. `TIMESTAMP_NTZ` is not an INT96 timestamp and stays on the native path. ## What changes are included in this PR? - `TIMESTAMP_MILLIS` floors `TimestampType` microseconds to milliseconds, including values before the epoch and timestamps nested in structs, arrays, and maps. `TIMESTAMP_NTZ` stays in microseconds. The conversion reserves the output buffer with the task memory pool before allocating it. - A plan whose output contains a `TimestampType` falls back when `outputTimestampType` is `INT96`. `writeLegacyFormat=true` falls back for the whole write. `int96RebaseModeInWrite=LEGACY` is a fallback reason only when the output type is actually `INT96`. - Native files store the Catalyst schema JSON in `org.apache.spark.sql.parquet.row.metadata`. On Spark 4 this is `WriteFiles` `dataColumns`, so partition columns stay out of the footer. - `WriterProperties::set_coerce_types(true)` gives list and map fields the Parquet specification names. - `ParquetWriter` carries `output_timestamp_type` and `spark_schema_json`. An empty timestamp type, as in an older plan, still means `TIMESTAMP_MICROS`. ## How are these changes tested? - `CometParquetWriterSuite` compares native `TIMESTAMP_MICROS` and `TIMESTAMP_MILLIS` files with Spark, including nested columns, column comments, the schema footer, and `CORRECTED`, `EXCEPTION`, and `LEGACY` reads. `TIMESTAMP_NTZ` stays native under every output timestamp setting. `INT96` and `writeLegacyFormat=true` assert a Spark fallback and the same Parquet schema Spark writes. - Rust tests cover floor division through zero, untouched sibling buffers, sliced lists, parent nulls, and refusal of the millisecond conversion when the memory pool cannot hold the buffer. - `./mvnw test -Dtest=none -Dsuites="org.apache.comet.parquet.CometParquetWriterSuite"` passed, 98 tests, on Spark 4.1 / Scala 2.13. -- 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]
