drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [01/17] git commit: DRILL-706, DRILL-524 : div and mod funnc bugfix DRILL-706, 524, 988: Review Comments DRILL-706, 524, 988: Added Testcase
Date Mon, 21 Jul 2014 02:46:23 GMT
Repository: incubator-drill
Updated Branches:
  refs/heads/master 699851b8d -> e5c2da0eb


DRILL-706, DRILL-524 : div and mod funnc bugfix DRILL-706,524,988: Review Comments DRILL-706,524,988:
Added Testcase


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

Branch: refs/heads/master
Commit: 1fb5840313327930d01374a5a47b3734b8a70299
Parents: 785aa5a
Author: Yash Sharma <yash.sharma@snapdeal.com>
Authored: Sat Jun 14 23:31:34 2014 +0530
Committer: Jacques Nadeau <jacques@apache.org>
Committed: Sun Jul 20 16:26:35 2014 -0700

----------------------------------------------------------------------
 .../src/main/codegen/data/MathFunc.tdd          | 10 +++---
 .../main/codegen/templates/MathFunctions.java   | 20 +++++++++--
 .../exec/fn/impl/TestNewMathFunctions.java      | 13 +++----
 .../functions/testDivModTruncFunctions.json     | 38 ++++++++++++++++++++
 4 files changed, 67 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1fb58403/exec/java-exec/src/main/codegen/data/MathFunc.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/MathFunc.tdd b/exec/java-exec/src/main/codegen/data/MathFunc.tdd
index cdce365..154836c 100644
--- a/exec/java-exec/src/main/codegen/data/MathFunc.tdd
+++ b/exec/java-exec/src/main/codegen/data/MathFunc.tdd
@@ -85,12 +85,12 @@ unaryMathFunctions : [
     {className: "Trunc", funcName: "trunc", types: [
       {input: "Int",  outputType: "Int", castType: "int"},
       {input: "BigInt",  outputType: "BigInt", castType: "long"},
-      {input: "Float4", outputType: "Float4", castType: "float"},
-      {input: "Float8", outputType: "Float8", castType: "double"},
+      {input: "Float4", outputType: "Float4", castType: "float", roundingRequired: "true"},
+      {input: "Float8", outputType: "Float8", castType: "double", roundingRequired: "true"},
       {input: "SmallInt",  outputType: "SmallInt", castType: "short"},
       {input: "TinyInt",  outputType: "TinyInt", castType: "byte"},
       {input: "UInt1", outputType: "UInt1", castType: "byte"},
-      {input: "UInt2", outputType: "UInt2", castType: "int", extraCast: "char"},
+      {input: "UInt2", outputType: "UInt2", castType: "char"},
       {input: "UInt4", outputType: "UInt4", castType: "int"},
       {input: "UInt8", outputType: "UInt8", castType: "long"}
      ]
@@ -113,8 +113,8 @@ unaryMathFunctions : [
     {className: "Div", funcName: "div", javaFunc : " / ", types: [
       {input: "Int",  outputType: "Int", castType: "int"},
       {input: "BigInt",  outputType: "BigInt", castType: "long"},
-      {input: "Float4", outputType: "Float4", castType: "float"},
-      {input: "Float8", outputType: "Float8", castType: "double"},
+      {input: "Float4", outputType: "Float4", castType: "float", roundingRequired: "true"},
+      {input: "Float8", outputType: "Float8", castType: "double", roundingRequired: "true"},
       {input: "SmallInt",  outputType: "SmallInt", castType: "short"},
       {input: "TinyInt",  outputType: "TinyInt", castType: "byte"},
       {input: "UInt1", outputType: "UInt1", castType: "byte"},

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1fb58403/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 8986b8a..30a71dd 100644
--- a/exec/java-exec/src/main/codegen/templates/MathFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/MathFunctions.java
@@ -69,10 +69,13 @@ public class GMathFunctions{
     public void eval() {
 
       <#if func.funcName=='trunc'>
-      java.math.BigDecimal bd = new java.math.BigDecimal(String.valueOf(in.value)).setScale(0,
java.math.BigDecimal.ROUND_DOWN);
+      <#if type.roundingRequired ??>
+      java.math.BigDecimal bd = java.math.BigDecimal.valueOf(in.value).setScale(0, java.math.BigDecimal.ROUND_DOWN);
       out.value = <#if type.extraCast ??>(${type.extraCast})</#if>bd.${type.castType}Value();
       <#else>
-      out.value =(${type.castType}) ${func.javaFunc}(in.value);
+      out.value = (${type.castType}) (in.value);</#if>
+      <#else>
+      out.value = (${type.castType}) ${func.javaFunc}(in.value);
       </#if>
     }
   }
@@ -99,7 +102,18 @@ public class GMathFunctions{
     }
 
     public void eval() {
-      out.value =(${type.castType}) ( input1.value ${func.javaFunc} input2.value);
+	<#if func.funcName == 'div'>
+	<#if type.roundingRequired ??>
+    java.math.BigDecimal bdOut = java.math.BigDecimal.valueOf(input1.value ${func.javaFunc}
input2.value).setScale(0, java.math.BigDecimal.ROUND_DOWN);
+    out.value = bdOut.${type.castType}Value();
+    <#else>
+    out.value = (${type.castType}) ( input1.value ${func.javaFunc} input2.value);
+    </#if>
+    <#elseif func.funcName == 'mod'>
+    out.value = (${type.castType}) (input2.value == 0 ? input1.value : (input1.value ${func.javaFunc}
input2.value));
+    <#else>
+    out.value =(${type.castType}) ( input1.value ${func.javaFunc} input2.value);
+    </#if>
     }
   }
   </#list>

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1fb58403/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java
index 3289601..328dd9c 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java
@@ -35,7 +35,6 @@ import org.apache.drill.exec.physical.base.FragmentRoot;
 import org.apache.drill.exec.physical.impl.ImplCreator;
 import org.apache.drill.exec.physical.impl.OperatorCreatorRegistry;
 import org.apache.drill.exec.physical.impl.SimpleRootExec;
-import org.apache.drill.exec.physical.impl.TestStringFunctions;
 import org.apache.drill.exec.planner.PhysicalPlanReader;
 import org.apache.drill.exec.proto.CoordinationProtos;
 import org.apache.drill.exec.proto.BitControl.PlanFragment;
@@ -96,14 +95,9 @@ public class TestNewMathFunctions {
 	      Object [] res = getRunResult(exec);
 	      assertEquals("return count does not match", res.length, expectedResults.length);
 
-	      System.out.println("-----------------------------------------------");
-	      System.out.println("ACTUAL_RESULTS\t\tEXPECTED_RESULTS");
-	      System.out.println("-----------------------------------------------");
 	      for (int i = 0; i<res.length; i++) {
-	      System.out.println(res[i] + "\t" + expectedResults[i]);
 	        assertEquals(String.format("column %s does not match", i),  res[i], expectedResults[i]);
 	      }
-	      System.out.println("-----------------------------------------------");
 	    }
 
 	    if(context.getFailureCause() != null){
@@ -129,4 +123,11 @@ public class TestNewMathFunctions {
 
 	    runTest(bitContext, connection, expected, "functions/testExtendedMathFunctions.json");
 	  }
+
+	  @Test
+	  public void testTruncDivMod(@Injectable final DrillbitContext bitContext,
+	                           @Injectable UserServer.UserClientConnection connection) throws
Throwable{
+	    Object [] expected = new Object[] {101.0, 0, 101, 1010.0, 101, 481.0, 0.001099999999931267};
+	    runTest(bitContext, connection, expected, "functions/testDivModTruncFunctions.json");
+	  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1fb58403/exec/java-exec/src/test/resources/functions/testDivModTruncFunctions.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/functions/testDivModTruncFunctions.json b/exec/java-exec/src/test/resources/functions/testDivModTruncFunctions.json
new file mode 100644
index 0000000..cf578c8
--- /dev/null
+++ b/exec/java-exec/src/test/resources/functions/testDivModTruncFunctions.json
@@ -0,0 +1,38 @@
+{
+  head : {
+    version : 1,
+    generator : {
+      type : "optiq",
+      info : "na"
+    },
+    type : "APACHE_DRILL_PHYSICAL"
+  },
+         graph:[
+         {
+             @id:1,
+             pop:"mock-sub-scan",
+             url: "http://apache.org",
+             entries:[
+                 {records: 1, types: [
+                   {name: "blue", type: "BIGINT", mode: "REQUIRED"}
+                 ]}
+             ]
+         }, {
+    pop : "project",
+    @id : 2,
+    exprs : [
+    { ref : "ref1", expr : " trunc(101.11) "},
+    { ref : "ref2", expr : " div(101, 111) "},
+    { ref : "ref3", expr : " mod(101, 111) " },
+    { ref : "ref4", expr : " trunc(1010.00) "},
+    { ref : "ref6", expr : " mod(101, 0) " },
+    { ref : "ref8", expr : " div(1010.1010, 2.1) "},
+    { ref : "ref9", expr : " mod(1010.10110, 2.1) " }
+    ],
+    child : 1
+  }, {
+    pop : "screen",
+    @id : 3,
+    child : 2
+  } ]
+}
\ No newline at end of file


Mime
View raw message