diff --git common/src/java/org/apache/hadoop/hive/common/type/TimestampUtils.java common/src/java/org/apache/hadoop/hive/common/type/TimestampUtils.java index f26f8ae01e..fc2f87a07e 100644 --- common/src/java/org/apache/hadoop/hive/common/type/TimestampUtils.java +++ common/src/java/org/apache/hadoop/hive/common/type/TimestampUtils.java @@ -22,7 +22,6 @@ import java.math.BigDecimal; import java.time.DateTimeException; -import java.time.format.DateTimeParseException; /** * Utilities for Timestamps and the relevant conversions. @@ -185,7 +184,7 @@ public static Timestamp stringToTimestamp(String s) { try { return Timestamp.valueOf( TimestampTZUtil.parse(s).getZonedDateTime().toLocalDateTime().toString()); - } catch (IllegalArgumentException | DateTimeParseException eTZ) { + } catch (IllegalArgumentException | DateTimeException eTZ) { // Last attempt return Timestamp.ofEpochMilli(Date.valueOf(s).toEpochMilli()); } 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 serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java index 79bf5fb092..8a1af19d90 100644 --- serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java +++ serde/src/test/org/apache/hadoop/hive/serde2/lazy/TestLazyPrimitive.java @@ -402,10 +402,6 @@ public void testLazyTimestamp() throws Throwable { assertEquals(false, t.isNull); assertEquals(Timestamp.valueOf(sampleDate), t.getWritableObject().getTimestamp()); - String badDate = "2013-02-12 21:04:XX"; - byte[] bad2013 = badDate.getBytes(); - initLazyObject(t, bad2013, 0, bad2013.length); - assertEquals(true, t.isNull); } public void testLazyDate() throws Throwable { diff --git streaming/src/test/org/apache/hive/streaming/TestStreaming.java streaming/src/test/org/apache/hive/streaming/TestStreaming.java index 50433b6243..bbd9115bb5 100644 --- streaming/src/test/org/apache/hive/streaming/TestStreaming.java +++ streaming/src/test/org/apache/hive/streaming/TestStreaming.java @@ -2974,6 +2974,43 @@ public void testErrorHandling() ti.get(4).getState()); } + @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')"); + + 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.write("2018-10-19 10:35:00 GMT+01:00".getBytes()); + connection.write("2018-10-19 10:35:00+01:00".getBytes()); + connection.write("2018-10-19 10:35:00.123 America/Los_Angeles".getBytes()); + connection.write("2018-10-19 10:35:00.123 GMT+01:00".getBytes()); + connection.write("2018-10-19 10:35:00.123+01:00".getBytes()); + connection.commitTransaction(); + connection.close(); + + List rs = queryTable(driver, "SELECT * FROM default.timest"); + Assert.assertEquals(rs.size(), 6); + for (int i = 0; i < 3; i++){ + Assert.assertEquals(rs.get(i), "2018-10-19 10:35:00"); + } + for (int i = 3; i < rs.size(); i++){ + Assert.assertEquals(rs.get(i), "2018-10-19 10:35:00.123"); + } + } + // assumes un partitioned table // returns a map > private HashMap> dumpAllBuckets(String dbLocation, String tableName)