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

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

                Author: ASF GitHub Bot
            Created on: 12/Sep/18 22:07
            Start Date: 12/Sep/18 22:07
    Worklog Time Spent: 10m 
      Work Description: apilloud commented on a change in pull request #6382: 
[BEAM-4449] Finish splitting Aggregate and Project
URL: https://github.com/apache/beam/pull/6382#discussion_r217205293
 
 

 ##########
 File path: 
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rule/BeamAggregationRule.java
 ##########
 @@ -54,29 +61,133 @@ public void onMatch(RelOptRuleCall call) {
 
   private static RelNode updateWindow(RelOptRuleCall call, Aggregate 
aggregate, Project project) {
     ImmutableBitSet groupByFields = aggregate.getGroupSet();
-    List<RexNode> projectMapping = project.getProjects();
+    ArrayList<RexNode> projects = new ArrayList(project.getProjects());
 
-    Optional<AggregateWindowField> windowField = Optional.empty();
+    WindowFn windowFn = null;
+    int windowFieldIndex = -1;
 
     for (int groupFieldIndex : groupByFields.asList()) {
-      RexNode projNode = projectMapping.get(groupFieldIndex);
+      RexNode projNode = projects.get(groupFieldIndex);
       if (!(projNode instanceof RexCall)) {
         continue;
       }
 
-      windowField = AggregateWindowFactory.getWindowFieldAt((RexCall) 
projNode, groupFieldIndex);
+      RexCall rexCall = (RexCall) projNode;
+      WindowFn fn = createWindowFn(rexCall.getOperands(), rexCall.op.kind);
+      if (fn != null) {
+        windowFn = fn;
+        windowFieldIndex = groupFieldIndex;
+        projects.set(groupFieldIndex, rexCall.getOperands().get(0));
+      }
     }
 
+    final Project newProject =
+        project.copy(project.getTraitSet(), project.getInput(), projects, 
project.getRowType());
+
     return new BeamAggregationRel(
         aggregate.getCluster(),
         aggregate.getTraitSet().replace(BeamLogicalConvention.INSTANCE),
-        convert(
-            aggregate.getInput(),
-            
aggregate.getInput().getTraitSet().replace(BeamLogicalConvention.INSTANCE)),
+        convert(newProject, 
newProject.getTraitSet().replace(BeamLogicalConvention.INSTANCE)),
         aggregate.indicator,
         aggregate.getGroupSet(),
         aggregate.getGroupSets(),
         aggregate.getAggCallList(),
-        windowField);
+        windowFn,
+        windowFieldIndex);
+  }
+
+  /**
 
 Review comment:
   Note: here down is moved from `AggregateWindowFactory.java`. This is the 
only place the code is used and keeping it all together makes it much easier to 
follow.

----------------------------------------------------------------
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: 143786)
    Time Spent: 6h 40m  (was: 6.5h)

> 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
>             Fix For: 2.5.0
>
>          Time Spent: 6h 40m
>  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