hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From li...@apache.org
Subject hive git commit: HIVE-14595: TimestampWritable::setTimestamp gives wrong result when 2nd VInt exists (Rui reviewed by Xuefu)
Date Mon, 22 Aug 2016 11:02:28 GMT
Repository: hive
Updated Branches:
  refs/heads/master 2d1f403dd -> a705bdaec


HIVE-14595: TimestampWritable::setTimestamp gives wrong result when 2nd VInt exists (Rui reviewed
by Xuefu)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/a705bdae
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/a705bdae
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/a705bdae

Branch: refs/heads/master
Commit: a705bdaecf13795933cd36418a18e0121aef99aa
Parents: 2d1f403
Author: Rui Li <lirui@apache.org>
Authored: Mon Aug 22 19:02:11 2016 +0800
Committer: Rui Li <shlr@cn.ibm.com>
Committed: Mon Aug 22 19:02:11 2016 +0800

----------------------------------------------------------------------
 .../hadoop/hive/serde2/io/TimestampWritable.java     | 15 ++-------------
 .../hadoop/hive/serde2/io/TestTimestampWritable.java | 11 +++++++++++
 2 files changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/a705bdae/serde/src/java/org/apache/hadoop/hive/serde2/io/TimestampWritable.java
----------------------------------------------------------------------
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 class TimestampWritable implements WritableComparable<TimestampWritable>
   }
 
   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) {

http://git-wip-us.apache.org/repos/asf/hive/blob/a705bdae/serde/src/test/org/apache/hadoop/hive/serde2/io/TestTimestampWritable.java
----------------------------------------------------------------------
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 class TestTimestampWritable {
     }
   }
 
+  @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);
+  }
+
 }


Mime
View raw message