You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by am...@apache.org on 2015/07/09 00:10:40 UTC

drill git commit: DRILL-3292: At the stage of converting Prel to Pop (planning phase), ensure constants in Window are converted to LogicalExpression

Repository: drill
Updated Branches:
  refs/heads/master b6577feda -> 8f3dc0d10


DRILL-3292: At the stage of converting Prel to Pop (planning phase), ensure constants in Window are converted to LogicalExpression


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/8f3dc0d1
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/8f3dc0d1
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/8f3dc0d1

Branch: refs/heads/master
Commit: 8f3dc0d10fd87c5c7df57b59a390dc2a150b35d0
Parents: b6577fe
Author: Hsuan-Yi Chu <hs...@usc.edu>
Authored: Mon Jul 6 10:58:45 2015 -0700
Committer: Aman Sinha <as...@maprtech.com>
Committed: Wed Jul 8 14:54:34 2015 -0700

----------------------------------------------------------------------
 .../drill/exec/planner/physical/WindowPrel.java | 17 +++++++++++----
 .../apache/drill/exec/TestWindowFunctions.java  | 22 +++++++++++++++++++-
 2 files changed, 34 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/8f3dc0d1/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WindowPrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WindowPrel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WindowPrel.java
index 170438e..c27b547 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WindowPrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/WindowPrel.java
@@ -20,8 +20,6 @@ package org.apache.drill.exec.planner.physical;
 
 import com.google.common.collect.Lists;
 
-import org.apache.calcite.rel.type.RelDataTypeField;
-import org.apache.calcite.rel.type.RelRecordType;
 import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.FieldReference;
 import org.apache.drill.common.expression.FunctionCall;
@@ -32,14 +30,18 @@ import org.apache.drill.common.logical.data.Order;
 import org.apache.drill.exec.physical.base.PhysicalOperator;
 import org.apache.drill.exec.physical.config.WindowPOP;
 import org.apache.drill.exec.planner.common.DrillWindowRelBase;
+import org.apache.drill.exec.planner.logical.DrillOptiq;
+import org.apache.drill.exec.planner.logical.DrillParseContext;
 import org.apache.drill.exec.planner.physical.visitor.PrelVisitor;
 import org.apache.drill.exec.record.BatchSchema;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
 import org.apache.calcite.rel.core.AggregateCall;
 import org.apache.calcite.rel.RelFieldCollation;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelTraitSet;
-import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rex.RexLiteral;
 import org.apache.calcite.util.BitSets;
 
@@ -48,7 +50,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import static com.google.common.base.Preconditions.checkState;
 
@@ -112,10 +113,17 @@ public class WindowPrel extends DrillWindowRelBase implements Prel {
   }
 
   protected LogicalExpression toDrill(AggregateCall call, List<String> fn) {
+    DrillParseContext context = new DrillParseContext(PrelUtil.getSettings(getCluster()));
+
     List<LogicalExpression> args = Lists.newArrayList();
     for (Integer i : call.getArgList()) {
+      final int indexInConstants = i - fn.size();
       if (i < fn.size()) {
         args.add(new FieldReference(fn.get(i)));
+      } else {
+        final RexLiteral constant = constants.get(indexInConstants);
+        LogicalExpression expr = DrillOptiq.toDrill(context, getInput(), constant);
+        args.add(expr);
       }
     }
 
@@ -123,6 +131,7 @@ public class WindowPrel extends DrillWindowRelBase implements Prel {
     if (args.isEmpty()) {
       args.add(new ValueExpressions.LongExpression(1l));
     }
+
     return new FunctionCall(call.getAggregation().getName().toLowerCase(), args, ExpressionPosition.UNKNOWN);
   }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/8f3dc0d1/exec/java-exec/src/test/java/org/apache/drill/exec/TestWindowFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/TestWindowFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/TestWindowFunctions.java
index 8676c28..7071bea 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/TestWindowFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/TestWindowFunctions.java
@@ -403,4 +403,24 @@ public class TestWindowFunctions extends BaseTestQuery {
       .build().run();
   }
 
-}
+  @Test // DRILL-3292
+  public void testWindowConstants() throws Exception {
+    String query = "select rank() over w fn, sum(2) over w sumINTEGER, sum(employee_id) over w sumEmpId, sum(0.5) over w sumFLOAT \n" +
+        "from cp.`employee.json` \n" +
+        "where position_id = 2 \n" +
+        "window w as(partition by position_id order by employee_id)";
+
+    testBuilder()
+        .sqlQuery(query)
+        .ordered()
+        .baselineColumns("fn", "sumINTEGER", "sumEmpId", "sumFLOAT")
+        .baselineValues(1l, 2l, 2l, 0.5)
+        .baselineValues(2l, 4l, 6l, 1.0)
+        .baselineValues(3l, 6l, 11l, 1.5)
+        .baselineValues(4l, 8l, 31l, 2.0)
+        .baselineValues(5l, 10l, 52l, 2.5)
+        .baselineValues(6l, 12l, 74l, 3.0)
+        .build()
+        .run();
+  }
+}
\ No newline at end of file