-
Notifications
You must be signed in to change notification settings - Fork 25k
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
SQL: Fix the inconsistent behaviour of ISO_WEEK_YEAR() #68758
Conversation
The `SELECT ISO_WEEK_OF_YEAR(a) AS x FROM test WHERE x=4` query returned with `x=3` results because the `ISO_WEEK_YEAR(a)` in the WHERE clause that turns into a script query and the `ISO_WEEK_YEAR(a)` in the projections that turns into a post-processing on top of the Query DSL results execute different code to calculate the result. This change unifies the different code paths and results in a single method being responsible for the actual calculation. Note: this change impacts the way how all the `DateTimeFunction`s that do the field extraction from a date get translated into a script query. Fixes part of elastic#67872
Pinging @elastic/es-ql (Team:QL) |
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. Left a comment for the integ test.
@@ -131,6 +131,32 @@ SELECT WEEK(birth_date) week, birth_date FROM test_emp ORDER BY WEEK(birth_date) | |||
44 |1961-11-02T00:00:00.000Z | |||
; | |||
|
|||
isoWeekOfYear | |||
schema::birth_date:ts|iso_week:i|week:i | |||
SELECT birth_date, IW(birth_date) iso_week, WEEK(birth_date) week FROM test_emp WHERE IW(birth_date) < 8 ORDER BY iso_week; |
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.
Minor: maybe you can add a AND week > 2
so we can check both filters work and one filter uses also the alias`
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
---------------+--------------- | ||
1 |2 |
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.
Note to self: "manual" checking the csv specs sometimes pays off.
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.
Left a comment about backwards compatibility - otherwise LGTM.
@@ -221,14 +221,14 @@ public static Number tan(Number value) { | |||
// | |||
// Date/Time functions | |||
// | |||
public static Integer dateTimeChrono(Object dateTime, String tzId, String chronoName) { | |||
if (dateTime == null || tzId == null || chronoName == null) { | |||
public static Integer dateTimeExtract(Object dateTime, String tzId, String extractorName) { |
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 don't have a strong preference regarding the method rename however there is an associated cost for it in backwards compatibility.
When executing across older clusters, the generated query would fail since there's no dateTimeExtract
in those versions, only dateTimeChrono
.
To avoid this, simply keep dateTimeChrono
around and redirect it to dateTimeExtract
so its backwards compatible or avoid the method rename in the first place.
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.
Thanks, good catch. It is not just a simple method rename, also the possible values of the last parameter changed (from ChronoField
enum to DateTimeExtract
enum values). I will keep around a @Deprecated dateTimeChrono()
for backwards compatibility that will do this translation. I guess we can remove it in the next major version.
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
The `SELECT ISO_WEEK_OF_YEAR(a) AS x FROM test WHERE x=4` query returned with `x=3` results because the `ISO_WEEK_YEAR(a)` in the WHERE clause that turns into a script query and the `ISO_WEEK_YEAR(a)` in the projections that turns into a post-processing on top of the Query DSL results execute different code to calculate the result. This change unifies the different code paths and results in a single method being responsible for the actual calculation. Note: this change impacts the way how all the `DateTimeFunction`s that do the field extraction from a date get translated into a script query. Fixes part of elastic#67872
The `SELECT ISO_WEEK_OF_YEAR(a) AS x FROM test WHERE x=4` query returned with `x=3` results because the `ISO_WEEK_YEAR(a)` in the WHERE clause that turns into a script query and the `ISO_WEEK_YEAR(a)` in the projections that turns into a post-processing on top of the Query DSL results execute different code to calculate the result. This change unifies the different code paths and results in a single method being responsible for the actual calculation. Note: this change impacts the way how all the `DateTimeFunction`s that do the field extraction from a date get translated into a script query. Fixes part of elastic#67872
The `SELECT ISO_WEEK_OF_YEAR(a) AS x FROM test WHERE x=4` query returned with `x=3` results because the `ISO_WEEK_YEAR(a)` in the WHERE clause that turns into a script query and the `ISO_WEEK_YEAR(a)` in the projections that turns into a post-processing on top of the Query DSL results execute different code to calculate the result. This change unifies the different code paths and results in a single method being responsible for the actual calculation. Note: this change impacts the way how all the `DateTimeFunction`s that do the field extraction from a date get translated into a script query. Fixes part of #67872
The `SELECT ISO_WEEK_OF_YEAR(a) AS x FROM test WHERE x=4` query returned with `x=3` results because the `ISO_WEEK_YEAR(a)` in the WHERE clause that turns into a script query and the `ISO_WEEK_YEAR(a)` in the projections that turns into a post-processing on top of the Query DSL results execute different code to calculate the result. This change unifies the different code paths and results in a single method being responsible for the actual calculation. Note: this change impacts the way how all the `DateTimeFunction`s that do the field extraction from a date get translated into a script query. Fixes part of #67872
The
SELECT ISO_WEEK_OF_YEAR(a) AS x FROM test WHERE x=4
query returnedwith
x=3
results because theISO_WEEK_YEAR(a)
in the WHERE clausethat turns into a script query and the
ISO_WEEK_YEAR(a)
in the projectionsthat turns into a post-processing on top of the Query DSL results execute
different code to calculate the result.
This change unifies the different code paths and results in a single method
being responsible for the actual calculation.
Note: this change impacts the way how all the
DateTimeFunction
s thatdo the field extraction from a date get translated into a script query.
Fixes part of #67872