hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject [12/50] [abbrv] hive git commit: HIVE-10819: SearchArgumentImpl for Timestamp is broken by HIVE-10286 (Daniel Dai)
Date Tue, 02 Jun 2015 23:23:17 GMT
HIVE-10819: SearchArgumentImpl for Timestamp is broken by HIVE-10286 (Daniel Dai)


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

Branch: refs/heads/llap
Commit: 95aad54104894ad0a442e7a9aaf3be2e7463781c
Parents: fa2dd83
Author: Daniel Dai <daijy@hortonworks.com>
Authored: Fri May 29 16:18:18 2015 -0700
Committer: Daniel Dai <daijy@hortonworks.com>
Committed: Fri May 29 16:18:18 2015 -0700

----------------------------------------------------------------------
 .../hive/ql/io/sarg/SearchArgumentImpl.java     |  6 +++++
 .../hive/ql/io/sarg/TestSearchArgumentImpl.java | 27 ++++++++++++++++++++
 2 files changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/95aad541/ql/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgumentImpl.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgumentImpl.java b/ql/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgumentImpl.java
index efe03ab..63b3ee9 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgumentImpl.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgumentImpl.java
@@ -117,6 +117,12 @@ final class SearchArgumentImpl implements SearchArgument {
 
     @Override
     public Object getLiteral() {
+      // To get around a kryo 2.22 bug while deserialize a Timestamp into Date
+      // (https://github.com/EsotericSoftware/kryo/issues/88)
+      // When we see a Date, convert back into Timestamp
+      if (literal instanceof java.util.Date) {
+        return new Timestamp(((java.util.Date)literal).getTime());
+      }
       return literal;
     }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/95aad541/ql/src/test/org/apache/hadoop/hive/ql/io/sarg/TestSearchArgumentImpl.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/io/sarg/TestSearchArgumentImpl.java b/ql/src/test/org/apache/hadoop/hive/ql/io/sarg/TestSearchArgumentImpl.java
index 5e61aba..51f7f47 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/io/sarg/TestSearchArgumentImpl.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/io/sarg/TestSearchArgumentImpl.java
@@ -30,6 +30,7 @@ import org.apache.hadoop.hive.common.type.HiveVarchar;
 import org.apache.hadoop.hive.ql.io.sarg.SearchArgument.TruthValue;
 import org.apache.hadoop.hive.ql.io.sarg.SearchArgumentImpl.ExpressionBuilder;
 import org.apache.hadoop.hive.ql.io.sarg.SearchArgumentImpl.ExpressionTree;
+import org.apache.hadoop.hive.ql.io.sarg.SearchArgumentImpl.PredicateLeafImpl;
 import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
 import org.apache.hadoop.hive.serde2.io.DateWritable;
 import org.junit.Test;
@@ -37,7 +38,9 @@ import org.junit.Test;
 import java.beans.XMLDecoder;
 import java.io.ByteArrayInputStream;
 import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Field;
 import java.math.BigDecimal;
+import java.sql.Timestamp;
 import java.util.List;
 import java.util.Set;
 
@@ -3038,4 +3041,28 @@ public class TestSearchArgumentImpl {
         "0.22)), eq(z1, 0.22))";
     assertEquals(expected, p.toString());
   }
+
+  @Test
+  public void testTimestampSerialization() throws Exception {
+    // There is a kryo which after serialize/deserialize,
+    // Timestamp becomes Date. We get around this issue in
+    // SearchArgumentImpl.getLiteral. Once kryo fixed the issue
+    // We can simplify SearchArgumentImpl.getLiteral
+    Timestamp now = new Timestamp(new java.util.Date().getTime());
+    SearchArgument sarg =
+      SearchArgumentFactory.newBuilder()
+        .startAnd()
+        .lessThan("x", now)
+        .end()
+        .build();
+
+    String serializedSarg = sarg.toKryo();
+    SearchArgument sarg2 = SearchArgumentImpl.fromKryo(serializedSarg);
+
+    Field literalField = PredicateLeafImpl.class.getDeclaredField("literal");
+    literalField.setAccessible(true);
+    assertTrue(literalField.get(sarg2.getLeaves().get(0)) instanceof java.util.Date);
+    Timestamp ts = (Timestamp)sarg2.getLeaves().get(0).getLiteral();
+    assertEquals(ts, now);
+  }
 }


Mime
View raw message