xudong963 commented on code in PR #27547:
URL: https://github.com/apache/datafusion/pull/27547#discussion_r4637308434


##########
datafusion/functions/src/datetime/date_trunc.rs:
##########
@@ -710,6 +721,16 @@ where
     1 + 3 * ((date.month() - 1) / 3)
 }
 
+/// The granularity `precision` always evaluates to, if that is known.
+fn constant_granularity(precision: &ExprProperties) -> Option<DatePart> {
+    let range = &precision.range;
+    if range.lower() != range.upper() {
+        return None;
+    }
+    let granularity = range.lower().try_as_str().flatten()?;

Review Comment:
   `precision` here is the SQL granularity argument, stored as a string-valued 
`ScalarValue`, rather than a `DatePart`. `try_as_str()` just borrows the 
existing string; it doesn't allocate or format it. We need its value because 
`'minute'` and `'hour'` have the same type but different ordering guarantees. 
We then parse it into `DatePart` and reuse the execution kernel's predicate. 



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