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

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

                Author: ASF GitHub Bot
            Created on: 08/Jun/18 14:48
            Start Date: 08/Jun/18 14:48
    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_r194081950
 
 

 ##########
 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:
   This is actually a really helpful comment, because: right now the 
environment is coded as though it can be re-used for multiple rows and windows 
(just because it doesn't reference them directly). But the values set in the 
env are tightly coupled to the current row and window, so it isn't actually 
independent. To do the environment lazily they need to be baked in, so that 
actually clarifies and simplifies more.

----------------------------------------------------------------
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: 110131)
    Time Spent: 4h 20m  (was: 4h 10m)

> 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 20m
>  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