hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jd...@apache.org
Subject svn commit: r1657737 - in /hive/trunk: data/files/tsformat.json hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/JsonSerDe.java ql/src/test/queries/clientpositive/json_serde_tsformat.q ql/src/test/results/clientpositive/json_serde_tsformat.q.out
Date Fri, 06 Feb 2015 01:49:15 GMT
Author: jdere
Date: Fri Feb  6 01:49:15 2015
New Revision: 1657737

URL: http://svn.apache.org/r1657737
Log:
HIVE-9564: Extend HIVE-9298 for JsonSerDe (Jason Dere, reviewed by Ashutosh Chauhan)

Added:
    hive/trunk/data/files/tsformat.json
    hive/trunk/ql/src/test/queries/clientpositive/json_serde_tsformat.q
    hive/trunk/ql/src/test/results/clientpositive/json_serde_tsformat.q.out
Modified:
    hive/trunk/hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/JsonSerDe.java

Added: hive/trunk/data/files/tsformat.json
URL: http://svn.apache.org/viewvc/hive/trunk/data/files/tsformat.json?rev=1657737&view=auto
==============================================================================
--- hive/trunk/data/files/tsformat.json (added)
+++ hive/trunk/data/files/tsformat.json Fri Feb  6 01:49:15 2015
@@ -0,0 +1,2 @@
+{"c1": 123, "c2": "abc", "c3": "2001-02-03T12:34:56"}
+{"c1": 456, "c2": "xyz", "c3": "1906-04-18T05:12:00"}

Modified: hive/trunk/hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/JsonSerDe.java
URL: http://svn.apache.org/viewvc/hive/trunk/hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/JsonSerDe.java?rev=1657737&r1=1657736&r2=1657737&view=diff
==============================================================================
--- hive/trunk/hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/JsonSerDe.java (original)
+++ hive/trunk/hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/JsonSerDe.java Fri
Feb  6 01:49:15 2015
@@ -70,6 +70,8 @@ import org.apache.hadoop.hive.serde2.typ
 import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.Writable;
+import org.apache.hive.common.util.HiveStringUtils;
+import org.apache.hive.common.util.TimestampParser;
 import org.apache.hive.hcatalog.common.HCatException;
 import org.apache.hive.hcatalog.data.schema.HCatFieldSchema;
 import org.apache.hive.hcatalog.data.schema.HCatFieldSchema.Type;
@@ -91,6 +93,7 @@ public class JsonSerDe implements SerDe
   private JsonFactory jsonFactory = null;
 
   private HCatRecordObjectInspector cachedObjectInspector;
+  private TimestampParser tsParser;
 
   @Override
   public void initialize(Configuration conf, Properties tbl)
@@ -138,6 +141,8 @@ public class JsonSerDe implements SerDe
     }
 
     jsonFactory = new JsonFactory();
+    tsParser = new TimestampParser(
+        HiveStringUtils.splitAndUnEscape(tbl.getProperty(serdeConstants.TIMESTAMP_FORMATS)));
   }
 
   /**
@@ -300,7 +305,7 @@ public class JsonSerDe implements SerDe
       val = (valueToken == JsonToken.VALUE_NULL) ? null : Date.valueOf(p.getText());
       break;
     case TIMESTAMP:
-      val = (valueToken == JsonToken.VALUE_NULL) ? null : Timestamp.valueOf(p.getText());
+      val = (valueToken == JsonToken.VALUE_NULL) ? null : tsParser.parseTimestamp(p.getText());
       break;
     case DECIMAL:
       val = (valueToken == JsonToken.VALUE_NULL) ? null : HiveDecimal.create(p.getText());

Added: hive/trunk/ql/src/test/queries/clientpositive/json_serde_tsformat.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/json_serde_tsformat.q?rev=1657737&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/json_serde_tsformat.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/json_serde_tsformat.q Fri Feb  6 01:49:15
2015
@@ -0,0 +1,12 @@
+
+add jar ${system:maven.local.repository}/org/apache/hive/hcatalog/hive-hcatalog-core/${system:hive.version}/hive-hcatalog-core-${system:hive.version}.jar;
+
+CREATE TABLE t1 (c1 int, c2 string, c3 timestamp)
+ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
+WITH SERDEPROPERTIES ('timestamp.formats'='yyyy-MM-dd\'T\'HH:mm:ss')
+;
+LOAD DATA LOCAL INPATH "../../data/files/tsformat.json" INTO TABLE t1;
+select a.c1, a.c2, b.c3
+from t1 a join t1 b on a.c1 = b.c1;
+
+drop table t1;

Added: hive/trunk/ql/src/test/results/clientpositive/json_serde_tsformat.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/json_serde_tsformat.q.out?rev=1657737&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/json_serde_tsformat.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/json_serde_tsformat.q.out Fri Feb  6 01:49:15
2015
@@ -0,0 +1,40 @@
+PREHOOK: query: CREATE TABLE t1 (c1 int, c2 string, c3 timestamp)
+ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
+WITH SERDEPROPERTIES ('timestamp.formats'='yyyy-MM-dd\'T\'HH:mm:ss')
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@t1
+POSTHOOK: query: CREATE TABLE t1 (c1 int, c2 string, c3 timestamp)
+ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
+WITH SERDEPROPERTIES ('timestamp.formats'='yyyy-MM-dd\'T\'HH:mm:ss')
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@t1
+PREHOOK: query: LOAD DATA LOCAL INPATH "../../data/files/tsformat.json" INTO TABLE t1
+PREHOOK: type: LOAD
+#### A masked pattern was here ####
+PREHOOK: Output: default@t1
+POSTHOOK: query: LOAD DATA LOCAL INPATH "../../data/files/tsformat.json" INTO TABLE t1
+POSTHOOK: type: LOAD
+#### A masked pattern was here ####
+POSTHOOK: Output: default@t1
+PREHOOK: query: select a.c1, a.c2, b.c3
+from t1 a join t1 b on a.c1 = b.c1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@t1
+#### A masked pattern was here ####
+POSTHOOK: query: select a.c1, a.c2, b.c3
+from t1 a join t1 b on a.c1 = b.c1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@t1
+#### A masked pattern was here ####
+123	abc	2001-02-03 12:34:56
+456	xyz	1906-04-18 05:12:00
+PREHOOK: query: drop table t1
+PREHOOK: type: DROPTABLE
+PREHOOK: Input: default@t1
+PREHOOK: Output: default@t1
+POSTHOOK: query: drop table t1
+POSTHOOK: type: DROPTABLE
+POSTHOOK: Input: default@t1
+POSTHOOK: Output: default@t1



Mime
View raw message