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) {
     wrapperFun = 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()));
   }
   ```
   
   Isn't this simpler :)




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


Reply via email to