benbellick commented on code in PR #25498:
URL: https://github.com/apache/datafusion/pull/25498#discussion_r4054224294


##########
datafusion/functions/src/datetime/date_trunc.rs:
##########


Review Comment:
   worth seeing if there is a regression. Have you tried the 
`date_trunc_minute_1000` benchmark? 



##########
datafusion/functions/src/datetime/date_trunc.rs:
##########
@@ -796,13 +772,8 @@ fn general_date_trunc_array_fine_granularity<T: 
ArrowTimestampType>(
             })
             .collect();
         let array: PrimitiveArray<T> = if maybe_underflow {
-            array.try_unary(|value| {
-                value.checked_sub(value.rem_euclid(unit)).ok_or_else(|| {
-                    exec_datafusion_err!(
-                        "Timestamp {value} out of range after truncating to 
{granularity}"
-                    )
-                })
-            })?
+            array
+                .try_unary(|value| date_trunc_fine_granularity(tu, value, 
granularity))?

Review Comment:
   IIUC we above do some work to turn `tu` into `unit` via 
`fine_granularity_unit` and then do the same computation again inside of this 
function `date_trunc_fine_granularity`. That feels like:
   1. duplicated work, and 
   2. a potential source of confusion while reading the code
   
   I think it is worth coming up with a simplification. What you think? 



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