-
Notifications
You must be signed in to change notification settings - Fork 613
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
feat(expr): AT TIME ZONE
to convert between timestamp
and timestamptz
#5968
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5968 +/- ##
==========================================
+ Coverage 74.57% 74.68% +0.10%
==========================================
Files 924 928 +4
Lines 147420 147871 +451
==========================================
+ Hits 109945 110438 +493
+ Misses 37475 37433 -42
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
src/expr/src/vector_op/timestampz.rs
Outdated
|
||
#[inline(always)] | ||
pub fn timestamp_at_time_zone(input: NaiveDateTimeWrapper, time_zone: &str) -> Result<i64> { | ||
let time_zone = parse_time_zone(time_zone)?; |
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.
Seems we need to parse the timezone every row, not sure whether it can be heavy. 🤔
Some possible optimizations:
- If the second expr is a
Constant
, use another optimized implementation like perf(expr): optimize to_char function with constant template #5130. - Use a thread-local memoization / LRU cache.
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.
The parsing is a lookup of a static and perfect hash table (crate phf
), where hash is done in a case-insensitive manner. So memoization / cache has no advantage here.
It is still true that most cases this is a constant, though.
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.
Cool. Then there should be no problem.
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.
Updated the function name to lookup_time_zone
.
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.
LGTM!
I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.
What's changed and what's your intention?
Casting between
timestamp
andtimestamp with time zone
requires an implicit session TimeZone, which is not supported yet (#5826).The
AT TIME ZONE
operator is another way to bridge these two types, via a TimeZone parameter explicitly specified in the query. This PR implements this expr.AT TIME ZONE
apache/datafusion-sqlparser-rs#539chrono-tz
withcast-insensitive
feature.Checklist
./risedev check
(or alias,./risedev c
)Documentation
Types of user-facing changes
Release note
timestamp_value AT TIME ZONE 'zone' -> timestamp_with_time_zone_value
timestamp_with_time_zone_value AT TIME ZONE 'zone' -> timestamp_value
Refer to a related PR or issue link (optional)