diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java b/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java index b90e576..ef7ad78 100644 --- a/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java +++ b/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java @@ -552,20 +552,9 @@ public static Timestamp longToTimestamp(long time, boolean intToTimestampInSecon } public static void setTimestamp(Timestamp t, byte[] bytes, int offset) { - boolean hasDecimalOrSecondVInt = hasDecimalOrSecondVInt(bytes[offset]); - long seconds = (long) TimestampWritable.getSeconds(bytes, offset); - int nanos = 0; - if (hasDecimalOrSecondVInt) { - nanos = TimestampWritable.getNanos(bytes, offset + 4); - if (hasSecondVInt(bytes[offset + 4])) { - seconds += LazyBinaryUtils.readVLongFromByteArray(bytes, - offset + 4 + WritableUtils.decodeVIntSize(bytes[offset + 4])); - } - } + long seconds = getSeconds(bytes, offset); t.setTime(seconds * 1000); - if (nanos != 0) { - t.setNanos(nanos); - } + t.setNanos(getNanos(bytes, offset + 4)); } public static Timestamp createTimestamp(byte[] bytes, int offset) { diff --git a/serde/src/test/org/apache/hadoop/hive/serde2/io/TestTimestampWritable.java b/serde/src/test/org/apache/hadoop/hive/serde2/io/TestTimestampWritable.java index 7619efa..cd7a1b9 100644 --- a/serde/src/test/org/apache/hadoop/hive/serde2/io/TestTimestampWritable.java +++ b/serde/src/test/org/apache/hadoop/hive/serde2/io/TestTimestampWritable.java @@ -493,4 +493,15 @@ public void testBinarySortable() { } } + @Test + public void testSetTimestamp() { + // make sure we need a 2nd VInt + Timestamp t1 = new Timestamp((long) Integer.MAX_VALUE * 1000 + 1234); + TimestampWritable writable = new TimestampWritable(t1); + byte[] bytes = writable.getBytes(); + Timestamp t2 = new Timestamp(0); + TimestampWritable.setTimestamp(t2, bytes, 0); + assertEquals(t1, t2); + } + }