-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,6 +186,23 @@ impl MonotonicityAnalyzer { | |
tz_is_utc // conservative | ||
} | ||
|
||
fn date_unit_larger_than_day(date_unit: Option<&str>) -> bool { | ||
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 | ||
) | ||
}) | ||
} | ||
|
||
match func_call.func_type() { | ||
ExprType::Unspecified => unreachable!(), | ||
ExprType::Add => match self.visit_binary_op(func_call.inputs()) { | ||
|
@@ -257,7 +274,13 @@ impl MonotonicityAnalyzer { | |
.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) { | ||
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) | ||
{ | ||
Comment on lines
+277
to
+283
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes I know that. I just got it. In my previous comment, I mixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. related: #13201
There may be more tricky cases to think about carefully.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. Thank for the
Only with the four all satisfied, we can say |
||
any | ||
} else { | ||
Inherent(Unknown) | ||
|
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
hereThere 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
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
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!