alamb commented on code in PR #20221:
URL: https://github.com/apache/datafusion/pull/20221#discussion_r2805677907


##########
datafusion/functions/src/datetime/date_bin.rs:
##########
@@ -715,14 +774,20 @@ fn date_bin_impl(
                         );
                     }
                     let array = array.as_primitive::<Time64MicrosecondType>();
-                    let apply_stride_fn = move |x: i64| {
-                        let binned_nanos = stride_fn(stride, x * 
NANOS_PER_MICRO, origin);
-                        let nanos = binned_nanos % (NANOSECONDS_IN_DAY);
-                        nanos / NANOS_PER_MICRO
-                    };
-                    let array: PrimitiveArray<Time64MicrosecondType> =
-                        array.unary(apply_stride_fn);
-                    ColumnarValue::Array(Arc::new(array))
+                    let result: PrimitiveArray<Time64MicrosecondType> = array

Review Comment:
   How about using `try_unary`? 
https://docs.rs/arrow/latest/arrow/array/struct.PrimitiveArray.html#method.try_unary
   
   I think that will result in a smaller diff and be faster as well
   
   The same comment applies to the other methods in this function



##########
datafusion/functions/src/datetime/date_bin.rs:
##########
@@ -295,7 +295,7 @@ impl ScalarUDFImpl for DateBinFunc {
 const NANOS_PER_MICRO: i64 = 1_000;
 const NANOS_PER_MILLI: i64 = 1_000_000;
 const NANOS_PER_SEC: i64 = NANOSECONDS;
-
+type BinFunction = fn(i64, i64, i64) -> Result<i64>;

Review Comment:
   Can you please add comments here aout what `BinFunction` is and what it 
represents (e.g. what are the aguments and what does it return)?



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