Repository: hive Updated Branches: refs/heads/branch-1 9fc7442ec -> 5ac33bbdc
HIVE-12196 NPE when converting bad timestamp value (Aihua Xu, reviewed by Chaoyu Tang) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/5ac33bbd Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/5ac33bbd Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/5ac33bbd Branch: refs/heads/branch-1 Commit: 5ac33bbdc8b892c3ac6c7e5665d69c8ff8e46d3f Parents: 9fc7442 Author: aihuaxu <aihu...@apache.org> Authored: Tue Nov 3 13:49:20 2015 -0500 Committer: aihuaxu <aihu...@apache.org> Committed: Mon Nov 16 10:48:37 2015 -0500 ---------------------------------------------------------------------- .../ql/udf/generic/GenericUDFFromUtcTimestamp.java | 11 +++++++---- .../queries/clientpositive/udf_from_utc_timestamp.q | 5 +++++ .../clientpositive/udf_from_utc_timestamp.q.out | 13 +++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/5ac33bbd/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFromUtcTimestamp.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFromUtcTimestamp.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFromUtcTimestamp.java index 1343d3b..3f10a24 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFromUtcTimestamp.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFromUtcTimestamp.java @@ -77,12 +77,15 @@ public class GenericUDFFromUtcTimestamp extends GenericUDF { return null; } - String tzStr = textConverter.convert(o1).toString(); - TimeZone timezone = TimeZone.getTimeZone(tzStr); + Object converted_o0 = timestampConverter.convert(o0); + if (converted_o0 == null) { + return null; + } - Timestamp timestamp = ((TimestampWritable) timestampConverter.convert(o0)) - .getTimestamp(); + Timestamp timestamp = ((TimestampWritable) converted_o0).getTimestamp(); + String tzStr = textConverter.convert(o1).toString(); + TimeZone timezone = TimeZone.getTimeZone(tzStr); int offset = timezone.getOffset(timestamp.getTime()); if (invert()) { offset = -offset; http://git-wip-us.apache.org/repos/asf/hive/blob/5ac33bbd/ql/src/test/queries/clientpositive/udf_from_utc_timestamp.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientpositive/udf_from_utc_timestamp.q b/ql/src/test/queries/clientpositive/udf_from_utc_timestamp.q index b113eec..ca0a6a8 100644 --- a/ql/src/test/queries/clientpositive/udf_from_utc_timestamp.q +++ b/ql/src/test/queries/clientpositive/udf_from_utc_timestamp.q @@ -22,3 +22,8 @@ from_utc_timestamp(cast('2012-02-11 04:30:00' as timestamp), ''), from_utc_timestamp(cast('2012-02-11 04:30:00' as timestamp), '---'), from_utc_timestamp(cast(null as timestamp), 'PST'), from_utc_timestamp(cast('2012-02-11 04:30:00' as timestamp), cast(null as string)); + +select +from_utc_timestamp('2012-02-11-04:30:00', 'UTC'), +from_utc_timestamp('2012-02-11-04:30:00', 'PST'); + http://git-wip-us.apache.org/repos/asf/hive/blob/5ac33bbd/ql/src/test/results/clientpositive/udf_from_utc_timestamp.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientpositive/udf_from_utc_timestamp.q.out b/ql/src/test/results/clientpositive/udf_from_utc_timestamp.q.out index 5b4bc35..be2cb1a 100644 --- a/ql/src/test/results/clientpositive/udf_from_utc_timestamp.q.out +++ b/ql/src/test/results/clientpositive/udf_from_utc_timestamp.q.out @@ -80,3 +80,16 @@ POSTHOOK: type: QUERY POSTHOOK: Input: _dummy_database@_dummy_table #### A masked pattern was here #### 2012-02-10 20:30:00 2012-02-11 08:30:00 2012-02-11 12:30:00 2012-02-11 04:30:00 2012-02-11 04:30:00 2012-02-11 04:30:00 NULL NULL +PREHOOK: query: select +from_utc_timestamp('2012-02-11-04:30:00', 'UTC'), +from_utc_timestamp('2012-02-11-04:30:00', 'PST') +PREHOOK: type: QUERY +PREHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +POSTHOOK: query: select +from_utc_timestamp('2012-02-11-04:30:00', 'UTC'), +from_utc_timestamp('2012-02-11-04:30:00', 'PST') +POSTHOOK: type: QUERY +POSTHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +NULL NULL