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

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

                Author: ASF GitHub Bot
            Created on: 04/Feb/20 18:30
            Start Date: 04/Feb/20 18:30
    Worklog Time Spent: 10m 
      Work Description: robinyqiu commented on pull request #10634: [BEAM-9178] 
Support all ZetaSQL TIMESTAMP functions
URL: https://github.com/apache/beam/pull/10634#discussion_r374846150
 
 

 ##########
 File path: 
sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/translation/ExpressionConverter.java
 ##########
 @@ -770,88 +765,34 @@ private RexNode convertResolvedFunctionCall(
           throw new UnsupportedOperationException(
               "Only support TUMBLE, HOP AND SESSION functions right now.");
       }
-    } else if (functionCall.getFunction().getGroup().equals("ZetaSQL")) {
-      op =
-          
SqlStdOperatorMappingTable.ZETASQL_FUNCTION_TO_CALCITE_SQL_OPERATOR.get(
-              functionCall.getFunction().getName());
-
+    } else if ("ZetaSQL".equals(funGroup)) {
       if (op == null) {
-        throw new UnsupportedOperationException(
-            "Does not support ZetaSQL function: " + 
functionCall.getFunction().getName());
+        TypeKind returnType =
+            
SqlStdOperatorMappingTable.ZETASQL_FUNCTION_NAME_TO_RETURN_TYPE.get(funName);
+        if (returnType != null) {
+          op =
+              SqlOperators.createSimpleSqlFunction(
+                  funName, ZetaSqlUtils.zetaSqlTypeToCalciteType(returnType));
+        } else {
+          throw new UnsupportedOperationException("Does not support ZetaSQL 
function: " + funName);
+        }
       }
 
-      // There are different processes to handle argument conversion because 
INTERVAL is not a
-      // type in ZetaSQL.
-      if 
(FUNCTION_FAMILY_DATE_ADD.contains(functionCall.getFunction().getName())) {
-        return convertTimestampAddFunction(functionCall, columnList, 
fieldList);
-      } else {
-        for (ResolvedExpr expr : functionCall.getArgumentList()) {
-          operands.add(convertRexNodeFromResolvedExpr(expr, columnList, 
fieldList));
-        }
+      for (ResolvedExpr expr : functionCall.getArgumentList()) {
+        operands.add(convertRexNodeFromResolvedExpr(expr, columnList, 
fieldList));
       }
     } else {
-      throw new UnsupportedOperationException(
-          "Does not support function group: " + 
functionCall.getFunction().getGroup());
+      throw new UnsupportedOperationException("Does not support function 
group: " + funGroup);
     }
 
     SqlOperatorRewriter rewriter =
-        
SqlStdOperatorMappingTable.ZETASQL_FUNCTION_TO_CALCITE_SQL_OPERATOR_REWRITER.get(
-            functionCall.getFunction().getName());
+        
SqlStdOperatorMappingTable.ZETASQL_FUNCTION_TO_CALCITE_SQL_OPERATOR_REWRITER.get(funName);
 
     if (rewriter != null) {
-      ret = rewriter.apply(rexBuilder(), operands);
+      return rewriter.apply(rexBuilder(), operands);
     } else {
-      ret = rexBuilder().makeCall(op, operands);
-    }
-    return ret;
-  }
-
-  private RexNode convertTimestampAddFunction(
-      ResolvedFunctionCall functionCall,
-      List<ResolvedColumn> columnList,
-      List<RelDataTypeField> fieldList) {
-
-    TimeUnit unit =
-        TIME_UNIT_CASTING_MAP.get(
-            ((ResolvedLiteral) 
functionCall.getArgumentList().get(2)).getValue().getEnumValue());
-
-    if ((unit == TimeUnit.MICROSECOND) || (unit == TimeUnit.NANOSECOND)) {
 
 Review comment:
   Yeah right now it might work inconsistently. We can throw an exception 
during timestamp value conversion 
([here](https://github.com/apache/beam/blob/39c4a9fafb82dce126870a129c7848470d21006d/sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/ZetaSqlUtils.java#L186))
 if we see microsecond precision used, but I am not sure if we should do that. 
One  down side of that is we might break functions unnecessarily (e.g. 
CURRENT_TIMESTAMP). Or maybe we can leave it as it is and see if we can fully 
fix the precision problem?
 
----------------------------------------------------------------
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: 381786)
    Time Spent: 1h 50m  (was: 1h 40m)

> Support ZetaSQL TIMESTAMP functions in BeamSQL
> ----------------------------------------------
>
>                 Key: BEAM-9178
>                 URL: https://issues.apache.org/jira/browse/BEAM-9178
>             Project: Beam
>          Issue Type: New Feature
>          Components: dsl-sql-zetasql
>            Reporter: Yueyang Qiu
>            Assignee: Yueyang Qiu
>            Priority: Major
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> Support *all* TIMESTAMP functions defined in ZetaSQL (BigQuery Standard SQL). 
> See the full list of functions below:
> [https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions]



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

Reply via email to