Fixes for safe_divide with vectorize and datatypes#15839
Merged
abhishekagarwal87 merged 3 commits intoapache:masterfrom Feb 8, 2024
Merged
Fixes for safe_divide with vectorize and datatypes#15839abhishekagarwal87 merged 3 commits intoapache:masterfrom
abhishekagarwal87 merged 3 commits intoapache:masterfrom
Conversation
dfe97a2 to
6346075
Compare
6346075 to
efaf8ef
Compare
somu-imply
commented
Feb 6, 2024
| new Object[]{1.0F, 1L, 1.0, 3253230.0F}, | ||
| new Object[]{0.0F, 0L, 0.0, 0.0F}, | ||
| new Object[]{1.0F, 1L, 1.0D, 3253230.0F}, | ||
| new Object[]{0.0F, null, 0.0D, 0.0F}, |
Contributor
Author
There was a problem hiding this comment.
This change is due to change in eval handling SQL compatibility mode correctly
somu-imply
commented
Feb 6, 2024
| { | ||
| private static final SqlFunction SQL_FUNCTION = OperatorConversions | ||
| .operatorBuilder(StringUtils.toUpperCase(Function.SafeDivide.NAME)) | ||
| .operandTypeChecker(OperandTypes.ANY_NUMERIC) |
Contributor
Author
There was a problem hiding this comment.
Refactored this slightly and added the proper return type inference. Quotient depended on if the numerator and denominators are null and would throw an exception of failing datatype EXPR$0: INTEGER NOT NULL -> INTEGER
pranavbhole
approved these changes
Feb 7, 2024
clintropolis
reviewed
Feb 7, 2024
Comment on lines
+1186
to
+1189
| if (x != 0) { | ||
| return ExprEval.ofLong(null); | ||
| } | ||
| return ExprEval.ofLong(0); | ||
| return ExprEval.ofLong(NullHandling.defaultLongValue()); |
Member
There was a problem hiding this comment.
why do we need to distinguish case of numerator being non-zero? in sql compatible mode this results in null in both cases.
Also, i think this should just be set to ExprEval.ofLong(null) in both cases since after #13809 the coercion of null to default values happens when stuff gets out of the expression layer instead of inside it
0c22617 to
c86d0e3
Compare
clintropolis
approved these changes
Feb 8, 2024
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.
Queries like
used to fail previously with the error
Cannot vectorize. The reason was that vectorized() was not implemented for the safe_divide function.Also
SAFE_DIVIDE(1,0)when used without a table would throw an exception andSAFE_DIVIDE(0,0)was not handled correctly for sqlCompatible mode. This PR fixes these issuesThis PR has: