You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ec...@apache.org on 2012/06/13 17:37:33 UTC

svn commit: r1349907 - in /hive/trunk: ql/src/test/queries/clientpositive/timestamp_lazy.q ql/src/test/results/clientpositive/timestamp_lazy.q.out serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java

Author: ecapriolo
Date: Wed Jun 13 15:37:32 2012
New Revision: 1349907

URL: http://svn.apache.org/viewvc?rev=1349907&view=rev
Log:
HIVE-3090 Timestamp types not having nano-second part breaks row (Navis via egc)

Added:
    hive/trunk/ql/src/test/queries/clientpositive/timestamp_lazy.q
    hive/trunk/ql/src/test/results/clientpositive/timestamp_lazy.q.out
Modified:
    hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java

Added: hive/trunk/ql/src/test/queries/clientpositive/timestamp_lazy.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/timestamp_lazy.q?rev=1349907&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/timestamp_lazy.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/timestamp_lazy.q Wed Jun 13 15:37:32 2012
@@ -0,0 +1,6 @@
+drop table timestamp_lazy;
+create table timestamp_lazy (t timestamp, key string, value string);
+insert overwrite table timestamp_lazy select cast('2011-01-01 01:01:01' as timestamp), key, value from src limit 5;
+
+select t,key,value from timestamp_lazy;
+select t,key,value from timestamp_lazy distribute by t;
\ No newline at end of file

Added: hive/trunk/ql/src/test/results/clientpositive/timestamp_lazy.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/timestamp_lazy.q.out?rev=1349907&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/timestamp_lazy.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/timestamp_lazy.q.out Wed Jun 13 15:37:32 2012
@@ -0,0 +1,52 @@
+PREHOOK: query: drop table timestamp_lazy
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: drop table timestamp_lazy
+POSTHOOK: type: DROPTABLE
+PREHOOK: query: create table timestamp_lazy (t timestamp, key string, value string)
+PREHOOK: type: CREATETABLE
+POSTHOOK: query: create table timestamp_lazy (t timestamp, key string, value string)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: default@timestamp_lazy
+PREHOOK: query: insert overwrite table timestamp_lazy select cast('2011-01-01 01:01:01' as timestamp), key, value from src limit 5
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Output: default@timestamp_lazy
+POSTHOOK: query: insert overwrite table timestamp_lazy select cast('2011-01-01 01:01:01' as timestamp), key, value from src limit 5
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Output: default@timestamp_lazy
+POSTHOOK: Lineage: timestamp_lazy.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: timestamp_lazy.t EXPRESSION []
+POSTHOOK: Lineage: timestamp_lazy.value SIMPLE [(src)src.FieldSchema(name:value, type:string, comment:default), ]
+PREHOOK: query: select t,key,value from timestamp_lazy
+PREHOOK: type: QUERY
+PREHOOK: Input: default@timestamp_lazy
+#### A masked pattern was here ####
+POSTHOOK: query: select t,key,value from timestamp_lazy
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@timestamp_lazy
+#### A masked pattern was here ####
+POSTHOOK: Lineage: timestamp_lazy.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: timestamp_lazy.t EXPRESSION []
+POSTHOOK: Lineage: timestamp_lazy.value SIMPLE [(src)src.FieldSchema(name:value, type:string, comment:default), ]
+2011-01-01 01:01:01	238	val_238
+2011-01-01 01:01:01	86	val_86
+2011-01-01 01:01:01	311	val_311
+2011-01-01 01:01:01	27	val_27
+2011-01-01 01:01:01	165	val_165
+PREHOOK: query: select t,key,value from timestamp_lazy distribute by t
+PREHOOK: type: QUERY
+PREHOOK: Input: default@timestamp_lazy
+#### A masked pattern was here ####
+POSTHOOK: query: select t,key,value from timestamp_lazy distribute by t
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@timestamp_lazy
+#### A masked pattern was here ####
+POSTHOOK: Lineage: timestamp_lazy.key SIMPLE [(src)src.FieldSchema(name:key, type:string, comment:default), ]
+POSTHOOK: Lineage: timestamp_lazy.t EXPRESSION []
+POSTHOOK: Lineage: timestamp_lazy.value SIMPLE [(src)src.FieldSchema(name:value, type:string, comment:default), ]
+2011-01-01 01:01:01	238	val_238
+2011-01-01 01:01:01	86	val_86
+2011-01-01 01:01:01	311	val_311
+2011-01-01 01:01:01	27	val_27
+2011-01-01 01:01:01	165	val_165

Modified: hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java
URL: http://svn.apache.org/viewvc/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java?rev=1349907&r1=1349906&r2=1349907&view=diff
==============================================================================
--- hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java (original)
+++ hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java Wed Jun 13 15:37:32 2012
@@ -166,7 +166,7 @@ public class TimestampWritable implement
       return timestamp.getNanos();
     }
 
-    return TimestampWritable.getNanos(currentBytes, offset+4);
+    return hasDecimal() ? TimestampWritable.getNanos(currentBytes, offset+4) : 0;
   }
 
   /**
@@ -183,7 +183,7 @@ public class TimestampWritable implement
    */
   private int getDecimalLength() {
     checkBytes();
-    return WritableUtils.decodeVIntSize(currentBytes[offset+4]);
+    return hasDecimal() ? WritableUtils.decodeVIntSize(currentBytes[offset+4]) : 0;
   }
 
   public Timestamp getTimestamp() {
@@ -393,7 +393,7 @@ public class TimestampWritable implement
     long millis = t.getTime();
     int nanos = t.getNanos();
 
-    boolean hasDecimal = setNanosBytes(nanos, b, offset+4);
+    boolean hasDecimal = nanos != 0 && setNanosBytes(nanos, b, offset+4);
     setSecondsBytes(millis, b, offset, hasDecimal);
   }
 
@@ -471,8 +471,11 @@ public class TimestampWritable implement
   }
 
   public static void setTimestamp(Timestamp t, byte[] bytes, int offset) {
+    boolean hasDecimal = hasDecimal(bytes[offset]);
     t.setTime(((long) TimestampWritable.getSeconds(bytes, offset)) * 1000);
-    t.setNanos(TimestampWritable.getNanos(bytes, offset+4));
+    if (hasDecimal) {
+      t.setNanos(TimestampWritable.getNanos(bytes, offset+4));
+    }
   }
 
   public static Timestamp createTimestamp(byte[] bytes, int offset) {
@@ -481,6 +484,10 @@ public class TimestampWritable implement
     return t;
   }
 
+  public boolean hasDecimal() {
+    return hasDecimal(currentBytes[offset]);
+  }
+
   /**
    *
    * @param b first byte in an encoded TimestampWritable