Better error message for unsupported double values#11409
Merged
abhishekagarwal87 merged 3 commits intoapache:masterfrom Jul 8, 2021
Merged
Better error message for unsupported double values#11409abhishekagarwal87 merged 3 commits intoapache:masterfrom
abhishekagarwal87 merged 3 commits intoapache:masterfrom
Conversation
| if (Double.isNaN(exprResultDouble)) | ||
| { | ||
| String expression = druidExpression.getExpression(); | ||
| throw new IAE("'%s' evaluates to 'NaN' that is not supported. You can either cast the expression as bigint ('cast(%s as bigint)') or char ('cast(%s as char)') or change the expression itself", |
Contributor
Author
There was a problem hiding this comment.
wondering if using a NumberFormatException instead of IAE makes more sense here.
rohangarg
reviewed
Jul 5, 2021
| if (Double.isInfinite(exprResultDouble)) | ||
| { | ||
| String expression = druidExpression.getExpression(); | ||
| throw new IAE("'%s' evaluates to '+/-Infinity' that is not supported. You can either cast the expression as bigint ('cast(%s as bigint)') or char ('cast(%s as char)') or change the expression itself", |
Member
There was a problem hiding this comment.
I think that toString for exprResultDouble does evaluate as +/-INFINITY or NaN - so maybe that can be directly used when Double.isNaN(exprResultDouble) || Double.isInfinite(exprResultDouble)
Contributor
Author
There was a problem hiding this comment.
👍 good tip.
clintropolis
approved these changes
Jul 7, 2021
jihoonson
pushed a commit
to jihoonson/druid
that referenced
this pull request
Jul 12, 2021
A constant expression may evaluate to Double.NEGATIVE_INFINITY/Double.POSITIVE_INFINITY/Double.NAN e.g. log10(0). When using such an expression in native queries, the user will get the corresponding value without any error. In SQL, however, the user will run into NumberFormatException because we convert the double to big-decimal while constructing a literal numeric expression. This probably should be fixed in calcite - see https://issues.apache.org/jira/browse/CALCITE-2067. This PR adds a verbose error message so that users can take corrective action without scratching their heads.
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.
A constant expression may evaluate to Double.NEGATIVE_INFINITY/Double.POSITIVE_INFINITY/Double.NAN e.g.
log10(0). When using such an expression in native queries, the user will get the corresponding value without any error. In SQL, however, the user will run intoNumberFormatExceptionbecause we convert the double to big-decimal while constructing a literal numeric expression. This probably should be fixed in calcite - see https://issues.apache.org/jira/browse/CALCITE-2067. This PR adds a verbose error message so that users can take corrective action without scratching their heads.Key changed/added classes in this PR
DruidRexExecutorThis PR has: