drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [5/8] git commit: DRILL-730: Initialize the buffer while creating sparse representation from BigDecimal
Date Tue, 08 Jul 2014 01:01:17 GMT
DRILL-730: Initialize the buffer while creating sparse representation from BigDecimal


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

Branch: refs/heads/master
Commit: ae7387519cac382f2e1789c00b7f843ca0b28a5b
Parents: e1cf5c2
Author: Mehant Baid <mehantr@gmail.com>
Authored: Sun Jul 6 19:02:56 2014 -0700
Committer: Jacques Nadeau <jacques@apache.org>
Committed: Mon Jul 7 14:50:32 2014 -0700

----------------------------------------------------------------------
 .../apache/drill/common/util/DecimalUtility.java  |  5 +++++
 .../templates/Decimal/CastFloatDecimal.java       | 10 +---------
 .../Decimal/DecimalAggrTypeFunctions1.java        |  3 ---
 .../Decimal/DecimalAggrTypeFunctions2.java        |  3 ---
 .../templates/Decimal/DecimalFunctions.java       | 18 ------------------
 5 files changed, 6 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ae738751/common/src/main/java/org/apache/drill/common/util/DecimalUtility.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/util/DecimalUtility.java b/common/src/main/java/org/apache/drill/common/util/DecimalUtility.java
index 465cf82..8311d82 100644
--- a/common/src/main/java/org/apache/drill/common/util/DecimalUtility.java
+++ b/common/src/main/java/org/apache/drill/common/util/DecimalUtility.java
@@ -268,6 +268,11 @@ public class DecimalUtility {
      */
     public static void getSparseFromBigDecimal(BigDecimal input, ByteBuf data, int startIndex,
int scale, int precision, int nDecimalDigits) {
 
+        // Initialize the buffer
+        for (int i = 0; i < nDecimalDigits; i++) {
+          data.setInt(startIndex + (i * integerSize), 0);
+        }
+
         boolean sign = false;
 
         if (input.signum() == -1) {

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ae738751/exec/java-exec/src/main/codegen/templates/Decimal/CastFloatDecimal.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastFloatDecimal.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastFloatDecimal.java
index 903634b..f4a5c77 100644
--- a/exec/java-exec/src/main/codegen/templates/Decimal/CastFloatDecimal.java
+++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastFloatDecimal.java
@@ -70,15 +70,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc {
         out.start = 0;
         out.buffer = buffer;
 
-        // Initialize the buffer
-        for (int i = 0; i < ${type.arraySize}; i++) {
-            out.setInteger(i, 0);
-        }
-
-        if (in.value < 0) {
-            out.setSign(true);
-        }
-        // Assign the integer part of the decimal to the output holder
+       // Assign the integer part of the decimal to the output holder
         org.apache.drill.common.util.DecimalUtility.getSparseFromBigDecimal(new java.math.BigDecimal(String.valueOf(in.value)),
out.buffer, out.start, out.scale, out.precision, out.nDecimalDigits);
 
         <#elseif type.to.endsWith("Decimal9")>

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ae738751/exec/java-exec/src/main/codegen/templates/Decimal/DecimalAggrTypeFunctions1.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalAggrTypeFunctions1.java
b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalAggrTypeFunctions1.java
index f284a19..8588f76 100644
--- a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalAggrTypeFunctions1.java
+++ b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalAggrTypeFunctions1.java
@@ -184,9 +184,6 @@ public static class ${type.inputType}${aggrtype.className} implements
DrillAggFu
     out.start  = 0;
     out.scale = outputScale;
     out.precision = 38;
-    for (int i = 0; i < out.nDecimalDigits; i++) {
-      out.setInteger(i, 0);
-    }
     value = value.setScale(out.scale, java.math.BigDecimal.ROUND_HALF_UP);
     org.apache.drill.common.util.DecimalUtility.getSparseFromBigDecimal(value, out.buffer,
out.start, out.scale, out.precision, out.nDecimalDigits);
     <#else>

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ae738751/exec/java-exec/src/main/codegen/templates/Decimal/DecimalAggrTypeFunctions2.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalAggrTypeFunctions2.java
b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalAggrTypeFunctions2.java
index 60d708a..f036655 100644
--- a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalAggrTypeFunctions2.java
+++ b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalAggrTypeFunctions2.java
@@ -100,9 +100,6 @@ public static class ${type.inputType}${aggrtype.className} implements
DrillAggFu
     out.start  = 0;
     out.scale = outputScale;
     out.precision = 38;
-    for (int i = 0; i < out.nDecimalDigits; i++) {
-      out.setInteger(i, 0);
-    }
     java.math.BigDecimal average = value.divide(java.math.BigDecimal.valueOf(count.value,
0), out.scale, java.math.BigDecimal.ROUND_HALF_UP);
     org.apache.drill.common.util.DecimalUtility.getSparseFromBigDecimal(average, out.buffer,
out.start, out.scale, out.precision, out.nDecimalDigits);
   }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ae738751/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
index b5a69f1..2118cab 100644
--- a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
+++ b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java
@@ -287,10 +287,6 @@ public class ${type.name}Functions {
             result.buffer = buffer;
             result.start = 0;
 
-            // Re initialize the buffer everytime
-            for (int i = 0; i < ${type.storage}; i++) {
-                result.setInteger(i, 0);
-            }
             java.math.BigDecimal leftInput = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromSparse(left.buffer,
left.start, left.nDecimalDigits, left.scale);
             java.math.BigDecimal rightInput = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromSparse(right.buffer,
right.start, right.nDecimalDigits, right.scale);
             java.math.BigDecimal addResult = leftInput.subtract(rightInput);
@@ -330,10 +326,6 @@ public class ${type.name}Functions {
             result.buffer = buffer;
             result.start = 0;
 
-            // Re initialize the buffer everytime
-            for (int i = 0; i < ${type.storage}; i++) {
-                result.setInteger(i, 0);
-            }
             java.math.BigDecimal leftInput = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromSparse(left.buffer,
left.start, left.nDecimalDigits, left.scale);
             java.math.BigDecimal rightInput = org.apache.drill.common.util.DecimalUtility.getBigDecimalFromSparse(right.buffer,
right.start, right.nDecimalDigits, right.scale);
             java.math.BigDecimal addResult = leftInput.add(rightInput);
@@ -547,11 +539,6 @@ public class ${type.name}Functions {
 
             java.math.BigDecimal output = numerator.divide(denominator, (int) result.scale,
java.math.BigDecimal.ROUND_DOWN);
 
-            // Initialize the result buffer
-            for (int i = 0; i < ${type.storage}; i++) {
-                result.setInteger(i, 0);
-            }
-
             org.apache.drill.common.util.DecimalUtility.getSparseFromBigDecimal(output, result.buffer,
result.start, result.scale, result.precision, result.nDecimalDigits);
         }
     }
@@ -591,11 +578,6 @@ public class ${type.name}Functions {
             java.math.BigDecimal output = numerator.remainder(denominator);
             output.setScale(result.scale, java.math.BigDecimal.ROUND_DOWN);
 
-            // Initialize the result buffer
-            for (int i = 0; i < ${type.storage}; i++) {
-                result.setInteger(i, 0);
-            }
-
             org.apache.drill.common.util.DecimalUtility.getSparseFromBigDecimal(output, result.buffer,
result.start, result.scale, result.precision, result.nDecimalDigits);
         }
     }


Mime
View raw message