vismaytiwari commented on code in PR #23279:
URL: https://github.com/apache/datafusion/pull/23279#discussion_r3600340641
##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -271,6 +271,183 @@ where
}
}
+/// Returns true for `time + interval` or `interval + time`.
+fn is_time_plus_interval(lhs: &DataType, rhs: &DataType) -> bool {
+ matches!(
+ (lhs, rhs),
+ (
+ DataType::Time32(_) | DataType::Time64(_),
+ DataType::Interval(_)
+ ) | (
+ DataType::Interval(_),
+ DataType::Time32(_) | DataType::Time64(_)
+ )
+ )
+}
+
+/// Returns true for `time - interval`.
+fn is_time_minus_interval(lhs: &DataType, rhs: &DataType) -> bool {
+ matches!(
+ (lhs, rhs),
+ (
+ DataType::Time32(_) | DataType::Time64(_),
+ DataType::Interval(_)
+ )
+ )
+}
+
+/// Evaluates `time + interval`, `interval + time`, or `time - interval`,
returning a
+/// `time` wrapped within the 24-hour clock to match PostgreSQL and DuckDB
(e.g.
+/// `time '23:30' + interval '2 hours'` is `01:30:00`). arrow's arithmetic
kernels do
+/// not implement time-of-day arithmetic, so it is handled here.
+///
+/// The result keeps the input time's unit; the interval (normalized to
`MonthDayNano`
+/// by the coercion layer) is applied at that resolution, mirroring `timestamp
+ interval`.
+/// Only the sub-day portion of the interval affects a time-of-day -- whole
months and
+/// days are ignored, matching PostgreSQL -- and any interval precision finer
than the
+/// time's unit is truncated (so `time(s) + interval '1 nanosecond'` is a
no-op).
Review Comment:
my truncation-toward-zero disagreed with timestamp here. Switched to
flooring the interval at ns precision (`div_euclid`, with the sign applied
before the floor), so `time(s) - interval '1 nanosecond'` now rolls back a full
second to `09:59:59`, matching your `timestamp(s)` example. Added an slt case
for it. a968da41
--
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]