MaxGekk opened a new pull request, #56320:
URL: https://github.com/apache/spark/pull/56320

   ### What changes were proposed in this pull request?
   This PR modifies `HiveResult` to support the nanosecond-precision timestamp 
types `TIMESTAMP_LTZ(p)` (`TimestampLTZNanosType`) and `TIMESTAMP_NTZ(p)` 
(`TimestampNTZNanosType`), `p` in [7, 9]. Two cases are added to 
`HiveResult.toHiveStringDefault`, mirroring the existing microsecond timestamp 
cases:
   
   - `(i: Instant, _: TimestampLTZNanosType)` -> rendered in the session time 
zone.
   - `(l: LocalDateTime, _: TimestampNTZNanosType)` -> rendered 
zone-independently.
   
   The external collected values are `Instant` (LTZ) and `LocalDateTime` (NTZ); 
they are converted to the physical `TimestampNanosVal` at the column precision 
and formatted with the nanosecond-aware `TimestampFormatter` (`formatNanos` / 
`formatWithoutTimeZoneNanos`, SPARK-57162), flooring sub-`p` digits and 
trimming trailing zeros. This is the same rendering used by casting these types 
to string (SPARK-57256), so Hive output stays consistent.
   
   ### Why are the changes needed?
   Before the change, formatting a nanosecond timestamp column through 
`HiveResult` (e.g. end-to-end SQL / golden-file tests, spark-sql CLI, Thrift 
server output) hits the catch-all match and fails with a `MatchError`, 
analogous to the `TimeType` issue fixed in SPARK-51517:
   
   ```
   scala.MatchError
   (2020-01-01T00:00:00.123456789Z, TimestampLTZNanosType(9)) (of class 
scala.Tuple2)
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   Yes. It fixes the error above. After the change, nanosecond timestamp values 
are rendered as proper strings in Hive results (only reachable when 
`spark.sql.timestampNanosTypes.enabled=true`).
   
   ### How was this patch tested?
   - New cases in `HiveResultSuite` covering `TIMESTAMP_LTZ(p)` / 
`TIMESTAMP_NTZ(p)` for `p` in [7, 9]: precision-driven fraction width, 
trailing-zero trimming, nanosWithinMicro 0 and 999, LTZ session-zone rendering 
vs. zone-independent NTZ, and nested (array/map/struct) values.
   - New golden-file end-to-end tests `timestamp-ltz-nanos.sql` and 
`timestamp-ntz-nanos.sql` (as SPARK-51517 added `time.sql`), disabled in 
`ThriftServerQueryTestSuite`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   Generated-by: Cursor 1.7.0


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