You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/07/05 13:10:37 UTC

[GitHub] [druid] rohangarg commented on a change in pull request #11409: Better error message for unsupported double values

rohangarg commented on a change in pull request #11409:
URL: https://github.com/apache/druid/pull/11409#discussion_r663920216



##########
File path: sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidRexExecutor.java
##########
@@ -126,6 +126,23 @@ public void reduce(
               // if exprResult evaluates to Nan or infinity, this will throw a NumberFormatException.
               // If you find yourself in such a position, consider casting the literal to a BIGINT so that
               // the query can execute.
+              double exprResultDouble = exprResult.asDouble();
+              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",
+                    expression,
+                    expression,
+                    expression);
+              }
+              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",

Review 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)`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org