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 issue regarding INTERVAL * number #42014

Merged
merged 3 commits into from May 15, 2019

Conversation

@matriv
Copy link
Contributor

commented May 9, 2019

Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

  1. There was no common type returned for that combination
  2. The BinaryArithmeticOperation was permitting the multiplication
    (called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
LoggerMessageFormat.format.

Fixes: #41239

SQL: Fix issue regarding INTERVAL * number
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

Fixes: #41239
@elasticmachine

This comment has been minimized.

Copy link
Collaborator

commented May 9, 2019

@matriv

This comment has been minimized.

Copy link
Contributor Author

commented May 9, 2019

Also fixes: #41200

@astefan
Copy link
Contributor

left a comment

LGTM. Left one comment.

DataType l = left().dataType();
DataType r = right().dataType();

if (!(r.isDateOrTimeBased() || DataTypes.isInterval(r))) {

This comment has been minimized.

Copy link
@astefan

astefan May 10, 2019

Contributor

if (!(r.isDateOrTimeBased() || DataTypes.isInterval(r))) {
return new TypeResolution(format(null, "[{}] has arguments with incompatible types [{}] and [{}]", symbol(), l, r));
}
if (!(l.isDateOrTimeBased() || DataTypes.isInterval(l))) {
return new TypeResolution(format(null, "[{}] has arguments with incompatible types [{}] and [{}]", symbol(), l, r));
}

The code here seems a duplicate. You could combine the two conditions, no?

@costin
costin approved these changes May 10, 2019
Copy link
Member

left a comment

LGTM.
Could you add a test with one and multiple negative values to see how the sign is being handled?

Thanks,

@matriv

This comment has been minimized.

Copy link
Contributor Author

commented May 11, 2019

@costin could you please explain a bit more? What do you mean with one and multiple negative values?

@costin

This comment has been minimized.

Copy link
Member

commented May 11, 2019

INTERVAL '1' MINUTE * -20
- INTERVAL '1' MINUTE * 20
- INTERVAL '1' MINUTE * -20

@matriv matriv merged commit 91039ba into elastic:master May 15, 2019

8 checks passed

CLA All commits in pull request signed
Details
elasticsearch-ci/1 Build finished.
Details
elasticsearch-ci/2 Build finished.
Details
elasticsearch-ci/bwc Build finished.
Details
elasticsearch-ci/default-distro Build finished.
Details
elasticsearch-ci/docbldesx Build finished.
Details
elasticsearch-ci/oss-distro-docs Build finished.
Details
elasticsearch-ci/packaging-sample Build finished.
Details

@matriv matriv deleted the matriv:fix-41239 branch May 15, 2019

matriv added a commit that referenced this pull request May 15, 2019
SQL: Fix issue regarding INTERVAL * number (#42014)
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

Fixes: #41239
Fixes: #41200
(cherry picked from commit 91039ba)
matriv added a commit that referenced this pull request May 15, 2019
SQL: Fix issue regarding INTERVAL * number (#42014)
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

Fixes: #41239
Fixes: #41200
(cherry picked from commit 91039ba)
matriv added a commit that referenced this pull request May 15, 2019
SQL: Fix issue regarding INTERVAL * number (#42014)
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

Fixes: #41239
Fixes: #41200
(cherry picked from commit 91039ba)
Megamiun added a commit to Megamiun/elasticsearch that referenced this pull request May 18, 2019
SQL: Fix issue regarding INTERVAL * number (elastic#42014)
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

Fixes: elastic#41239
Fixes: elastic#41200
gurkankaymak pushed a commit to gurkankaymak/elasticsearch that referenced this pull request May 27, 2019
SQL: Fix issue regarding INTERVAL * number (elastic#42014)
Interval * integer number is a valid operation which previously was
only supported for foldables (literals) and not when a field was
involved. That was because:

1. There was no common type returned for that combination
2. The `BinaryArithmeticOperation` was permitting the multiplication
(called by fold()) but the BinaryArithmeticProcessor didn't allow it

Moreover the error message for invalid arithmetic operations was wrong
because of the issue with the overloading methods of
`LoggerMessageFormat.format`.

Fixes: elastic#41239
Fixes: elastic#41200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.