Index: serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java =================================================================== --- serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java (revision 1349642) +++ serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java (working copy) @@ -166,7 +166,7 @@ return timestamp.getNanos(); } - return TimestampWritable.getNanos(currentBytes, offset+4); + return hasDecimal() ? TimestampWritable.getNanos(currentBytes, offset+4) : 0; } /** @@ -183,7 +183,7 @@ */ 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 @@ 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 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 @@ return t; } + public boolean hasDecimal() { + return hasDecimal(currentBytes[offset]); + } + /** * * @param b first byte in an encoded TimestampWritable Index: ql/src/test/results/clientpositive/timestamp_lazy.q.out =================================================================== --- ql/src/test/results/clientpositive/timestamp_lazy.q.out (revision 0) +++ ql/src/test/results/clientpositive/timestamp_lazy.q.out (revision 0) @@ -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 Index: ql/src/test/queries/clientpositive/timestamp_lazy.q =================================================================== --- ql/src/test/queries/clientpositive/timestamp_lazy.q (revision 0) +++ ql/src/test/queries/clientpositive/timestamp_lazy.q (revision 0) @@ -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