drin commented on code in PR #18648:
URL: https://github.com/apache/datafusion/pull/18648#discussion_r2874331504
##########
datafusion/functions/src/datetime/date_trunc.rs:
##########
@@ -502,6 +650,125 @@ fn truncate_time_secs(value: i32, granularity:
DateTruncGranularity) -> i32 {
}
}
+/// Increment time in nanoseconds by the specified granularity
+fn increment_time_nanos(value: i64, granularity: DateTruncGranularity) -> i64 {
+ match granularity {
+ DateTruncGranularity::Hour => value + NANOS_PER_HOUR,
+ DateTruncGranularity::Minute => value + NANOS_PER_MINUTE,
+ DateTruncGranularity::Second => value + NANOS_PER_SECOND,
+ DateTruncGranularity::Millisecond => value + NANOS_PER_MILLISECOND,
+ DateTruncGranularity::Microsecond => value + NANOS_PER_MICROSECOND,
+ // Other granularities are not valid for time - should be caught
earlier
+ _ => value,
+ }
+}
+
+/// Increment time in microseconds by the specified granularity
+fn increment_time_micros(value: i64, granularity: DateTruncGranularity) -> i64
{
+ match granularity {
+ DateTruncGranularity::Hour => value + MICROS_PER_HOUR,
+ DateTruncGranularity::Minute => value + MICROS_PER_MINUTE,
+ DateTruncGranularity::Second => value + MICROS_PER_SECOND,
+ DateTruncGranularity::Millisecond => value + MICROS_PER_MILLISECOND,
+ DateTruncGranularity::Microsecond => value + 1,
+ // Other granularities are not valid for time - should be caught
earlier
+ _ => value,
+ }
+}
+
+/// Increment time in milliseconds by the specified granularity
+fn increment_time_millis(value: i32, granularity: DateTruncGranularity) -> i32
{
+ match granularity {
+ DateTruncGranularity::Hour => value + MILLIS_PER_HOUR,
+ DateTruncGranularity::Minute => value + MILLIS_PER_MINUTE,
+ DateTruncGranularity::Second => value + MILLIS_PER_SECOND,
+ DateTruncGranularity::Millisecond => value + 1,
Review Comment:
What I do instead, is I return the same value (no increment) and then I
check if the increment call was a no-op (lower == upper), and if so, I print an
appropriate error (e.g. "Millisecond too granular for time in Seconds").
--
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]