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

   ### What changes were proposed in this pull request?
   Change `DateTimeUtils.timeAddInterval` from throwing on out-of-range results 
to wrapping modulo 24 hours, per ANSI SQL standard (std L16582-16583). Also 
remove the now-dead `timeAddIntervalOverflowError` method and its unused 
IntervalUtils import.
   
   ### Why are the changes needed?
   ANSI SQL specifies that TIME arithmetic wraps modulo 24 hours (e.g., `TIME 
'23:00' + INTERVAL '2' HOUR = TIME '01:00'`). Spark's current implementation 
throws `DATETIME_OVERFLOW` when the result leaves `[00:00, 24:00)`, which is 
non-standard and prevents legitimate use cases like scheduling calculations 
that cross midnight. With modulo-24 semantics, TRY mode becomes a no-op since 
the operation never errors.
   
   ### Does this PR introduce _any_ user-facing change?
   Yes. `TIME + INTERVAL` and `TIME - INTERVAL` that cross midnight now wrap 
around instead of throwing an error. For example:
   - `TIME '23:00' + INTERVAL '2' HOUR` returns `TIME '01:00'` (previously 
threw `DATETIME_OVERFLOW`)
   - `TIME '01:00' - INTERVAL '3' HOUR` returns `TIME '22:00'` (previously 
threw `DATETIME_OVERFLOW`)
   
   
   ### How was this patch tested?
   - Updated `DateTimeUtilsSuite` ("add day-time interval to time") with 
wrap-around assertions
   - Added modulo-24 wrap cases to `TimeExpressionsSuite` ("Add ANSI day-time 
intervals to TIME")
   - Added golden SQL test cases in `time.sql` documenting wrap behavior for 
forward, backward, microsecond-precision, and full-day intervals
   
   ### Was this patch authored or co-authored using generative AI tooling?
   Co-authored using Claude Opus 4.6


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