You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by li...@apache.org on 2016/08/22 14:37:55 UTC
hive git commit: HIVE-14595: TimestampWritable::setTimestamp gives
wrong result when 2nd VInt exists (Rui reviewed by Xuefu, amend the 1st patch)
Repository: hive
Updated Branches:
refs/heads/master a705bdaec -> 6a93fa5c6
HIVE-14595: TimestampWritable::setTimestamp gives wrong result when 2nd VInt exists (Rui reviewed by Xuefu, amend the 1st patch)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/6a93fa5c
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/6a93fa5c
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/6a93fa5c
Branch: refs/heads/master
Commit: 6a93fa5c615ceb5438ffd6cdc50513318ca0d69c
Parents: a705bda
Author: Rui Li <li...@apache.org>
Authored: Mon Aug 22 22:37:18 2016 +0800
Committer: Rui Li <sh...@cn.ibm.com>
Committed: Mon Aug 22 22:37:18 2016 +0800
----------------------------------------------------------------------
.../hadoop/hive/serde2/io/TimestampWritable.java | 6 +++++-
.../hive/serde2/io/TestTimestampWritable.java | 17 +++++++++++++++--
2 files changed, 20 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/6a93fa5c/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 ef7ad78..bbccc7f 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
@@ -554,7 +554,11 @@ public class TimestampWritable implements WritableComparable<TimestampWritable>
public static void setTimestamp(Timestamp t, byte[] bytes, int offset) {
long seconds = getSeconds(bytes, offset);
t.setTime(seconds * 1000);
- t.setNanos(getNanos(bytes, offset + 4));
+ if (hasDecimalOrSecondVInt(bytes[offset])) {
+ t.setNanos(getNanos(bytes, offset + 4));
+ } else {
+ t.setNanos(0);
+ }
}
public static Timestamp createTimestamp(byte[] bytes, int offset) {
http://git-wip-us.apache.org/repos/asf/hive/blob/6a93fa5c/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 cd7a1b9..3c483cc 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
@@ -495,8 +495,21 @@ public class TestTimestampWritable {
@Test
public void testSetTimestamp() {
- // make sure we need a 2nd VInt
- Timestamp t1 = new Timestamp((long) Integer.MAX_VALUE * 1000 + 1234);
+ // one VInt without nanos
+ verifySetTimestamp(1000);
+
+ // one VInt with nanos
+ verifySetTimestamp(1001);
+
+ // two VInt without nanos
+ verifySetTimestamp((long) Integer.MAX_VALUE * 1000 + 1000);
+
+ // two VInt with nanos
+ verifySetTimestamp((long) Integer.MAX_VALUE * 1000 + 1234);
+ }
+
+ private static void verifySetTimestamp(long time) {
+ Timestamp t1 = new Timestamp(time);
TimestampWritable writable = new TimestampWritable(t1);
byte[] bytes = writable.getBytes();
Timestamp t2 = new Timestamp(0);