diff --git common/src/java/org/apache/hive/common/util/TimestampParser.java common/src/java/org/apache/hive/common/util/TimestampParser.java index d30ab88892..1a85c586d2 100644 --- common/src/java/org/apache/hive/common/util/TimestampParser.java +++ common/src/java/org/apache/hive/common/util/TimestampParser.java @@ -25,6 +25,7 @@ import java.util.regex.Pattern; import org.apache.hadoop.hive.common.type.Timestamp; +import org.apache.hadoop.hive.common.type.TimestampUtils; import org.joda.time.DateTime; import org.joda.time.LocalDateTime; import org.joda.time.MutableDateTime; @@ -106,7 +107,7 @@ public Timestamp parseTimestamp(String strValue) throws IllegalArgumentException } // Otherwise try default timestamp parsing - return Timestamp.valueOf(strValue); + return TimestampUtils.stringToTimestamp(strValue); } private Optional tryParseWithFormat(String strValue) { diff --git common/src/test/org/apache/hive/common/util/TestTimestampParser.java common/src/test/org/apache/hive/common/util/TestTimestampParser.java index 00a7904ecf..631665218d 100644 --- common/src/test/org/apache/hive/common/util/TestTimestampParser.java +++ common/src/test/org/apache/hive/common/util/TestTimestampParser.java @@ -66,6 +66,19 @@ public void testDefault() { Timestamp.valueOf("1970-01-01 00:00:00")), new ValidTimestampCase("1945-12-31T23:59:59", Timestamp.valueOf("1945-12-31 23:59:59")), + + new ValidTimestampCase("2018-10-19 10:35:00.123 America/Los_Angeles", + Timestamp.valueOf("2018-10-19 10:35:00.123")), + new ValidTimestampCase("2018-10-19 10:35:00.123 GMT+01:00", + Timestamp.valueOf("2018-10-19 10:35:00.123")), + new ValidTimestampCase("2018-10-19 10:35:00.123+01:00", + Timestamp.valueOf("2018-10-19 10:35:00.123")), + new ValidTimestampCase("2018-10-19 10:35:00 America/Los_Angeles", + Timestamp.valueOf("2018-10-19 10:35:00")), + new ValidTimestampCase("2018-10-19 10:35:00 GMT+01:00", + Timestamp.valueOf("2018-10-19 10:35:00")), + new ValidTimestampCase("2018-10-19 10:35:00+01:00", + Timestamp.valueOf("2018-10-19 10:35:00")), }; String[] invalidCases = { diff --git streaming/src/test/org/apache/hive/streaming/TestStreaming.java streaming/src/test/org/apache/hive/streaming/TestStreaming.java index 50433b6243..93194287f3 100644 --- streaming/src/test/org/apache/hive/streaming/TestStreaming.java +++ streaming/src/test/org/apache/hive/streaming/TestStreaming.java @@ -575,6 +575,34 @@ public void testConnectionWithWriteId() throws Exception { Assert.assertTrue(rs.get(3), rs.get(3).endsWith("bucket_00000")); } + @Test + public void testTimeStamp() throws Exception { + queryTable(driver, "drop table if exists default.timest"); + queryTable(driver, "create table default.timest (a TIMESTAMP) stored as orc " + + "TBLPROPERTIES('transactional'='true')"); + // queryTable(driver, "insert into table default.timest values('2015-10-19 10:35:40 UTC')"); + + StrictDelimitedInputWriter wr = StrictDelimitedInputWriter.newBuilder() + .withFieldDelimiter(',') + .build(); + HiveStreamingConnection connection = HiveStreamingConnection.newBuilder() + .withDatabase("default") + .withTable("timest") + .withAgentInfo("UT_" + Thread.currentThread().getName()) + .withRecordWriter(wr) + .withHiveConf(conf) + .connect(); + + connection.beginTransaction(); + connection.write("2018-10-19 10:35:00 America/Los_Angeles".getBytes()); + connection.commitTransaction(); + connection.close(); + + List rs = queryTable(driver, "SELECT * FROM default.timest"); + Assert.assertEquals(rs.size(), 1); + + } + @Test public void testAllTypesDelimitedWriter() throws Exception { queryTable(driver, "drop table if exists default.alltypes");