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

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

                Author: ASF GitHub Bot
            Created on: 11/Sep/20 21:55
            Start Date: 11/Sep/20 21:55
    Worklog Time Spent: 10m 
      Work Description: amaliujia commented on a change in pull request #12766:
URL: https://github.com/apache/beam/pull/12766#discussion_r487307937



##########
File path: 
sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/translation/AggregateScanConverter.java
##########
@@ -227,8 +224,35 @@ private AggregateCall convertAggCall(
         ZetaSqlCalciteTranslationUtils.toCalciteType(
             computedColumn.getColumn().getType(), nullable, 
getCluster().getRexBuilder());
 
+    SqlAggFunction sqlAggFunction =
+        getSqlAggFunction(aggregateFunctionCall.getFunction().getName(), 
returnType);
+
     String aggName = getTrait().resolveAlias(computedColumn.getColumn());
     return AggregateCall.create(
         sqlAggFunction, false, false, false, argList, -1, RelCollations.EMPTY, 
returnType, aggName);
   }
+
+  private static SqlAggFunction getSqlAggFunction(
+      String zetaSqlAggFunctionName, RelDataType returnType) {
+    // ZetaSQL specific aggregation functions, implemented with a user-defined 
CombineFn
+    if (ZETASQL_UDAF_OPERATORS.containsKey(zetaSqlAggFunctionName)) {
+      return ZETASQL_UDAF_OPERATORS.get(zetaSqlAggFunctionName);
+    }
+
+    if ("$count_star".equals(zetaSqlAggFunctionName)) {
+      zetaSqlAggFunctionName = "COUNT"; // $count_star and count both map to 
the same implementation
+    } else {
+      // BeamBuiltinAggregations.BUILTIN_AGGREGATOR_FACTORIES uses upper-case 
function names
+      zetaSqlAggFunctionName = zetaSqlAggFunctionName.toUpperCase();
+    }
+
+    // Beam builtin aggregation functions (available in both ZetaSQL and 
CalciteSQL), implemented in
+    // {@link 
org.apache.beam.sdk.extensions.sql.impl.transform.BeamBuiltinAggregations}
+    if 
(BeamBuiltinAggregations.BUILTIN_AGGREGATOR_FACTORIES.containsKey(zetaSqlAggFunctionName))
 {

Review comment:
       Is there a need to use the upper case of `zetaSqlAggFunctionName`?




----------------------------------------------------------------
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: 482314)
    Time Spent: 0.5h  (was: 20m)

> Support ZetaSQL aggregate functions for NUMERIC type
> ----------------------------------------------------
>
>                 Key: BEAM-10459
>                 URL: https://issues.apache.org/jira/browse/BEAM-10459
>             Project: Beam
>          Issue Type: Bug
>          Components: dsl-sql-zetasql
>            Reporter: Zijie Song
>            Assignee: Robin Qiu
>            Priority: P2
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Currently, Sum and Avg are not supported for ZetaSQL NUMERIC type due to type 
> mismatch.



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

Reply via email to