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

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

                Author: ASF GitHub Bot
            Created on: 03/Oct/18 23:27
            Start Date: 03/Oct/18 23:27
    Worklog Time Spent: 10m 
      Work Description: apilloud closed pull request #6558: [BEAM-5112] Don't 
use BeamSqlInputRefExpression to pass Integer
URL: https://github.com/apache/beam/pull/6558
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/transform/BeamAggregationTransforms.java
 
b/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/transform/BeamAggregationTransforms.java
index 687d85588cf..61342c45245 100644
--- 
a/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/transform/BeamAggregationTransforms.java
+++ 
b/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/transform/BeamAggregationTransforms.java
@@ -39,15 +39,12 @@
 import org.apache.beam.sdk.coders.KvCoder;
 import org.apache.beam.sdk.coders.RowCoder;
 import org.apache.beam.sdk.coders.VarIntCoder;
-import 
org.apache.beam.sdk.extensions.sql.impl.interpreter.BeamSqlExpressionEnvironments;
-import 
org.apache.beam.sdk.extensions.sql.impl.interpreter.operator.BeamSqlInputRefExpression;
 import org.apache.beam.sdk.extensions.sql.impl.interpreter.operator.UdafImpl;
 import org.apache.beam.sdk.extensions.sql.impl.transform.agg.CovarianceFn;
 import org.apache.beam.sdk.extensions.sql.impl.transform.agg.VarianceFn;
 import org.apache.beam.sdk.extensions.sql.impl.utils.BigDecimalConverter;
 import org.apache.beam.sdk.extensions.sql.impl.utils.CalciteUtils;
 import org.apache.beam.sdk.schemas.Schema;
-import org.apache.beam.sdk.schemas.Schema.FieldType;
 import org.apache.beam.sdk.transforms.Combine.CombineFn;
 import org.apache.beam.sdk.transforms.Count;
 import org.apache.beam.sdk.transforms.DoFn;
@@ -153,22 +150,10 @@ public AggregationAdaptor(
           int refIndexKey = call.getArgList().get(0);
           int refIndexValue = call.getArgList().get(1);
 
-          FieldType keyDescriptor = 
sourceSchema.getField(refIndexKey).getType();
-          BeamSqlInputRefExpression sourceExpKey =
-              new 
BeamSqlInputRefExpression(CalciteUtils.toSqlTypeName(keyDescriptor), 
refIndexKey);
-
-          FieldType valueDescriptor = 
sourceSchema.getField(refIndexValue).getType();
-          BeamSqlInputRefExpression sourceExpValue =
-              new BeamSqlInputRefExpression(
-                  CalciteUtils.toSqlTypeName(valueDescriptor), refIndexValue);
-
-          sourceFieldExps.add(KV.of(sourceExpKey, sourceExpValue));
+          sourceFieldExps.add(KV.of(refIndexKey, refIndexValue));
         } else {
-          int refIndex = call.getArgList().size() > 0 ? 
call.getArgList().get(0) : 0;
-          FieldType fieldType = sourceSchema.getField(refIndex).getType();
-          BeamSqlInputRefExpression sourceExp =
-              new 
BeamSqlInputRefExpression(CalciteUtils.toSqlTypeName(fieldType), refIndex);
-          sourceFieldExps.add(sourceExp);
+          Integer refIndex = call.getArgList().size() > 0 ? 
call.getArgList().get(0) : 0;
+          sourceFieldExps.add(refIndex);
         }
 
         Schema.Field field = CalciteUtils.toField(aggName, call.type);
