kumarUjjawal commented on code in PR #22315:
URL: https://github.com/apache/datafusion/pull/22315#discussion_r3329719174


##########
datafusion/functions/src/datetime/date_bin.rs:
##########
@@ -710,20 +765,26 @@ fn date_bin_impl(
                 T: ArrowTimestampType,
             {
                 let array = as_primitive_array::<T>(array)?;
-                let scale = match T::UNIT {
-                    Nanosecond => 1,
-                    Microsecond => NANOS_PER_MICRO,
-                    Millisecond => NANOS_PER_MILLI,
-                    Second => NANOSECONDS,
-                };
-
-                let result: PrimitiveArray<T> = array.try_unary(|val| {
-                    stride_fn(stride, val * scale, origin)
-                        .map(|binned| binned / scale)
-                        .map_err(|e| {
-                            
arrow::error::ArrowError::ComputeError(e.to_string())
-                        })
-                })?;
+                let scale = timestamp_scale::<T>();
+
+                let values = array
+                    .iter()
+                    .map(|val| match val {
+                        Some(val) => {
+                            let scaled = val.checked_mul(scale).ok_or_else(|| {
+                                DataFusionError::Execution(
+                                    timestamp_scale_overflow_message(val),
+                                )
+                            })?;
+                            Ok(stride_fn(stride, scaled, origin)
+                                .ok()

Review Comment:
   Thanks @Jefffrey I will wait for this to get merged as I am doing some 
cleanup too.



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