You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Weijun-H (via GitHub)" <gi...@apache.org> on 2023/06/15 17:59:45 UTC

[GitHub] [arrow-datafusion] Weijun-H commented on a diff in pull request #6654: fix: 'datatrunc' return inconsistent type

Weijun-H commented on code in PR #6654:
URL: https://github.com/apache/arrow-datafusion/pull/6654#discussion_r1231370472


##########
datafusion/physical-expr/src/datetime_expressions.rs:
##########
@@ -282,54 +341,64 @@ pub fn date_trunc(args: &[ColumnarValue]) -> Result<ColumnarValue> {
 
     Ok(match array {
         ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(v, tz_opt)) => {
-            let nano = (f)(*v)?;
-            match granularity.as_str() {
-                "minute" => {
-                    // trunc to minute
-                    let second = ScalarValue::TimestampNanosecond(
-                        Some(nano.unwrap() / 1_000_000_000 * 1_000_000_000),
-                        tz_opt.clone(),
-                    );
-                    ColumnarValue::Scalar(second)
+            _date_trunc(TimeUnit::Nanosecond, v, granularity.as_str(), f, tz_opt)?
+        }
+        ColumnarValue::Scalar(ScalarValue::TimestampMicrosecond(v, tz_opt)) => {
+            _date_trunc(TimeUnit::Microsecond, v, granularity.as_str(), f, tz_opt)?
+        }
+        ColumnarValue::Scalar(ScalarValue::TimestampMillisecond(v, tz_opt)) => {
+            _date_trunc(TimeUnit::Millisecond, v, granularity.as_str(), f, tz_opt)?
+        }
+        ColumnarValue::Scalar(ScalarValue::TimestampSecond(v, tz_opt)) => {
+            _date_trunc(TimeUnit::Second, v, granularity.as_str(), f, tz_opt)?
+        }
+        ColumnarValue::Array(array) => {
+            let array_type = array.data_type();

Review Comment:
   I use `f` function pointer, which uses `granularity ` as parameter



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org