hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xu...@apache.org
Subject svn commit: r1598989 - in /hive/trunk: common/src/test/org/apache/hadoop/hive/common/type/ data/files/ ql/src/java/org/apache/hadoop/hive/ql/io/parquet/serde/ ql/src/test/results/clientpositive/
Date Sun, 01 Jun 2014 14:28:54 GMT
Author: xuefu
Date: Sun Jun  1 14:28:54 2014
New Revision: 1598989

URL: http://svn.apache.org/r1598989
Log:
HIVE-7149: Parquet not able to handle negative decimal numbers (reviewed by Brock)

Modified:
    hive/trunk/common/src/test/org/apache/hadoop/hive/common/type/TestHiveDecimal.java
    hive/trunk/data/files/dec.txt
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/io/parquet/serde/ParquetHiveSerDe.java
    hive/trunk/ql/src/test/results/clientpositive/avro_decimal.q.out
    hive/trunk/ql/src/test/results/clientpositive/parquet_decimal.q.out

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=1598989&r1=1598988&r2=1598989&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 Sun
Jun  1 14:28:54 2014
@@ -121,13 +121,23 @@ public class TestHiveDecimal {
 
   @Test
   public void testBinaryConversion() {
-    HiveDecimal dec = HiveDecimal.create("234.79");
+    testBinaryConversion("0.0");
+    testBinaryConversion("-12.25");
+    testBinaryConversion("234.79");
+  }
+
+  private void testBinaryConversion(String num) {
+    HiveDecimal dec = HiveDecimal.create(num);
     int scale = 2;
     byte[] d = dec.setScale(2).unscaledValue().toByteArray();
     Assert.assertEquals(dec, HiveDecimal.create(new BigInteger(d), scale));
     int prec = 5;
-    int len =  (int) (Math.ceil((Math.log(Math.pow(10, prec)) - 1)/Math.log(2) + 1) / 8);
+    int len =  (int)
+        Math.ceil((Math.log(Math.pow(10, prec) - 1) / Math.log(2) + 1) / 8);
     byte[] res = new byte[len];
+    if ( dec.signum() == -1)
+      for (int i = 0; i < len; i++)
+        res[i] |= 0xFF;
     System.arraycopy(d, 0, res, len-d.length, d.length); // Padding leading zeros.
     Assert.assertEquals(dec, HiveDecimal.create(new BigInteger(res), scale));
   }

Modified: hive/trunk/data/files/dec.txt
URL: http://svn.apache.org/viewvc/hive/trunk/data/files/dec.txt?rev=1598989&r1=1598988&r2=1598989&view=diff
==============================================================================
--- hive/trunk/data/files/dec.txt (original)
+++ hive/trunk/data/files/dec.txt Sun Jun  1 14:28:54 2014
@@ -3,8 +3,8 @@ Beck77.341
 Snow55.71
 Mary4.329
 Cluck5.96
-Tom12.25
+Tom-12.25
 Mary33.33
 Tom19.00
-Beck3.145
+Beck0.0
 Beck79.9

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/io/parquet/serde/ParquetHiveSerDe.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/io/parquet/serde/ParquetHiveSerDe.java?rev=1598989&r1=1598988&r2=1598989&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/io/parquet/serde/ParquetHiveSerDe.java
(original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/io/parquet/serde/ParquetHiveSerDe.java
Sun Jun  1 14:28:54 2014
@@ -264,7 +264,13 @@ public class ParquetHiveSerDe extends Ab
         return new BinaryWritable(Binary.fromByteArray(src));
       }
       byte[] tgt = new byte[bytes];
-      System.arraycopy(src, 0, tgt, bytes - src.length, src.length); // Padding leading zeroes.
+      if ( hd.signum() == -1) {
+        // For negative number, initializing bits to 1
+        for (int i = 0; i < bytes; i++) {
+          tgt[i] |= 0xFF;
+        }
+      }
+      System.arraycopy(src, 0, tgt, bytes - src.length, src.length); // Padding leading zeroes/ones.
       return new BinaryWritable(Binary.fromByteArray(tgt));
     default:
       throw new SerDeException("Unknown primitive : " + inspector.getPrimitiveCategory());

Modified: hive/trunk/ql/src/test/results/clientpositive/avro_decimal.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/avro_decimal.q.out?rev=1598989&r1=1598988&r2=1598989&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/avro_decimal.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/avro_decimal.q.out Sun Jun  1 14:28:54 2014
@@ -85,10 +85,10 @@ Beck	77.34
 Snow	55.71
 Mary	4.33
 Cluck	5.96
-Tom	12.25
+Tom	-12.25
 Mary	33.33
 Tom	19
-Beck	3.15
+Beck	0
 Beck	79.9
 PREHOOK: query: DROP TABLE IF EXISTS avro_dec1
 PREHOOK: type: DROPTABLE

Modified: hive/trunk/ql/src/test/results/clientpositive/parquet_decimal.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/parquet_decimal.q.out?rev=1598989&r1=1598988&r2=1598989&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/parquet_decimal.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/parquet_decimal.q.out Sun Jun  1 14:28:54
2014
@@ -59,10 +59,10 @@ Beck	77.34
 Snow	55.71
 Mary	4.33
 Cluck	5.96
-Tom	12.25
+Tom	-12.25
 Mary	33.33
 Tom	19
-Beck	3.15
+Beck	0
 Beck	79.9
 PREHOOK: query: TRUNCATE TABLE parq_dec
 PREHOOK: type: TRUNCATETABLE



Mime
View raw message