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

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

                Author: ASF GitHub Bot
            Created on: 28/Dec/18 21:01
            Start Date: 28/Dec/18 21:01
    Worklog Time Spent: 10m 
      Work Description: apilloud commented on pull request #6417: [BEAM-5112] 
Use Calcite codegen to implement BeamCalcRel
URL: https://github.com/apache/beam/pull/6417#discussion_r244407083
 
 

 ##########
 File path: 
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamCalcRel.java
 ##########
 @@ -96,43 +224,243 @@ public boolean isInputSortRelAndLimitOnly() {
 
   /** {@code CalcFn} is the executor for a {@link BeamCalcRel} step. */
   private static class CalcFn extends DoFn<Row, Row> {
-    private BeamSqlExpressionExecutor executor;
-    private Schema outputSchema;
+    private final String processElementBlock;
+    private final Schema outputSchema;
+    private transient @Nullable ScriptEvaluator se = null;
 
-    public CalcFn(BeamSqlExpressionExecutor executor, Schema outputSchema) {
-      super();
-      this.executor = executor;
+    public CalcFn(String processElementBlock, Schema outputSchema) {
+      this.processElementBlock = processElementBlock;
       this.outputSchema = outputSchema;
     }
 
+    ScriptEvaluator compile() {
+      ScriptEvaluator se = new ScriptEvaluator();
+      se.setParameters(
+          new String[] {outputSchemaParam.name, processContextParam.name, 
DataContext.ROOT.name},
+          new Class[] {
+            (Class) outputSchemaParam.getType(),
+            (Class) processContextParam.getType(),
+            (Class) DataContext.ROOT.getType()
+          });
+      try {
+        se.cook(processElementBlock);
+      } catch (CompileException e) {
+        throw new RuntimeException("Could not compile CalcFn: " + 
processElementBlock, e);
+      }
+      return se;
+    }
+
     @Setup
     public void setup() {
-      executor.prepare();
+      this.se = compile();
     }
 
     @ProcessElement
     public void processElement(ProcessContext c) {
-      Row inputRow = c.element();
-      @Nullable
-      List<Object> rawResultValues =
-          executor.execute(inputRow, null, 
BeamSqlExpressionEnvironments.forRow(inputRow, null));
-
-      if (rawResultValues != null) {
-        List<Object> castResultValues =
-            IntStream.range(0, outputSchema.getFieldCount())
-                .mapToObj(i -> castField(rawResultValues, i))
-                .collect(toList());
-        
c.output(Row.withSchema(outputSchema).addValues(castResultValues).build());
+      assert se != null;
+      try {
+        se.evaluate(new Object[] {outputSchema, c, CONTEXT_INSTANCE});
+      } catch (InvocationTargetException e) {
+        throw new RuntimeException(
+            "CalcFn failed to evaluate: " + processElementBlock, e.getCause());
+      }
+    }
+  }
+
+  private static final Map<TypeName, Type> rawTypeMap =
+      ImmutableMap.<TypeName, Type>builder()
+          .put(TypeName.BYTE, Byte.class)
+          .put(TypeName.INT16, Short.class)
+          .put(TypeName.INT32, Integer.class)
+          .put(TypeName.INT64, Long.class)
+          .put(TypeName.FLOAT, Float.class)
+          .put(TypeName.DOUBLE, Double.class)
+          .build();
+
+  private Expression castOutput(Expression value, FieldType toType) {
+    if (value.getType() == Object.class) {
 
 Review comment:
   See the comment below. This is the fast copy path, which is actually used 
quite a bit. When a field is copied from input to output without modification 
code is generated to fetch it with `getValue` which returns an object. That 
object can be passed through to the new row without any conversion.
 
----------------------------------------------------------------
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:
[email protected]


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

    Worklog Id:     (was: 179568)
    Time Spent: 4h 10m  (was: 4h)

> 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: 4h 10m
>  Remaining Estimate: 0h
>




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

Reply via email to