Jefffrey commented on code in PR #19341:
URL: https://github.com/apache/datafusion/pull/19341#discussion_r2635645465


##########
datafusion/functions/src/datetime/date_bin.rs:
##########
@@ -193,11 +245,17 @@ impl ScalarUDFImpl for DateBinFunc {
     ) -> Result<ColumnarValue> {
         let args = &args.args;
         if args.len() == 2 {
-            // Default to unix EPOCH
-            let origin = 
ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(
-                Some(0),
-                Some("+00:00".into()),
-            ));
+            let origin = if matches!(args[1].data_type(), Time32(_)) {
+                ColumnarValue::Scalar(ScalarValue::Time32Second(Some(0)))
+            } else if matches!(args[1].data_type(), Time64(_)) {
+                ColumnarValue::Scalar(ScalarValue::Time64Nanosecond(Some(0)))

Review Comment:
   It seems odd that the signature requires origin (if provided) & expression 
to have the same time granularity, but if origin is omitted we provide 
granularity of only second or nanosecond; so we could have expression of 
time64(microseconds) with origin of time64(nanoseconds)?



##########
datafusion/functions/src/datetime/date_bin.rs:
##########
@@ -176,13 +229,12 @@ impl ScalarUDFImpl for DateBinFunc {
 
     fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
         match &arg_types[1] {
-            Timestamp(Nanosecond, None) | Utf8 | Null => 
Ok(Timestamp(Nanosecond, None)),
-            Timestamp(Nanosecond, tz_opt) => Ok(Timestamp(Nanosecond, 
tz_opt.clone())),
-            Timestamp(Microsecond, tz_opt) => Ok(Timestamp(Microsecond, 
tz_opt.clone())),
-            Timestamp(Millisecond, tz_opt) => Ok(Timestamp(Millisecond, 
tz_opt.clone())),
-            Timestamp(Second, tz_opt) => Ok(Timestamp(Second, tz_opt.clone())),
+            Utf8 | LargeUtf8 | Utf8View | Null => Ok(Timestamp(Nanosecond, 
None)),

Review Comment:
   ```suggestion
   ```
   
   Signature doesn't allow string arguments (or null for that matter)



##########
datafusion/functions/src/datetime/date_bin.rs:
##########
@@ -481,17 +667,82 @@ fn date_bin_impl(
                         origin, stride, stride_fn, array, tz_opt,
                     )?
                 }
+                Time32(Millisecond) => {
+                    if !is_time {

Review Comment:
   Is it possible to provide a non-time origin when the expression is time?



##########
datafusion/functions/src/datetime/date_bin.rs:
##########
@@ -146,7 +162,44 @@ impl DateBinFunc {
                     DataType::Interval(DayTime),
                     Timestamp(array_type, Some(TIMEZONE_WILDCARD.into())),
                 ]),
-            ]
+            ];
+
+            match array_type {
+                Second | Millisecond => {
+                    v.append(&mut vec![
+                        Exact(vec![
+                            DataType::Interval(MonthDayNano),
+                            Time32(array_type),
+                            Time32(array_type),

Review Comment:
   Could you explain why for time we require the expression & origin arguments 
to have the same granularity in terms of time units, whereas for timestamps 
above we seem to always have origin as Nanoseconds regardless of the expression 
granularity?



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