From e500c139fb6297bfc85c5ec7c847326385e8416c Mon Sep 17 00:00:00 2001 From: nareshpr Date: Fri, 21 Sep 2018 18:59:15 +0530 Subject: [PATCH] HIVE-20599: CAST(INTERVAL_DAY_TIME AS STRING) is throwing SemanticException --- .../apache/hadoop/hive/ql/udf/UDFToString.java | 18 ++++++++++++++++++ .../queries/clientpositive/udf_to_string.q | 3 +++ .../results/clientpositive/udf_to_string.q.out | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToString.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToString.java index a16d4295b7..2d49f21501 100755 --- a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToString.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFToString.java @@ -24,6 +24,8 @@ import org.apache.hadoop.hive.serde2.io.DateWritableV2; import org.apache.hadoop.hive.serde2.io.DoubleWritable; import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable; +import org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable; import org.apache.hadoop.hive.serde2.io.ShortWritable; import org.apache.hadoop.hive.serde2.io.TimestampLocalTZWritable; import org.apache.hadoop.hive.serde2.io.TimestampWritableV2; @@ -178,4 +180,20 @@ public Text evaluate (BytesWritable bw) { t.set(bw.getBytes(),0,bw.getLength()); return t; } + + public Text evaluate(HiveIntervalDayTimeWritable hiw) { + if (null == hiw) { + return null; + } + t.set(hiw.toString()); + return t; + } + + public Text evaluate(HiveIntervalYearMonthWritable hiw) { + if (null == hiw) { + return null; + } + t.set(hiw.toString()); + return t; + } } diff --git a/ql/src/test/queries/clientpositive/udf_to_string.q b/ql/src/test/queries/clientpositive/udf_to_string.q index ac4b5242e1..50186b8c8b 100644 --- a/ql/src/test/queries/clientpositive/udf_to_string.q +++ b/ql/src/test/queries/clientpositive/udf_to_string.q @@ -16,3 +16,6 @@ SELECT CAST(CAST(-3.14 AS DECIMAL(3,2)) AS STRING) FROM src tablesample (1 rows) SELECT CAST('Foo' AS STRING) FROM src tablesample (1 rows); +SELECT CAST(from_utc_timestamp(timestamp '2018-05-02 15:30:30', 'PST') - from_utc_timestamp(timestamp '1970-01-30 16:00:00', 'PST') AS STRING); +SELECT CAST(interval_year_month('1-2') AS STRING); + diff --git a/ql/src/test/results/clientpositive/udf_to_string.q.out b/ql/src/test/results/clientpositive/udf_to_string.q.out index bf2f72dab5..fc888a1e63 100644 --- a/ql/src/test/results/clientpositive/udf_to_string.q.out +++ b/ql/src/test/results/clientpositive/udf_to_string.q.out @@ -88,3 +88,21 @@ POSTHOOK: type: QUERY POSTHOOK: Input: default@src #### A masked pattern was here #### Foo +PREHOOK: query: SELECT CAST(from_utc_timestamp(timestamp '2018-05-02 15:30:30', 'PST') - from_utc_timestamp(timestamp '1970-01-30 16:00:00', 'PST') AS STRING) +PREHOOK: type: QUERY +PREHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +POSTHOOK: query: SELECT CAST(from_utc_timestamp(timestamp '2018-05-02 15:30:30', 'PST') - from_utc_timestamp(timestamp '1970-01-30 16:00:00', 'PST') AS STRING) +POSTHOOK: type: QUERY +POSTHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +17624 00:30:30.000000000 +PREHOOK: query: SELECT CAST(interval_year_month('1-2') AS STRING) +PREHOOK: type: QUERY +PREHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +POSTHOOK: query: SELECT CAST(interval_year_month('1-2') AS STRING) +POSTHOOK: type: QUERY +POSTHOOK: Input: _dummy_database@_dummy_table +#### A masked pattern was here #### +1-2 -- 2.17.1