@@ -243,10 +228,8 @@ public AggregationAccumulator 
addInput(AggregationAccumulator accumulator, Row i
         CombineFn aggregator = aggregators.get(idx);
         Object element = accumulator.accumulatorElements.get(idx);
 
-        if (sourceFieldExps.get(idx) instanceof BeamSqlInputRefExpression) {
-          BeamSqlInputRefExpression exp = (BeamSqlInputRefExpression) 
sourceFieldExps.get(idx);
-          Object value =
-              exp.evaluate(input, null, 
BeamSqlExpressionEnvironments.empty()).getValue();
+        if (sourceFieldExps.get(idx) instanceof Integer) {
+          Object value = input.getValue((Integer) sourceFieldExps.get(idx));
 
           // every aggregator ignores null values, e.g., COUNT(NULL) is always 
zero
           if (value != null) {
@@ -260,16 +243,11 @@ public AggregationAccumulator 
addInput(AggregationAccumulator accumulator, Row i
            * If source expression is type of KV pair, we bundle the value of 
two expressions into KV
            * pair and pass it to aggregator's addInput method.
            */
-          KV<BeamSqlInputRefExpression, BeamSqlInputRefExpression> exp =
-              (KV<BeamSqlInputRefExpression, BeamSqlInputRefExpression>) 
sourceFieldExps.get(idx);
+          KV<Integer, Integer> exp = (KV<Integer, Integer>) 
sourceFieldExps.get(idx);
 
-          Object key =
-              exp.getKey().evaluate(input, null, 
BeamSqlExpressionEnvironments.empty()).getValue();
+          Object key = input.getValue(exp.getKey());
 
-          Object value =
-              exp.getValue()
-                  .evaluate(input, null, BeamSqlExpressionEnvironments.empty())
-                  .getValue();
+          Object value = input.getValue(exp.getValue());
 
           // ignore aggregator if either key or value is null, e.g., 
COVAR_SAMP(x, NULL) is null
           if (key != null && value != null) {
@@ -313,20 +291,18 @@ private Object getAggregatorOutput(AggregationAccumulator 
accumulator, int idx)
       registry.registerCoderForClass(BigDecimal.class, BigDecimalCoder.of());
       List<Coder> aggAccuCoderList = new ArrayList<>();
       for (int idx = 0; idx < aggregators.size(); ++idx) {
-        if (sourceFieldExps.get(idx) instanceof BeamSqlInputRefExpression) {
-          BeamSqlInputRefExpression exp = (BeamSqlInputRefExpression) 
sourceFieldExps.get(idx);
-          int srcFieldIndex = exp.getInputRef();
+        if (sourceFieldExps.get(idx) instanceof Integer) {
+          int srcFieldIndex = (Integer) sourceFieldExps.get(idx);
           Coder srcFieldCoder =
               RowCoder.coderForPrimitiveType(
                   
sourceSchema.getField(srcFieldIndex).getType().getTypeName());
           
aggAccuCoderList.add(aggregators.get(idx).getAccumulatorCoder(registry, 
srcFieldCoder));
         } else if (sourceFieldExps.get(idx) instanceof KV) {
           // extract coder of two expressions separately.
-          KV<BeamSqlInputRefExpression, BeamSqlInputRefExpression> exp =
-              (KV<BeamSqlInputRefExpression, BeamSqlInputRefExpression>) 
sourceFieldExps.get(idx);
+          KV<Integer, Integer> exp = (KV<Integer, Integer>) 
sourceFieldExps.get(idx);
 
-          int srcFieldIndexKey = exp.getKey().getInputRef();
-          int srcFieldIndexValue = exp.getValue().getInputRef();
+          int srcFieldIndexKey = exp.getKey();
+          int srcFieldIndexValue = exp.getValue();
 
           Coder srcFieldCoderKey =
               RowCoder.coderForPrimitiveType(


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

    Worklog Id:     (was: 150980)
    Time Spent: 1h  (was: 50m)

> Investigate if Calcite can generate functions that we need
> ----------------------------------------------------------
>
>                 Key: BEAM-5112
>                 URL: https://issues.apache.org/jira/browse/BEAM-5112
>             Project: Beam
>          Issue Type: Sub-task
>          Components: dsl-sql
>            Reporter: Rui Wang
>            Assignee: Andrew Pilloud
>            Priority: Major
>          Time Spent: 1h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to