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 30ef5ab..331ee6b 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 Object evaluate(DeferredObject[] arguments) throws HiveException { 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; 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'); + 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