martin-g commented on code in PR #19341:
URL: https://github.com/apache/datafusion/pull/19341#discussion_r2626048002
##########
datafusion/functions/src/datetime/date_bin.rs:
##########
@@ -481,17 +656,82 @@ fn date_bin_impl(
origin, stride, stride_fn, array, tz_opt,
)?
}
+ Time32(Millisecond) => {
+ if !is_time {
+ return exec_err!(
+ "DATE_BIN with Time32 source requires Time32
origin"
+ );
+ }
+ let array = array.as_primitive::<Time32MillisecondType>();
+ let apply_stride_fn = move |x: i32| {
+ let binned_nanos =
+ stride_fn(stride, x as i64 * NANOS_PER_MILLI,
origin);
+ let nanos = binned_nanos % (NANOSECONDS_IN_DAY);
+ (nanos / NANOS_PER_MILLI) as i32
+ };
+ let array: PrimitiveArray<Time32MillisecondType> =
+ array.unary(apply_stride_fn);
+ ColumnarValue::Array(Arc::new(array))
+ }
+ Time32(Second) => {
+ if !is_time {
+ return exec_err!(
+ "DATE_BIN with Time32 source requires Time32
origin"
+ );
+ }
+ let array = array.as_primitive::<Time32SecondType>();
+ let apply_stride_fn = move |x: i32| {
+ let binned_nanos =
+ stride_fn(stride, x as i64 * NANOS_PER_SEC,
origin);
+ let nanos = binned_nanos % (NANOSECONDS_IN_DAY);
+ (nanos / NANOS_PER_SEC) as i32
+ };
+ let array: PrimitiveArray<Time32SecondType> =
+ array.unary(apply_stride_fn);
+ ColumnarValue::Array(Arc::new(array))
+ }
+ Time64(Microsecond) => {
+ if !is_time {
+ return exec_err!(
+ "DATE_BIN with Time64 source requires Time64
origin"
+ );
+ }
+ let array = array.as_primitive::<Time64MicrosecondType>();
+ let apply_stride_fn = move |x: i64| {
+ let binned_nanos = stride_fn(stride, x, origin);
Review Comment:
```suggestion
let binned_nanos = stride_fn(stride, x *
NANOS_PER_MICRO, origin);
```
##########
datafusion/functions/src/datetime/date_bin.rs:
##########
Review Comment:
Maybe add a new example for `time` too ? Currently there are two examples
for timestamps
--
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]