ranflarion commented on PR #12263:
URL: https://github.com/apache/arrow-rs/pull/12263#issuecomment-7073169159

   > Thanks [@ranflarion](https://github.com/ranflarion). Following up on my 
comment above, I'm not convinced arrow-rs should add an INT96 writer, and I'd 
like us to settle that question before the code goes further.
   > 
   > The spec says new writers should not write INT96 
([parquet.thrift](https://github.com/apache/parquet-format/blob/5cc18cae643835b19f869d3cffb085cd3c04eb15/src/main/thrift/parquet.thrift#L36)).
 For Arrow input I can't find a case where INT96 is the better choice:
   > 
   > * It adds no range or resolution. An Arrow millisecond, microsecond, or 
nanosecond value is an `i64` count of its unit, so it fits INT64 `TIMESTAMP` of 
that unit exactly. INT96's 32-bit Julian day is narrower than Arrow seconds and 
milliseconds, which is why this PR needs an out-of-range error at all. For a 
range wider than INT64 nanoseconds, the spec now allows `TIMESTAMP` on 
`FIXED_LEN_BYTE_ARRAY(12)` 
([LogicalTypes.md](https://github.com/apache/parquet-format/blob/5cc18cae643835b19f869d3cffb085cd3c04eb15/LogicalTypes.md?plain=1#L372-L374),
 [GH-600: Allow TimestampType to annotate FLBA(12) 
parquet-format#601](https://github.com/apache/parquet-format/pull/601)).
   > * It's larger. INT96 values take 12 bytes instead of 8, and the spec 
allows neither `DELTA_BINARY_PACKED` nor `BYTE_STREAM_SPLIT` for INT96 
([Encodings.md](https://github.com/apache/parquet-format/blob/5cc18cae643835b19f869d3cffb085cd3c04eb15/Encodings.md?plain=1#L202),
 
[Encodings.md](https://github.com/apache/parquet-format/blob/5cc18cae643835b19f869d3cffb085cd3c04eb15/Encodings.md?plain=1#L369)).
 Here are file sizes for 1M `Timestamp(Microsecond, "UTC")` values written with 
this PR:
   >   
   >   
   >   
   >   Input
   >   Compression
   >   INT64, defaults
   >   INT96, defaults
   >   INT64, `DELTA_BINARY_PACKED`
   >   
   >   
   >   
   >   
   >   Sorted, 1 s apart plus random microseconds
   >   none
   >   8.27 MB
   >   12.18 MB
   >   2.66 MB
   >   
   >   
   >   Sorted, 1 s apart plus random microseconds
   >   zstd
   >   4.08 MB
   >   4.54 MB
   >   2.66 MB
   >   
   >   
   >   Random over 50 years
   >   none
   >   8.27 MB
   >   12.18 MB
   >   6.55 MB
   >   
   >   
   >   Random over 50 years
   >   zstd
   >   7.56 MB
   >   9.82 MB
   >   6.55 MB
   > * Its statistics are less useful. Readers that don't know the 
[`INT96_TIMESTAMP_ORDER`](https://github.com/apache/parquet-format/blob/5cc18cae643835b19f869d3cffb085cd3c04eb15/src/main/thrift/parquet.thrift#L1158-L1168)
 column order have to ignore min and max for the column 
([parquet.thrift](https://github.com/apache/parquet-format/blob/5cc18cae643835b19f869d3cffb085cd3c04eb15/src/main/thrift/parquet.thrift#L1113-L1114)),
 so they can't prune on it.
   > 
   > For Spark, INT96 isn't needed. Spark reads INT64 `TIMESTAMP(MICROS)` with 
[`isAdjustedToUTC`](https://github.com/apache/parquet-format/blob/5cc18cae643835b19f869d3cffb085cd3c04eb15/LogicalTypes.md?plain=1#L375-L379)
 set to true as `TimestampType` 
([ParquetSchemaConverter.scala](https://github.com/apache/spark/blob/5ab5ec5fc59d2d4d900f6f87c0e03e92273e2420/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetSchemaConverter.scala#L328-L333)).
 Spark's own source calls that type recommended and keeps INT96 as the default 
only for backward compatibility 
([ParquetSchemaConverter.scala](https://github.com/apache/spark/blob/5ab5ec5fc59d2d4d900f6f87c0e03e92273e2420/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetSchemaConverter.scala#L722-L724)).
 arrow-rs already writes that type for `Timestamp(Microsecond, Some(tz))` 
([schema/mod.rs](https://github.com/apache/arrow-rs/blob/4f1ed42f7a1fb76d090ec1351cfdb6e904f59f0b/parquet/src
 /arrow/schema/mod.rs#L754-L758)). Which reader do you need to support that 
can't read it? If there is one, I think the case for an INT96 writer belongs on 
the dev mailing list.
   > 
   > Spark 3.x may also refuse to read what this writes. A file without 
`org.apache.spark.version` in its footer gets its INT96 calendar rebase mode 
from `spark.sql.parquet.int96RebaseModeInRead` 
([DataSourceUtils.scala](https://github.com/apache/spark/blob/5ab5ec5fc59d2d4d900f6f87c0e03e92273e2420/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceUtils.scala#L209-L220)).
 In Spark 3.5 that defaults to `EXCEPTION`, which fails the read "if it sees 
ancient timestamps that are ambiguous between the two calendars" 
([SQLConf.scala](https://github.com/apache/spark/blob/7c14a3c28b141cc97a330c4d0f5d2a6da7267f85/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala#L4027-L4041)).
 Spark `master` defaults to `CORRECTED` 
([SQLConf.scala](https://github.com/apache/spark/blob/5ab5ec5fc59d2d4d900f6f87c0e03e92273e2420/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala#L8078-L8089)).
 So whether Spark can read old timestamps from this wr
 iter depends on its version and settings.
   > 
   > There's also the question of who maintains this. Since March 2025 arrow-rs 
has merged eight INT96 changes for reading and statistics alone: 
[#7285](https://github.com/apache/arrow-rs/pull/7285), 
[#7367](https://github.com/apache/arrow-rs/pull/7367), 
[#7687](https://github.com/apache/arrow-rs/pull/7687), 
[#7975](https://github.com/apache/arrow-rs/pull/7975), 
[#8034](https://github.com/apache/arrow-rs/pull/8034), 
[#8603](https://github.com/apache/arrow-rs/pull/8603), 
[#10106](https://github.com/apache/arrow-rs/pull/10106), and 
[#11348](https://github.com/apache/arrow-rs/pull/11348). A writer is new 
surface that someone has to keep correct as the spec and other readers change.
   
   @mbutrovich i understand your sentiment. the reason is spark compatibility 
but i can see how that might not be convincing enough


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

Reply via email to