waitingkuo commented on code in PR #6818:
URL: https://github.com/apache/arrow-datafusion/pull/6818#discussion_r1252516097
##########
datafusion/expr/src/built_in_function.rs:
##########
@@ -895,15 +894,37 @@ impl BuiltinScalarFunction {
],
self.volatility(),
),
- BuiltinScalarFunction::DateTrunc => Signature::one_of(
- vec![
- Exact(vec![Utf8, Timestamp(Nanosecond, None)]),
- Exact(vec![Utf8, Timestamp(Microsecond, None)]),
- Exact(vec![Utf8, Timestamp(Millisecond, None)]),
- Exact(vec![Utf8, Timestamp(Second, None)]),
- ],
- self.volatility(),
- ),
+ BuiltinScalarFunction::DateTrunc => {
+ let time_zones = vec![
Review Comment:
Hi @alamb @Weijun-H @tustvold . i don't have the solution. actually i have
some other pr blocked by this for now.
i wonder whether force it to be coerced to UTC ```Timestamp(someunit,
Some("+00:00".into())``` makes sense before we have better solution for what
@tustvold suggested
##########
datafusion/expr/src/built_in_function.rs:
##########
@@ -557,13 +557,12 @@ impl BuiltinScalarFunction {
BuiltinScalarFunction::ConcatWithSeparator => Ok(Utf8),
BuiltinScalarFunction::DatePart => Ok(Float64),
BuiltinScalarFunction::DateBin | BuiltinScalarFunction::DateTrunc
=> {
- match input_expr_types[1] {
- Timestamp(Nanosecond, _) | Utf8 | Null => {
- Ok(Timestamp(Nanosecond, None))
- }
- Timestamp(Microsecond, _) => Ok(Timestamp(Microsecond,
None)),
- Timestamp(Millisecond, _) => Ok(Timestamp(Millisecond,
None)),
- Timestamp(Second, _) => Ok(Timestamp(Second, None)),
+ match &input_expr_types[1] {
Review Comment:
https://github.com/apache/arrow-datafusion/blob/02a470f6061cce8ee8e57f7af8a6a0e0ddc1571b/datafusion/physical-expr/src/datetime_expressions.rs#L343-L347
it truncates before applying timezone offset, which is inconsistent with
postgresql
```bash
❯ set timezone to '+08:00';
0 rows in set. Query took 0.026 seconds.
❯ select timestamptz '2000-01-01T00:00:00';
+-----------------------------+
| Utf8("2000-01-01T00:00:00") |
+-----------------------------+
| 2000-01-01T00:00:00+08:00 |
+-----------------------------+
1 row in set. Query took 0.002 seconds.
❯ select date_trunc('day', timestamptz '2000-01-01T00:00:00');
+-----------------------------------------------------+
| date_trunc(Utf8("day"),Utf8("2000-01-01T00:00:00")) |
+-----------------------------------------------------+
| 1999-12-31T00:00:00 |
+-----------------------------------------------------+
1 row in set. Query took 0.032 seconds.
```
```bash
willy=# select timestamptz '2000-01-01T00:00:00';
timestamptz
------------------------
2000-01-01 00:00:00+08
(1 row)
willy=# select date_trunc('day', timestamptz '2000-01-01T00:00:00');
date_trunc
------------------------
2000-01-01 00:00:00+08
(1 row)
```
##########
datafusion/core/tests/sqllogictests/test_files/timestamps.slt:
##########
@@ -1281,7 +1281,14 @@ SELECT
----
true false true true
+# date_trunc with timestamptz
+statement ok
+set timezone to '+08:00';
+query P
+select date_trunc('hour', timestamptz '2000-01-01T00:00:00');
+----
+2000-01-01T00:00:00+08:00
Review Comment:
i think we should a test case that truncate the day
--
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]