-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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 MINUTE_OF_DAY() function that throws exception when used in comparisons #68783
Conversation
… in comparisons The `MINUTE_OF_DAY()` extraction function does not have an equivalent expressable using a datetime format pattern. The `MinuteOfDay.dateTimeFormat()` is called during the query translation and throws an exception, but the return value actually does not impact the translated query (binary comparisons with `DateTimeFunction` on one side always turn into a script query). This change fixes the immediate issue raised as part of elastic#67872, add integration tests covering the problem, but leaves the removal of the unnecessary `dateTimeFormat()` function a separate PR.
…ranslations lazy Removes the `DateTimeFunction.dateTimeFormat()` method that was called, but had no effect on the translated queries. This change also adds laziness, so translations don't execute unnecessarily. Before the `ExpressionTranslators` did some unnecessary `Expression` -> `Query` translations, where the result queries were thrown away by later translations (by the `wrapFunctionQuery`). One of the examples, when this happens, is when one side of the `BinaryComparison` is a function. The `BinaryComparison` at the end turns into a `ScriptQuery`, but in the intermediate steps the `ExpressionTranslators` try to translate it to a `RangeQuery`. Follows elastic#68783
Pinging @elastic/es-ql (Team:QL) |
https://github.com/elastic/elasticsearch/pull/68788/files#diff-385222df7bc48aa29c7282fd51bd3f3de071de85974214e19a44670750637182R274 and https://github.com/elastic/elasticsearch/pull/68788/files#diff-4f9289c27c5213594234e5b9a58c9a35248e71bb33b80696c6c6fddd13ea592dR45 shows the places where the ScriptQuery "wins" and throws away the results of the queries that were the only consumers of the |
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
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
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
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
@@ -153,6 +153,16 @@ SELECT WEEK(birth_date) week, birth_date FROM test_emp WHERE WEEK(birth_date) > | |||
2 |1953-01-07T00:00:00.000Z | |||
; | |||
|
|||
minuteOfDayFilterEquality | |||
SELECT MINUTE_OF_DAY(CONCAT(CONCAT('2021-01-22T14:26:06.', (salary % 2)::text), 'Z')::datetime) AS min_of_day |
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.
Not sure if adding the given time to the dates in hire_date
would have been less contrived, but this works too.
… in comparisons (elastic#68783) The `MINUTE_OF_DAY()` extraction function does not have an equivalent expressable using a datetime format pattern. The `MinuteOfDay.dateTimeFormat()` is called during the query translation and throws an exception, but the return value actually does not impact the translated query (binary comparisons with `DateTimeFunction` on one side always turn into a script query). This change fixes the immediate issue raised as part of elastic#67872, add integration tests covering the problem, but leaves the removal of the unnecessary `dateTimeFormat()` function a separate PR.
… in comparisons (elastic#68783) The `MINUTE_OF_DAY()` extraction function does not have an equivalent expressible using a datetime format pattern. The `MinuteOfDay.dateTimeFormat()` is called during the query translation and throws an exception, but the return value actually does not impact the translated query (binary comparisons with `DateTimeFunction` on one side always turn into a script query). This change fixes the immediate issue raised as part of elastic#67872, add integration tests covering the problem, but leaves the removal of the unnecessary `dateTimeFormat()` function a separate PR.
… in comparisons (#68783) (#68846) The `MINUTE_OF_DAY()` extraction function does not have an equivalent expressible using a datetime format pattern. The `MinuteOfDay.dateTimeFormat()` is called during the query translation and throws an exception, but the return value actually does not impact the translated query (binary comparisons with `DateTimeFunction` on one side always turn into a script query). This change fixes the immediate issue raised as part of #67872, add integration tests covering the problem, but leaves the removal of the unnecessary `dateTimeFormat()` function a separate PR.
… in comparisons (#68783) (#68854) The `MINUTE_OF_DAY()` extraction function does not have an equivalent expressible using a datetime format pattern. The `MinuteOfDay.dateTimeFormat()` is called during the query translation and throws an exception, but the return value actually does not impact the translated query (binary comparisons with `DateTimeFunction` on one side always turn into a script query). This change fixes the immediate issue raised as part of #67872, add integration tests covering the problem, but leaves the removal of the unnecessary `dateTimeFormat()` function a separate PR.
Removes the `DateTimeFunction.dateTimeFormat()` and the `TranslatorHandler.dateTimeFormat()` methods that were called, but had no effect on the translated queries. One of the examples, when this happens, is when one side of the `BinaryComparison` is a function. The `BinaryComparison` at the end turns into a `ScriptQuery`, but in the intermediate steps the `ExpressionTranslators` try to translate it to a `RangeQuery`. Follows #68783
…ic#68788) Removes the `DateTimeFunction.dateTimeFormat()` and the `TranslatorHandler.dateTimeFormat()` methods that were called, but had no effect on the translated queries. One of the examples, when this happens, is when one side of the `BinaryComparison` is a function. The `BinaryComparison` at the end turns into a `ScriptQuery`, but in the intermediate steps the `ExpressionTranslators` try to translate it to a `RangeQuery`. Follows elastic#68783
… (#69123) Removes the `DateTimeFunction.dateTimeFormat()` and the `TranslatorHandler.dateTimeFormat()` methods that were called, but had no effect on the translated queries. One of the examples, when this happens, is when one side of the `BinaryComparison` is a function. The `BinaryComparison` at the end turns into a `ScriptQuery`, but in the intermediate steps the `ExpressionTranslators` try to translate it to a `RangeQuery`. Follows #68783
Before the `ExpressionTranslators` did some unnecessary `Expression` -> `Query` translations, where the result queries were thrown away by later translations (by the `wrapFunctionQuery`). This change adds laziness, so translations don't execute unnecessarily. Follows elastic#68783
Before the `ExpressionTranslators` did some unnecessary `Expression` -> `Query` translations, where the result queries were thrown away by later translations (by the `wrapFunctionQuery`). This change adds laziness, so translations don't execute unnecessarily. Follows elastic#68783 and elastic#68788
The `DateTimeFunction.dateTimeFormat()` method that was called, but had no effect on the translated queries. One of the examples, when this happens, is when one side of the `BinaryComparison` is a function. The `BinaryComparison` at the end turns into a `ScriptQuery`, but in the intermediate steps the `ExpressionTranslators` try to translate it to a `RangeQuery`. Follows elastic#68783
The
MINUTE_OF_DAY()
extraction function does not have an equivalentdatetime format pattern.
The
MinuteOfDay.dateTimeFormat()
is called during the querytranslation and throws an exception, but the return value actually
does not impact the translated query (binary comparisons with
DateTimeFunction
on one side always turn into a script query).This change fixes the immediate issue raised as part of #67872,
add integration tests covering the problem, but leaves the removal
of the unnecessary
dateTimeFormat()
function to #68788.