drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meh...@apache.org
Subject [2/2] drill git commit: DRILL-3719: Expand -expression as -1 * expression in visitCall of DrillOptiq
Date Mon, 31 Aug 2015 20:24:44 GMT
DRILL-3719: Expand -expression as -1 * expression in visitCall of DrillOptiq


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

Branch: refs/heads/master
Commit: bcc01c05a4d593b1f9226121e64930251586b304
Parents: dfa47da
Author: Hsuan-Yi Chu <hsuanyi@usc.edu>
Authored: Fri Aug 28 10:33:01 2015 -0700
Committer: Mehant Baid <mehantr@gmail.com>
Committed: Sun Aug 30 21:43:14 2015 -0700

----------------------------------------------------------------------
 .../drill/exec/planner/logical/DrillOptiq.java  | 17 +++++++++++++----
 .../org/apache/drill/TestExampleQueries.java    | 20 ++++++++++++++++++++
 2 files changed, 33 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/bcc01c05/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
index 11b9c9e..43d8b6b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
@@ -41,6 +41,7 @@ import org.apache.drill.common.types.Types;
 import org.apache.drill.exec.planner.StarColumnHelper;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
 import org.apache.calcite.rex.RexCall;
 import org.apache.calcite.rex.RexCorrelVariable;
 import org.apache.calcite.rex.RexDynamicParam;
@@ -123,9 +124,18 @@ public class DrillOptiq {
         logger.debug("Prefix");
         LogicalExpression arg = call.getOperands().get(0).accept(this);
         switch(call.getKind()){
-        case NOT:
-          return FunctionCallFactory.createExpression(call.getOperator().getName().toLowerCase(),
-            ExpressionPosition.UNKNOWN, arg);
+          case NOT:
+            return FunctionCallFactory.createExpression(call.getOperator().getName().toLowerCase(),
+                ExpressionPosition.UNKNOWN, arg);
+          case MINUS_PREFIX:
+            final RexBuilder builder = input.getCluster().getRexBuilder();
+            final List<RexNode> operands = Lists.newArrayList();
+            operands.add(builder.makeExactLiteral(new BigDecimal(-1)));
+            operands.add(call.getOperands().get(0));
+
+            return visitCall((RexCall) builder.makeCall(
+                SqlStdOperatorTable.MULTIPLY,
+                    operands));
         }
         throw new AssertionError("todo: implement syntax " + syntax + "(" + call + ")");
       case SPECIAL:
@@ -243,7 +253,6 @@ public class DrillOptiq {
       return super.visitFieldAccess(fieldAccess);
     }
 
-
     private LogicalExpression getDrillCastFunctionFromOptiq(RexCall call){
       LogicalExpression arg = call.getOperands().get(0).accept(this);
       MajorType castType = null;

http://git-wip-us.apache.org/repos/asf/drill/blob/bcc01c05/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
index 6b74ecf..d15cff2 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
@@ -1101,4 +1101,24 @@ public class TestExampleQueries extends BaseTestQuery {
     test(query1);
     test(query2);
   }
+
+  @Test
+  public void testNegativeExtractOperator() throws Exception {
+    String query = "select -EXTRACT(DAY FROM birth_date) as col \n" +
+        "from cp.`employee.json` \n" +
+        "order by col \n" +
+        "limit 5";
+
+    testBuilder()
+        .sqlQuery(query)
+        .ordered()
+        .baselineColumns("col")
+        .baselineValues(-27l)
+        .baselineValues(-27l)
+        .baselineValues(-27l)
+        .baselineValues(-26l)
+        .baselineValues(-26l)
+        .build()
+        .run();
+  }
 }


Mime
View raw message