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

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

                Author: ASF GitHub Bot
            Created on: 08/Jun/18 14:35
            Start Date: 08/Jun/18 14:35
    Worklog Time Spent: 10m 
      Work Description: kennknowles commented on a change in pull request 
#5544: [BEAM-4449] Replace project and filter with calc
URL: https://github.com/apache/beam/pull/5544#discussion_r194073182
 
 

 ##########
 File path: 
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/interpreter/BeamSqlFnExecutor.java
 ##########
 @@ -503,13 +513,32 @@ private static boolean isDateNode(SqlTypeName type, 
Object value) {
   public void prepare() {}
 
   @Override
-  public List<Object> execute(
-      Row inputRow, BoundedWindow window, ImmutableMap<Integer, Object> 
correlateEnv) {
-    List<Object> results = new ArrayList<>();
-    for (BeamSqlExpression exp : exps) {
-      results.add(exp.evaluate(inputRow, window, correlateEnv).getValue());
+  public @Nullable List<Object> execute(
+      Row inputRow, BoundedWindow window, BeamSqlExpressionEnvironment env) {
+
+    final BeamSqlExpressionEnvironment finalEnv = buildExprEnv(inputRow, 
window, env);
+
+    boolean conditionResult = filterCondition.evaluate(inputRow, window, 
finalEnv).getBoolean();
+
+    if (conditionResult) {
+      return projections
+          .stream()
+          .map(project -> project.evaluate(inputRow, window, 
finalEnv).getValue())
+          .collect(Collectors.toList());
+    } else {
+      return null;
+    }
+  }
+
+  private BeamSqlExpressionEnvironment buildExprEnv(
+      Row inputRow, BoundedWindow window, BeamSqlExpressionEnvironment env) {
+    int nextExprId = 0;
+    BeamSqlExpressionEnvironment localEnv = 
env.copyWithEmptyLocalRefs(exprs.size());
+    for (BeamSqlExpression expr : exprs) {
+      localEnv.setLocalRef(nextExprId, expr.evaluate(inputRow, window, 
localEnv));
 
 Review comment:
   That is a good question. I'm not actually sure. I am going to try to get the 
other things green here and then consider that change.

----------------------------------------------------------------
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: 110126)
    Time Spent: 4h  (was: 3h 50m)

> Use Calc instead of Project and Filter separately
> -------------------------------------------------
>
>                 Key: BEAM-4449
>                 URL: https://issues.apache.org/jira/browse/BEAM-4449
>             Project: Beam
>          Issue Type: Improvement
>          Components: dsl-sql
>            Reporter: Kenneth Knowles
>            Assignee: Kenneth Knowles
>            Priority: Major
>          Time Spent: 4h
>  Remaining Estimate: 0h
>
> Calcite has a combined Calc operator that is amenable to more optimization, 
> and also means less code to manage as we adjust how the operators/expressions 
> are implemented.



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

Reply via email to