You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by xu...@apache.org on 2014/09/08 05:35:56 UTC

svn commit: r1623261 - in /hive/trunk/common/src: java/org/apache/hadoop/hive/common/type/HiveDecimal.java test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java

Author: xuefu
Date: Mon Sep  8 03:35:56 2014
New Revision: 1623261

URL: http://svn.apache.org/r1623261
Log:
HIVE-8008: NPE while reading null decimal value (Chao via Xuefu)

Modified:
    hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java
    hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java?rev=1623261&r1=1623260&r2=1623261&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java Mon Sep  8 03:35:56 2014
@@ -254,16 +254,16 @@ public class HiveDecimal implements Comp
       return null;
     }
 
+    if (bd.scale() > maxScale) {
+      bd = bd.setScale(maxScale, RoundingMode.HALF_UP);
+    }
+
     int maxIntDigits = maxPrecision - maxScale;
     int intDigits = bd.precision() - bd.scale();
     if (intDigits > maxIntDigits) {
       return null;
     }
 
-    if (bd.scale() > maxScale) {
-      bd = bd.setScale(maxScale, RoundingMode.HALF_UP);
-    }
-
     return bd;
   }
 }

Modified: hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java?rev=1623261&r1=1623260&r2=1623261&view=diff
==============================================================================
--- hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java (original)
+++ hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java Mon Sep  8 03:35:56 2014
@@ -68,6 +68,13 @@ public class TestHiveDecimal {
     Assert.assertEquals("0.02", HiveDecimal.enforcePrecisionScale(new BigDecimal("0.015"), 3, 2).toString());
     Assert.assertEquals("0.01", HiveDecimal.enforcePrecisionScale(new BigDecimal("0.0145"), 3, 2).toString());
 
+    // Rounding numbers that increase int digits
+    Assert.assertEquals("10",
+        HiveDecimal.enforcePrecisionScale(new BigDecimal("9.5"), 2, 0).toString());
+    Assert.assertNull(HiveDecimal.enforcePrecisionScale(new BigDecimal("9.5"), 1, 0));
+    Assert.assertEquals("9",
+        HiveDecimal.enforcePrecisionScale(new BigDecimal("9.4"), 1, 0).toString());
+
     // Integers with no scale values are not modified (zeros are not null)
     Assert.assertEquals("0", HiveDecimal.enforcePrecisionScale(new BigDecimal("0"), 1, 0).toString());
     Assert.assertEquals("30", HiveDecimal.enforcePrecisionScale(new BigDecimal("30"), 2, 0).toString());