Skip to content
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

Merged
merged 1 commit into from
Feb 10, 2021

Conversation

palesz
Copy link
Contributor

@palesz palesz commented Feb 9, 2021

The MINUTE_OF_DAY() extraction function does not have an equivalent
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 to #68788.

… 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.
palesz pushed a commit to palesz/elasticsearch that referenced this pull request Feb 9, 2021
…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
@palesz palesz added :Analytics/SQL SQL querying >bug Team:QL (Deprecated) Meta label for query languages team v7.11.1 v7.12.0 v8.0.0 labels Feb 9, 2021
@palesz palesz marked this pull request as ready for review February 9, 2021 21:48
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

@palesz
Copy link
Contributor Author

palesz commented Feb 9, 2021

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@bpintea bpintea left a 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
Copy link
Contributor

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.

@palesz palesz merged commit 2b95858 into elastic:master Feb 10, 2021
@palesz palesz deleted the minute_of_day-fix branch February 10, 2021 14:25
palesz pushed a commit to palesz/elasticsearch that referenced this pull request Feb 10, 2021
… 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.
palesz pushed a commit to palesz/elasticsearch that referenced this pull request Feb 10, 2021
… 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.
palesz pushed a commit that referenced this pull request Feb 10, 2021
… 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.
palesz pushed a commit that referenced this pull request Feb 10, 2021
… 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.
palesz pushed a commit that referenced this pull request Feb 17, 2021
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
palesz pushed a commit to palesz/elasticsearch that referenced this pull request Feb 17, 2021
…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
palesz pushed a commit that referenced this pull request Feb 18, 2021
… (#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
palesz pushed a commit to palesz/elasticsearch that referenced this pull request Feb 18, 2021
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
palesz pushed a commit that referenced this pull request Mar 2, 2021
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 #68783 and #68788
palesz pushed a commit to palesz/elasticsearch that referenced this pull request Mar 2, 2021
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
palesz pushed a commit that referenced this pull request Mar 2, 2021
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 #68783 and #68788
palesz pushed a commit to palesz/elasticsearch that referenced this pull request Mar 2, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants