Fix issue with CASE/IIF pre-calculating results#49553
Merged
matriv merged 3 commits intoelastic:masterfrom Nov 26, 2019
Merged
Conversation
Previously, CaseProcessor was pre-calculating (called process()) on all the building elements of a CASE/IIF expression, not only the conditions involved but also the results (if true/if false), as well as the final else result. In case one of those results had an erroneous calculation (e.g.: division by zero) this was executed and resulted in an Exception to be thrown, even if this result was not used because of the condition guarding it. e.g.: ``` SELECT CASE myField1 = 0 THEN NULL ELSE myField2 / myField1 END FROM test; ``` Fixes: elastic#49388
Collaborator
|
Pinging @elastic/es-search (:Search/SQL) |
Contributor
Author
astefan
approved these changes
Nov 25, 2019
Contributor
astefan
left a comment
There was a problem hiding this comment.
LGTM. Left two cosmetic comments and in terms of tests, I would like to see an IT one with more than one WHEN branch.
| List<Object> objects = new ArrayList<>(processors.size()); | ||
| for (Processor processor : processors) { | ||
| objects.add(processor.process(input)); | ||
| for (int i = 0; i < processors.size() - 2; i += 2) { |
Contributor
There was a problem hiding this comment.
So, here you basically take a condition and you evaluate it, and if it holds then you evaluate its results and break out of the loop. If it doesn't hold (evaluates to false), then move on to the next set of [condition, result] and repeat the process. Can you add a comment about this, please?
| for (Processor processor : processors) { | ||
| objects.add(processor.process(input)); | ||
| for (int i = 0; i < processors.size() - 2; i += 2) { | ||
| if (processors.get(i).process(input)==Boolean.TRUE) { |
Contributor
There was a problem hiding this comment.
processors.get(i).process(input) == Boolean.TRUE
matriv
added a commit
that referenced
this pull request
Nov 26, 2019
Previously, CaseProcessor was pre-calculating (called `process()`) on all the building elements of a CASE/IIF expression, not only the conditions involved but also the results, as well as the final else result. In case one of those results had an erroneous calculation (e.g.: division by zero) this was executed and resulted in an Exception to be thrown, even if this result was not used because of the condition guarding it. e.g.: ``` SELECT CASE myField1 = 0 THEN NULL ELSE myField2 / myField1 END FROM test; ``` Fixes: #49388 (cherry picked from commit dbd169a)
matriv
added a commit
that referenced
this pull request
Nov 26, 2019
Previously, CaseProcessor was pre-calculating (called `process()`) on all the building elements of a CASE/IIF expression, not only the conditions involved but also the results, as well as the final else result. In case one of those results had an erroneous calculation (e.g.: division by zero) this was executed and resulted in an Exception to be thrown, even if this result was not used because of the condition guarding it. e.g.: ``` SELECT CASE myField1 = 0 THEN NULL ELSE myField2 / myField1 END FROM test; ``` Fixes: #49388 (cherry picked from commit dbd169a)
matriv
added a commit
that referenced
this pull request
Nov 26, 2019
Previously, CaseProcessor was pre-calculating (called `process()`) on all the building elements of a CASE/IIF expression, not only the conditions involved but also the results, as well as the final else result. In case one of those results had an erroneous calculation (e.g.: division by zero) this was executed and resulted in an Exception to be thrown, even if this result was not used because of the condition guarding it. e.g.: ``` SELECT CASE myField1 = 0 THEN NULL ELSE myField2 / myField1 END FROM test; ``` Fixes: #49388 (cherry picked from commit dbd169a)
This was referenced Feb 3, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, CaseProcessor was pre-calculating (called process())
on all the building elements of a CASE/IIF expression, not only the
conditions involved but also the results (if true/if false), as well as
the final else result. In case one of those results had an erroneous
calculation (e.g.: division by zero) this was executed and resulted in
an Exception to be thrown, even if this result was not used because of
the condition guarding it. e.g.:
Fixes: #49388