You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ji...@apache.org on 2014/03/17 23:14:00 UTC

svn commit: r1578627 - in /hive/branches/branch-0.13: common/src/java/org/apache/hadoop/hive/common/type/ common/src/test/org/apache/hadoop/hive/common/type/ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ ql/src/java/org/apache/hadoop/h...

Author: jitendra
Date: Mon Mar 17 22:13:59 2014
New Revision: 1578627

URL: http://svn.apache.org/r1578627
Log:
HIVE-6680. Decimal128#update(Decimal128 o, short scale) should adjust the unscaled value. (jitendra, reviewed by Remus Rusanu)

Modified:
    hive/branches/branch-0.13/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java
    hive/branches/branch-0.13/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java
    hive/branches/branch-0.13/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/MathExpr.java
    hive/branches/branch-0.13/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java

Modified: hive/branches/branch-0.13/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java
URL: http://svn.apache.org/viewvc/hive/branches/branch-0.13/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java?rev=1578627&r1=1578626&r2=1578627&view=diff
==============================================================================
--- hive/branches/branch-0.13/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java (original)
+++ hive/branches/branch-0.13/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java Mon Mar 17 22:13:59 2014
@@ -261,7 +261,9 @@ public final class Decimal128 extends Nu
    *          object to copy from
    */
   public Decimal128 update(Decimal128 o) {
-    update(o, o.scale);
+    this.unscaledValue.update(o.unscaledValue);
+    this.scale = o.scale;
+    this.signum = o.signum;
     return this;
   }
 
@@ -272,9 +274,8 @@ public final class Decimal128 extends Nu
    *          object to copy from
    */
   public Decimal128 update(Decimal128 o, short scale) {
-    this.unscaledValue.update(o.unscaledValue);
-    this.scale = scale;
-    this.signum = o.signum;
+    update(o);
+    this.changeScaleDestructive(scale);
     return this;
   }
 

Modified: hive/branches/branch-0.13/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java
URL: http://svn.apache.org/viewvc/hive/branches/branch-0.13/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java?rev=1578627&r1=1578626&r2=1578627&view=diff
==============================================================================
--- hive/branches/branch-0.13/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java (original)
+++ hive/branches/branch-0.13/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java Mon Mar 17 22:13:59 2014
@@ -854,4 +854,12 @@ public class TestDecimal128 {
     assertEquals(hd7.toString(), d12.getHiveDecimalString());
     assertEquals("27", hd7.toString());
   }
+
+  @Test
+  public void testUpdateWithScale() {
+    Decimal128 d1 = new Decimal128(1234.123, (short)4);
+    Decimal128 d2 = new Decimal128(0, (short)3);
+    d2.update(d1, (short)3);
+    assertEquals(0, d1.compareTo(d2));
+  }
 }

Modified: hive/branches/branch-0.13/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/MathExpr.java
URL: http://svn.apache.org/viewvc/hive/branches/branch-0.13/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/MathExpr.java?rev=1578627&r1=1578626&r2=1578627&view=diff
==============================================================================
--- hive/branches/branch-0.13/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/MathExpr.java (original)
+++ hive/branches/branch-0.13/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/MathExpr.java Mon Mar 17 22:13:59 2014
@@ -46,11 +46,23 @@ public class MathExpr {
   }
 
   public static double sign(double v) {
-    return v >= 0 ? 1.0 : -1.0;
+    if (v == 0) {
+      return 0;
+    } else if (v > 0) {
+      return 1.0;
+    } else {
+      return -1.0;
+    }
   }
 
   public static double sign(long v) {
-    return v >= 0 ? 1.0 : -1.0;
+    if (v == 0) {
+      return 0;
+    } else if (v > 0) {
+      return 1.0;
+    } else {
+      return -1.0;
+    }
   }
 
   // for casting integral types to boolean

Modified: hive/branches/branch-0.13/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java
URL: http://svn.apache.org/viewvc/hive/branches/branch-0.13/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java?rev=1578627&r1=1578626&r2=1578627&view=diff
==============================================================================
--- hive/branches/branch-0.13/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java (original)
+++ hive/branches/branch-0.13/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java Mon Mar 17 22:13:59 2014
@@ -303,15 +303,15 @@ public class VectorUDAFSumDecimal extend
       Decimal128[] vector = inputVector.vector;
 
       if (inputVector.isRepeating) {
-        if (inputVector.noNulls) {
-        if (myagg.isNull) {
-          myagg.isNull = false;
-          myagg.sum.zeroClear();
+        if ((inputVector.noNulls) || !inputVector.isNull[0]) {
+          if (myagg.isNull) {
+            myagg.isNull = false;
+            myagg.sum.zeroClear();
+          }
+          scratchDecimal.update(batchSize);
+          scratchDecimal.multiplyDestructive(vector[0], inputVector.scale);
+          myagg.sum.addDestructive(scratchDecimal, inputVector.scale);
         }
-        scratchDecimal.update(batchSize);
-        scratchDecimal.multiplyDestructive(vector[0], inputVector.scale);
-        myagg.sum.update(scratchDecimal);
-      }
         return;
       }