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

   ### What changes were proposed in this pull request?
   
   Extend `timestampadd(unit, quantity, timestamp)` to accept 
nanosecond-precision timestamp endpoints (`TIMESTAMP_NTZ(p)` / 
`TIMESTAMP_LTZ(p)`, p in [7, 9]).
   
   - Widen `TimestampAdd.inputTypes` to `TypeCollection(AnyTimestampType, 
AnyTimestampNanoType)` so a nanosecond argument is no longer implicitly cast to 
microseconds (which silently dropped the sub-microsecond fraction). The result 
keeps the input's nanosecond type.
   - For units of MICROSECOND or coarser, the addition runs on the microsecond 
grid (reusing the existing calendar/DST/overflow handling) and the 
sub-microsecond fraction is carried through unchanged.
   - Add a `NANOSECOND` unit (the token already exists for interval literals; 
it is added to the shared `datetimeUnit` grammar rule): the fraction absorbs 
the quantity and whole microseconds carry into `epochMicros`. Overflow surfaces 
as `DATETIME_OVERFLOW`. `NANOSECOND` is meaningful only for a 
nanosecond-precision timestamp; on a microsecond timestamp it is rejected as an 
invalid unit.
   
   ### Why are the changes needed?
   
   Part of the nanosecond-precision timestamp umbrella (SPARK-56822). Without 
this, `timestampadd` rejected nanosecond timestamp arguments by casting them to 
microseconds, silently losing the sub-microsecond digits.
   
   ### Does this PR introduce any user-facing change?
   
   Yes. `timestampadd` now accepts nanosecond-precision timestamps and 
preserves their sub-microsecond fraction, and supports a new `NANOSECOND` unit 
for nanosecond-precision inputs.
   
   ### How was this patch tested?
   
   New unit test in `DateExpressionsSuite` and golden file tests.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Co-Authored-by: Claude Opus 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