hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jiten...@apache.org
Subject svn commit: r1578597 - in /hive/trunk: 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/hive/ql/exec/vec...
Date Mon, 17 Mar 2014 21:27:46 GMT
Author: jitendra
Date: Mon Mar 17 21:27:46 2014
New Revision: 1578597

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

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

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java?rev=1578597&r1=1578596&r2=1578597&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java Mon Mar
17 21:27:46 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/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java?rev=1578597&r1=1578596&r2=1578597&view=diff
==============================================================================
--- hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java (original)
+++ hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java Mon
Mar 17 21:27:46 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/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/MathExpr.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/MathExpr.java?rev=1578597&r1=1578596&r2=1578597&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/MathExpr.java
(original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/MathExpr.java
Mon Mar 17 21:27:46 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/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java?rev=1578597&r1=1578596&r2=1578597&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java
(original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/aggregates/VectorUDAFSumDecimal.java
Mon Mar 17 21:27:46 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;
       }
 



Mime
View raw message