hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xu...@apache.org
Subject svn commit: r1604611 - in /hive/trunk: ql/src/test/queries/clientpositive/ ql/src/test/results/clientpositive/ serde/src/java/org/apache/hadoop/hive/serde2/lazy/
Date Sun, 22 Jun 2014 16:48:27 GMT
Author: xuefu
Date: Sun Jun 22 16:48:26 2014
New Revision: 1604611

URL: http://svn.apache.org/r1604611
Log:
HIVE-7234: Select on decimal column throws NPE (Ashish via Xuefu)

Added:
    hive/trunk/ql/src/test/queries/clientpositive/decimal_10_0.q
    hive/trunk/ql/src/test/results/clientpositive/decimal_10_0.q.out
Modified:
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyHiveDecimal.java
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java

Added: hive/trunk/ql/src/test/queries/clientpositive/decimal_10_0.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/decimal_10_0.q?rev=1604611&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/decimal_10_0.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/decimal_10_0.q Sun Jun 22 16:48:26 2014
@@ -0,0 +1,9 @@
+DROP TABLE IF EXISTS DECIMAL;
+
+CREATE TABLE DECIMAL (dec decimal);
+
+LOAD DATA LOCAL INPATH '../../data/files/decimal_10_0.txt' OVERWRITE INTO TABLE DECIMAL;
+
+SELECT dec FROM DECIMAL;
+
+DROP TABLE DECIMAL;
\ No newline at end of file

Added: hive/trunk/ql/src/test/results/clientpositive/decimal_10_0.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/decimal_10_0.q.out?rev=1604611&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/decimal_10_0.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/decimal_10_0.q.out Sun Jun 22 16:48:26 2014
@@ -0,0 +1,37 @@
+PREHOOK: query: DROP TABLE IF EXISTS DECIMAL
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: DROP TABLE IF EXISTS DECIMAL
+POSTHOOK: type: DROPTABLE
+PREHOOK: query: CREATE TABLE DECIMAL (dec decimal)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+POSTHOOK: query: CREATE TABLE DECIMAL (dec decimal)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@DECIMAL
+PREHOOK: query: LOAD DATA LOCAL INPATH '../../data/files/decimal_10_0.txt' OVERWRITE INTO
TABLE DECIMAL
+PREHOOK: type: LOAD
+#### A masked pattern was here ####
+PREHOOK: Output: default@decimal
+POSTHOOK: query: LOAD DATA LOCAL INPATH '../../data/files/decimal_10_0.txt' OVERWRITE INTO
TABLE DECIMAL
+POSTHOOK: type: LOAD
+#### A masked pattern was here ####
+POSTHOOK: Output: default@decimal
+PREHOOK: query: SELECT dec FROM DECIMAL
+PREHOOK: type: QUERY
+PREHOOK: Input: default@decimal
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT dec FROM DECIMAL
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@decimal
+#### A masked pattern was here ####
+1000000000
+NULL
+PREHOOK: query: DROP TABLE DECIMAL
+PREHOOK: type: DROPTABLE
+PREHOOK: Input: default@decimal
+PREHOOK: Output: default@decimal
+POSTHOOK: query: DROP TABLE DECIMAL
+POSTHOOK: type: DROPTABLE
+POSTHOOK: Input: default@decimal
+POSTHOOK: Output: default@decimal

Modified: hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyHiveDecimal.java
URL: http://svn.apache.org/viewvc/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyHiveDecimal.java?rev=1604611&r1=1604610&r2=1604611&view=diff
==============================================================================
--- hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyHiveDecimal.java (original)
+++ hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyHiveDecimal.java Sun
Jun 22 16:48:26 2014
@@ -17,6 +17,9 @@
  */
 package org.apache.hadoop.hive.serde2.lazy;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
 import java.nio.charset.CharacterCodingException;
 
 import org.apache.commons.logging.Log;
@@ -33,6 +36,7 @@ public class LazyHiveDecimal extends Laz
 
   private final int precision;
   private final int scale;
+  private static final byte[] nullBytes = new byte[]{0x0, 0x0, 0x0, 0x0};
 
   public LazyHiveDecimal(LazyHiveDecimalObjectInspector oi) {
     super(oi);
@@ -93,4 +97,19 @@ public class LazyHiveDecimal extends Laz
     return data;
   }
 
+  /**
+   * Writes HiveDecimal object to output stream as string
+   * @param outputStream
+   * @param hiveDecimal
+   * @throws IOException
+   */
+  public static void writeUTF8(OutputStream outputStream, HiveDecimal hiveDecimal)
+    throws IOException {
+    if (hiveDecimal == null) {
+      outputStream.write(nullBytes);
+    } else {
+      ByteBuffer b = Text.encode(hiveDecimal.toString());
+      outputStream.write(b.array(), 0, b.limit());
+    }
+  }
 }

Modified: hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java
URL: http://svn.apache.org/viewvc/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java?rev=1604611&r1=1604610&r2=1604611&view=diff
==============================================================================
--- hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java (original)
+++ hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyUtils.java Sun Jun 22
16:48:26 2014
@@ -28,7 +28,6 @@ import java.util.Arrays;
 import java.util.Properties;
 
 import org.apache.commons.codec.binary.Base64;
-import org.apache.hadoop.hive.common.type.HiveDecimal;
 import org.apache.hadoop.hive.serde.serdeConstants;
 import org.apache.hadoop.hive.serde2.SerDeException;
 import org.apache.hadoop.hive.serde2.io.HiveCharWritable;
@@ -261,9 +260,8 @@ public final class LazyUtils {
       break;
     }
     case DECIMAL: {
-      HiveDecimal bd = ((HiveDecimalObjectInspector) oi).getPrimitiveJavaObject(o);
-      ByteBuffer b = Text.encode(bd.toString());
-      out.write(b.array(), 0, b.limit());
+      LazyHiveDecimal.writeUTF8(out,
+        ((HiveDecimalObjectInspector) oi).getPrimitiveJavaObject(o));
       break;
     }
     default: {



Mime
View raw message