ZijieSong946 commented on a change in pull request #12292:
URL: https://github.com/apache/beam/pull/12292#discussion_r456545841
##########
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 am not quiet sure how to merge the first three blocks with the last
one, because the first three use `resBuilder().makeCall()` while the last one
uses `rexBuilder().makeApproxLiteral()`. Also, `returnType` seems can only be
used in the last block.
----------------------------------------------------------------
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]