DRILL-1391 : Fix compilation error in run-time generated code for several math 
functions over decimal types.


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

Branch: refs/heads/smp-merge-230914
Commit: 8b8d78726e3f33b3f57ab9110bd551a7690f0ed7
Parents: 0988c08
Author: Jinfeng Ni <j...@maprtech.com>
Authored: Mon Sep 8 15:37:08 2014 -0700
Committer: Steven Phillips <sphill...@maprtech.com>
Committed: Tue Sep 23 22:22:52 2014 -0700

----------------------------------------------------------------------
 .../main/codegen/templates/MathFunctions.java   |  6 +--
 .../drill/exec/physical/impl/TestDecimal.java   | 35 +++++++++++++++++
 .../resources/decimal/simple_decimal_math.json  | 41 ++++++++++++++++++++
 3 files changed, 78 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/8b8d7872/exec/java-exec/src/main/codegen/templates/MathFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/MathFunctions.java 
b/exec/java-exec/src/main/codegen/templates/MathFunctions.java
index 30a71dd..fa5f1ac 100644
--- a/exec/java-exec/src/main/codegen/templates/MathFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/MathFunctions.java
@@ -29,7 +29,6 @@
 
 package org.apache.drill.exec.expr.fn.impl;
 
-import java.math.BigDecimal;
 
 import org.apache.drill.common.types.TypeProtos;
 import org.apache.drill.common.types.Types;
@@ -174,7 +173,6 @@ import org.apache.drill.exec.expr.annotations.Workspace;
 import org.apache.drill.exec.expr.fn.impl.StringFunctions;
 import org.apache.drill.exec.expr.holders.*;
 import org.apache.drill.exec.record.RecordBatch;
-import java.math.BigDecimal;
 /*
  * This class is automatically generated from MathFunc.tdd using FreeMarker.
  */
@@ -205,7 +203,7 @@ public static class ${func.className}${type.input} 
implements DrillSimpleFunc {
 
   public void eval() {
          <#if type.input?matches("^Decimal[1-9]*")>
-         double dblval = new 
BigDecimal(in.value).setScale(in.scale).doubleValue();
+         double dblval = new 
java.math.BigDecimal(in.value).setScale(in.scale).doubleValue();
          out.value = ${func.javaFunc}(dblval);
          <#else>
          out.value = ${func.javaFunc}(in.value);
@@ -235,7 +233,7 @@ public static class ${func.className}${type.input} 
implements DrillSimpleFunc {
 
   public void eval() {
          <#if type.input?matches("^Decimal[1-9]*")>
-         double dblval = new 
BigDecimal(val.value).setScale(val.scale).doubleValue();
+         double dblval = new 
java.math.BigDecimal(val.value).setScale(val.scale).doubleValue();
          out.value = ${func.javaFunc}(dblval)/ ${func.javaFunc}(base.value);
          <#else>
          out.value = ${func.javaFunc}(val.value)/ ${func.javaFunc}(base.value);

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/8b8d7872/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestDecimal.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestDecimal.java
 
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestDecimal.java
index 780e20e..5357a13 100644
--- 
a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestDecimal.java
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestDecimal.java
@@ -276,4 +276,39 @@ public class TestDecimal extends PopUnitTestBase{
             }
         }
     }
+
+  @Test
+  public void testSimpleDecimalMathFunc() throws Exception {
+
+    try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
+         Drillbit bit = new Drillbit(CONFIG, serviceSet);
+         DrillClient client = new DrillClient(CONFIG, 
serviceSet.getCoordinator())) {
+
+      // run query.
+      bit.run();
+      client.connect();
+      List<QueryResultBatch> results = 
client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL,
+          
Files.toString(FileUtils.getResourceAsFile("/decimal/simple_decimal_math.json"),
 Charsets.UTF_8)
+              .replace("#{TEST_FILE}", "/input_simple_decimal.json")
+      );
+
+      RecordBatchLoader batchLoader = new 
RecordBatchLoader(bit.getContext().getAllocator());
+
+      QueryResultBatch batch = results.get(0);
+      assertTrue(batchLoader.load(batch.getHeader().getDef(), 
batch.getData()));
+
+      Iterator<VectorWrapper<?>> itr = batchLoader.iterator();
+
+      // Check the output of decimal18
+      ValueVector.Accessor dec18Accessor = 
itr.next().getValueVector().getAccessor();
+
+      assertEquals(6, dec18Accessor.getValueCount());
+
+      batchLoader.clear();
+      for (QueryResultBatch result : results) {
+        result.release();
+      }
+    }
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/8b8d7872/exec/java-exec/src/test/resources/decimal/simple_decimal_math.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/decimal/simple_decimal_math.json 
b/exec/java-exec/src/test/resources/decimal/simple_decimal_math.json
new file mode 100644
index 0000000..42fd78e
--- /dev/null
+++ b/exec/java-exec/src/test/resources/decimal/simple_decimal_math.json
@@ -0,0 +1,41 @@
+{
+  "head" : {
+    "version" : 1,
+    "generator" : {
+      "type" : "org.apache.drill.exec.planner.logical.DrillImplementor",
+      "info" : ""
+    },
+    "type" : "APACHE_DRILL_PHYSICAL",
+    "resultMode" : "EXEC"
+  },
+  graph:[
+  {
+      @id:1,
+      pop:"fs-scan",
+      format: {type: "json"},
+      storage:{type: "file", connection: "classpath:///"},
+      files:["#{TEST_FILE}"]
+  }, {
+    "pop" : "project",
+    "@id" : 2,
+    "exprs" : [
+    { "ref" : "DECIMAL_18", "expr": "log((cast(DEC18 as decimal18(18, 9))))" }
+    ],
+
+    "child" : 1
+  },
+{
+    "pop" : "project",
+    "@id" : 4,
+    "exprs" : [
+    {"ref": "DECIMAL_18", "expr" : "cast(DECIMAL_18 as varchar(100))"}
+    ],
+
+    "child" : 2
+  },
+{
+    "pop" : "screen",
+    "@id" : 5,
+    "child" : 4
+  } ]
+}
\ No newline at end of file

Reply via email to