-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: date_trunc support timezone #6818
Conversation
a38dee7
to
a8f7b75
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Weijun-H
I think this PR preserves the timezone part of date_trunc which is good. However, it doens't seem to actually change date_trunc to take the timezones into account during the calculation.
self.volatility(), | ||
), | ||
BuiltinScalarFunction::DateTrunc => { | ||
let time_zones = vec![ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @waitingkuo has some ideas about how to deal with timezones in function signatures.
It seems not quite right to have to list all timezones specially for date_trun
only -- shouldn't the timezone logic apply to any function that takes timezones ? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure there is a better way to provide the timezone here. And wait for @waitingkuo suggestion.
Also, it should be extended to other functions using timezone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW this issue also arises for decimal types, I suspect that the current pattern of explicitly listing the possible type signatures is going to require revisiting. We probably want to extend the pattern established in #6778 and allow functions to return a signature given a set of input types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timestamp(Microsecond, _) => Ok(Timestamp(Microsecond, None)), | ||
Timestamp(Millisecond, _) => Ok(Timestamp(Millisecond, None)), | ||
Timestamp(Second, _) => Ok(Timestamp(Second, None)), | ||
match &input_expr_types[1] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if any of the calculations actually have to change based on timezone (as wouldn't the end of theday
being truncated depend on the timezone)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it truncates before applying timezone offset, which is inconsistent with postgresql
❯ 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.
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)
self.volatility(), | ||
), | ||
BuiltinScalarFunction::DateTrunc => { | ||
let time_zones = vec![ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
select date_trunc('hour', timestamptz '2000-01-01T00:00:00'); | ||
---- | ||
2000-01-01T00:00:00+08:00 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should add a test case that truncate the day
Timestamp(Microsecond, _) => Ok(Timestamp(Microsecond, None)), | ||
Timestamp(Millisecond, _) => Ok(Timestamp(Millisecond, None)), | ||
Timestamp(Second, _) => Ok(Timestamp(Second, None)), | ||
match &input_expr_types[1] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it truncates before applying timezone offset, which is inconsistent with postgresql
❯ 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.
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)
a8f7b75
to
ee70381
Compare
ee70381
to
382d2f4
Compare
What is the current status of this PR? It seems to have gone stale |
Hi, @alamb. This pr can truncate the day and hour now. I am not sure there is a better way to mention the timezone.
|
Which issue does this PR close?
Closes #5976
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?