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

   ### What changes were proposed in this pull request?
   
   Support `EXTRACT(field FROM source)` and `date_part(field, source)` over the 
nanosecond-precision timestamp types `TIMESTAMP_NTZ(p)` / `TIMESTAMP_LTZ(p)`. 
Follow-up to SPARK-57315, which covered `hour()` / `minute()` / `second()` but 
not `EXTRACT` / `date_part` (they bypass the function builders via 
`DatePart.parseExtractField`).
   
   - **HOUR / MINUTE**: cast the nanosecond input down to the matching 
microsecond type via the existing `NanosTimestampCast.castToMicros` (lossless 
for integer fields).
   - **SECOND**: new `SecondWithFractionNanos` expression returning 
`DECIMAL(11, 9)` with the full nanosecond fraction, instead of truncating to 
the `DECIMAL(8, 6)` of `SecondWithFraction`. Backed by a new 
`DateTimeUtils.getSecondsWithFractionNanos`.
   
   Date-based fields (`YEAR`, `MONTH`, ...) are out of scope
   
   ### Why are the changes needed?
   
   `EXTRACT` / `date_part` are documented as equivalent to `hour()` / 
`minute()` / `second()`, but after SPARK-57315 they still fail analysis on 
nanosecond timestamps. Part of the nanosecond timestamp preview (SPARK-56822).
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, but only with the preview flag `spark.sql.timestampNanosTypes.enabled` 
set to `true`
   
   ```sql
   SELECT extract(HOUR FROM TIMESTAMP_NTZ '2018-02-14 12:58:59.123456789');
   -- 12 (previously: analysis error)
   SELECT extract(SECOND FROM TIMESTAMP_NTZ '2018-02-14 12:58:59.123456789');
   -- 59.123456789 (DECIMAL(11, 9))
   ```
   How was this patch tested?
   Tests in this PR.
   
   Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Fable 5)


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