-
Notifications
You must be signed in to change notification settings - Fork 633
feat: derive monotonicity for date_truc with timezone when unit larger than day #20097
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
base: main
Are you sure you want to change the base?
Conversation
src/frontend/planner_test/tests/testdata/input/temporal_filter.yaml
Outdated
Show resolved
Hide resolved
let date_unit = func_call.inputs()[0] | ||
.as_literal() | ||
.and_then(|literal| literal.get_data().as_ref()) | ||
.map(|tz| tz.as_utf8().as_ref()); | ||
if time_zone_is_without_dst(time_zone) | ||
|| date_unit_larger_than_day(date_unit) | ||
{ |
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.
Can you please add an example to demonstrate the correctness?
What I can think of is like in a timezone with DST, MM-dd 23:50:00
+ interval 12 minutes
may be MM-dd 23:02:00
, while the date_trunc('day', ...)
result be MM-dd 00:12:00
versus MM-dd (00:00:00)
. Seems this will break the correctness. Am I understanding it wrong?
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 has all fields that are less significant than the selected one set to zero (or one, for day and month).
https://arc.net/l/quote/wfxyyukb
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 has all fields that are less significant than the selected one set to zero (or one, for day and month).
Yes I know that.
I just got it. In my previous comment, I mixed F(X + C)
with F(X) + C
. I think what we need to ensure here is that, if X2 > X1
, F(X2) > F(X1)
, and vice versa. We don't need to compare F(X + C)
with F(X) + C
.
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.
related: #13201
In short:
- PostgreSQL does treat units >= day and units < day differently (
redotz
boolean flag) - Counter-intuitively, it is possible that
date_trunc('day', x) > x
and the return value hashour != 0
There may be more tricky cases to think about carefully.
I think what we need to ensure here is that, if X2 > X1, F(X2) > F(X1), and vice versa.
- We only have
X2 > X1 implies F(X2) >= F(X1)
with the equal sign - Do you mean
F(X2) > F(X1) implies X2 > X1
by vice versa?
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.
- We only have
X2 > X1 implies F(X2) >= F(X1)
with the equal sign- Do you mean
F(X2) > F(X1) implies X2 > X1
by vice versa?
Yes. Thank for the equal sign
though. To be clear, I think it should be:
X2 >= X1
→F(X2) >= F(X1)
F(X2) >= F(X1)
→X2 >= X1
X2 <= X1
→F(X2) <= F(X1)
F(X2) <= F(X1)
→X2 <= X1
Only with the four all satisfied, we can say F
maintains the monotonicity.
const DAY: &str = "day"; | ||
const WEEK: &str = "week"; | ||
const MONTH: &str = "month"; | ||
const QUARTER: &str = "quarter"; | ||
const YEAR: &str = "year"; | ||
const DECADE: &str = "decade"; | ||
const CENTURY: &str = "century"; | ||
const MILLENNIUM: &str = "millennium"; | ||
date_unit.map_or(false, |date_unit| { | ||
matches!( | ||
date_unit.to_ascii_lowercase().as_str(), | ||
DAY | WEEK | MONTH | QUARTER | YEAR | DECADE | CENTURY | MILLENNIUM | ||
) | ||
}) |
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.
what's the point of the const
here
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.
In case SQL is standardized to use a language other than English in the future?
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.
just maintain it same as the expression's implementation
risingwave/src/expr/impl/src/scalar/date_trunc.rs
Lines 20 to 33 in c06b0c6
// TODO(xiangjinwu): parse into an enum | |
const MICROSECONDS: &str = "microseconds"; | |
const MILLISECONDS: &str = "milliseconds"; | |
const SECOND: &str = "second"; | |
const MINUTE: &str = "minute"; | |
const HOUR: &str = "hour"; | |
const DAY: &str = "day"; | |
const WEEK: &str = "week"; | |
const MONTH: &str = "month"; | |
const QUARTER: &str = "quarter"; | |
const YEAR: &str = "year"; | |
const DECADE: &str = "decade"; | |
const CENTURY: &str = "century"; | |
const MILLENNIUM: &str = "millennium"; |
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 mean why not use those existing definition?
It doesn't make sense to
- Define const repeatedly in multiple places
- Define const in-place just before its usage site
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.
This modification is a bit troublesome; we have to expose these const from a very deep level within expr... Since we might never modify it, I would rather make a copy.
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.
You could move these const from the deep mod into a upper layer, and import it in the original place. That should be easy to do.
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 too lazy....
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.
Your brain will become rusty!
This PR has been open for 60 days with no activity. If it's blocked by code review, feel free to ping a reviewer or ask someone else to review it. If you think it is still relevant today, and have time to work on it in the near future, you can comment to update the status, or just manually remove the You can also confidently close this PR to keep our backlog clean. (If no further action taken, the PR will be automatically closed after 7 days. Sorry! 🙏) |
…r than day
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
Checklist
Documentation
Release note