[ 
https://issues.apache.org/jira/browse/BEAM-8057?focusedWorklogId=460389&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-460389
 ]

ASF GitHub Bot logged work on BEAM-8057:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Jul/20 17:19
            Start Date: 17/Jul/20 17:19
    Worklog Time Spent: 10m 
      Work Description: robinyqiu commented on a change in pull request #12292:
URL: https://github.com/apache/beam/pull/12292#discussion_r456572768



##########
File path: 
sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/translation/ExpressionConverter.java
##########
@@ -786,15 +786,39 @@ private RexNode convertSimpleValueToRexNode(TypeKind 
kind, Value value) {
                     ZetaSqlCalciteTranslationUtils.toSimpleRelDataType(kind, 
rexBuilder()));
         break;
       case TYPE_DOUBLE:
+        // Cannot simply call makeApproxLiteral() for ZetaSQL DOUBLE type 
because positive infinity,
+        // negative infinity and Nan cannot be directly converted to 
BigDecimal. So we create three
+        // wrapper functions here for these three cases such that we can later 
recognize it and
+        // customize its unparsing in BeamBigQuerySqlDialect.
         double val = value.getDoubleValue();
-        if (Double.isInfinite(val) || Double.isNaN(val)) {
-          throw new UnsupportedOperationException("Does not support Infinite 
or NaN literals.");
+        if (Double.isInfinite(val) && val > 0) {
+          ret =
+              rexBuilder()
+                  .makeCall(
+                      SqlOperators.createOtherKindSqlFunction(
+                          BeamBigQuerySqlDialect.DOUBLE_POSITIVE_INF_FUNCTION,
+                          
ZetaSqlCalciteTranslationUtils.toCalciteTypeName(kind)));
+        } else if (Double.isInfinite(val) && val < 0) {
+          ret =
+              rexBuilder()
+                  .makeCall(
+                      SqlOperators.createOtherKindSqlFunction(
+                          BeamBigQuerySqlDialect.DOUBLE_NEGATIVE_INF_FUNCTION,
+                          
ZetaSqlCalciteTranslationUtils.toCalciteTypeName(kind)));
+        } else if (Double.isNaN(val)) {
+          ret =
+              rexBuilder()
+                  .makeCall(
+                      SqlOperators.createOtherKindSqlFunction(
+                          BeamBigQuerySqlDialect.DOUBLE_NAN_FUNCTION,
+                          
ZetaSqlCalciteTranslationUtils.toCalciteTypeName(kind)));
+        } else {
+          ret =
+              rexBuilder()
+                  .makeApproxLiteral(
+                      new BigDecimal(val),
+                      ZetaSqlCalciteTranslationUtils.toSimpleRelDataType(kind, 
rexBuilder()));

Review comment:
       I meant
   ```
   String wrapperFun = null;
   if (val == Double.POSITIVE_INFINITY) {
     wrapperFun = BeamBigQuerySqlDialect.DOUBLE_POSITIVE_INF_FUNCTION;
   } else if (val == Double.NEGATIVE_INFINITY) {
     BeamBigQuerySqlDialect.DOUBLE_NEGATIVE_INF_FUNCTION
   } else if (Double.isNan(val)) {
     wrapperFun = BeamBigQuerySqlDialect.DOUBLE_NAN_FUNCTION;
   }
   RelDataType returnType = 
ZetaSqlCalciteTranslationUtils.toSimpleRelDataType(kind, rexBuilder());
   if (wrapperFun == null) {
     ret = rexBuilder().makeApproxLiteral(new BigDecimal(val), returnType);
   } else {
     ret = 
rexBuilder().makeCall(SqlOperators.createOtherKindSqlFunction(wrapperFun, 
returnType.getSqlTypeName()));
   }
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 460389)
    Time Spent: 1h 10m  (was: 1h)

> Support NAN, INF, and -INF
> --------------------------
>
>                 Key: BEAM-8057
>                 URL: https://issues.apache.org/jira/browse/BEAM-8057
>             Project: Beam
>          Issue Type: Improvement
>          Components: dsl-sql-zetasql
>            Reporter: Rui Wang
>            Priority: P3
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to