diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDayOfMonth.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDayOfMonth.java index 5f12625..21e6ff7 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDayOfMonth.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFDayOfMonth.java @@ -29,6 +29,7 @@ import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFDayOfMonthLong; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFDayOfMonthString; import org.apache.hadoop.hive.serde2.io.DateWritable; +import org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable; import org.apache.hadoop.hive.serde2.io.TimestampWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; @@ -38,9 +39,12 @@ * */ @Description(name = "day,dayofmonth", - value = "_FUNC_(date) - Returns the date of the month of date", - extended = "date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or " - + "'yyyy-MM-dd'.\n" + value = "_FUNC_(param) - Returns the day of the month of date/timestamp, or day component of interval", + extended = "param can be one of:\n" + + "1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd'.\n" + + "2. A date value\n" + + "3. A timestamp value\n" + + "4. A day-time interval value" + "Example:\n " + " > SELECT _FUNC_('2009-07-30') FROM src LIMIT 1;\n" + " 30") @VectorizedExpressions({VectorUDFDayOfMonthLong.class, VectorUDFDayOfMonthString.class}) @@ -98,4 +102,12 @@ public IntWritable evaluate(TimestampWritable t) { return result; } + public IntWritable evaluate(HiveIntervalDayTimeWritable i) { + if (i == null) { + return null; + } + + result.set(i.getHiveIntervalDayTime().getDays()); + return result; + } } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFHour.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFHour.java index 155dc29..835cecc 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFHour.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFHour.java @@ -28,6 +28,7 @@ import org.apache.hadoop.hive.ql.exec.vector.VectorizedExpressions; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFHourLong; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFHourString; +import org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable; import org.apache.hadoop.hive.serde2.io.TimestampWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; @@ -37,9 +38,11 @@ * */ @Description(name = "hour", - value = "_FUNC_(date) - Returns the hour of date", - extended = "date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or " - + "'HH:mm:ss'.\n" + value = "_FUNC_(param) - Returns the hour componemnt of the string/timestamp/interval", + extended ="param can be one of:\n" + + "1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'HH:mm:ss'.\n" + + "2. A timestamp value\n" + + "3. A day-time interval value" + "Example:\n " + " > SELECT _FUNC_('2009-07-30 12:58:59') FROM src LIMIT 1;\n" + " 12\n" @@ -95,4 +98,12 @@ public IntWritable evaluate(TimestampWritable t) { return result; } + public IntWritable evaluate(HiveIntervalDayTimeWritable i) { + if (i == null) { + return null; + } + + result.set(i.getHiveIntervalDayTime().getHours()); + return result; + } } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMinute.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMinute.java index 5755adb..a9f5393 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMinute.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMinute.java @@ -28,6 +28,7 @@ import org.apache.hadoop.hive.ql.exec.vector.VectorizedExpressions; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFMinuteLong; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFMinuteString; +import org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable; import org.apache.hadoop.hive.serde2.io.TimestampWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; @@ -37,9 +38,11 @@ * */ @Description(name = "minute", - value = "_FUNC_(date) - Returns the minute of date", - extended = "date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or " - + "'HH:mm:ss'.\n" + value = "_FUNC_(param) - Returns the minute component of the string/timestamp/interval", + extended = "param can be one of:\n" + + "1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'HH:mm:ss'.\n" + + "2. A timestamp value\n" + + "3. A day-time interval value" + "Example:\n " + " > SELECT _FUNC_('2009-07-30 12:58:59') FROM src LIMIT 1;\n" + " 58\n" @@ -95,4 +98,12 @@ public IntWritable evaluate(TimestampWritable t) { return result; } + public IntWritable evaluate(HiveIntervalDayTimeWritable i) { + if (i == null) { + return null; + } + + result.set(i.getHiveIntervalDayTime().getMinutes()); + return result; + } } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java index f37c054..3365804 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFMonth.java @@ -29,6 +29,7 @@ import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFMonthLong; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFMonthString; import org.apache.hadoop.hive.serde2.io.DateWritable; +import org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable; import org.apache.hadoop.hive.serde2.io.TimestampWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; @@ -38,8 +39,13 @@ * */ @Description(name = "month", - value = "_FUNC_(date) - Returns the month of date", - extended = "Example:\n" + value = "_FUNC_(param) - Returns the month component of the date/timestamp/interval", + extended = "param can be one of:\n" + + "1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd'.\n" + + "2. A date value\n" + + "3. A timestamp value\n" + + "4. A year-month interval value" + + "Example:\n" + " > SELECT _FUNC_('2009-07-30') FROM src LIMIT 1;\n" + " 7") @VectorizedExpressions({VectorUDFMonthLong.class, VectorUDFMonthString.class}) public class UDFMonth extends UDF { @@ -94,4 +100,12 @@ public IntWritable evaluate(TimestampWritable t) { return result; } + public IntWritable evaluate(HiveIntervalYearMonthWritable i) { + if (i == null) { + return null; + } + + result.set(i.getHiveIntervalYearMonth().getMonths()); + return result; + } } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java index 0292931..e7c3d67 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFSecond.java @@ -23,23 +23,29 @@ import java.util.Calendar; import java.util.Date; +import org.apache.hadoop.hive.common.type.HiveIntervalDayTime; import org.apache.hadoop.hive.ql.exec.Description; import org.apache.hadoop.hive.ql.exec.UDF; import org.apache.hadoop.hive.ql.exec.vector.VectorizedExpressions; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFSecondLong; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFSecondString; +import org.apache.hadoop.hive.serde2.io.DoubleWritable; +import org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable; import org.apache.hadoop.hive.serde2.io.TimestampWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; +import org.apache.hive.common.util.DateUtils; /** * UDFSecond. * */ @Description(name = "second", - value = "_FUNC_(date) - Returns the second of date", - extended = "date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or " - + "'HH:mm:ss'.\n" + value = "_FUNC_(date) - Returns the second component of the string/timestamp/interval", + extended = "param can be one of:\n" + + "1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'HH:mm:ss'.\n" + + "2. A timestamp value\n" + + "3. A day-time interval value" + "Example:\n " + " > SELECT _FUNC_('2009-07-30 12:58:59') FROM src LIMIT 1;\n" + " 59\n" @@ -96,4 +102,13 @@ public IntWritable evaluate(TimestampWritable t) { return result; } + public IntWritable evaluate(HiveIntervalDayTimeWritable i) { + if (i == null) { + return null; + } + + HiveIntervalDayTime idt = i.getHiveIntervalDayTime(); + result.set(idt.getSeconds()); + return result; + } } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java index 16525c2..34b0c47 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFYear.java @@ -29,6 +29,7 @@ import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFYearLong; import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorUDFYearString; import org.apache.hadoop.hive.serde2.io.DateWritable; +import org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable; import org.apache.hadoop.hive.serde2.io.TimestampWritable; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; @@ -38,9 +39,12 @@ * */ @Description(name = "year", - value = "_FUNC_(date) - Returns the year of date", - extended = "date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or " - + "'yyyy-MM-dd'.\n" + value = "_FUNC_(param) - Returns the year component of the date/timestamp/interval", + extended = "param can be one of:\n" + + "1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd'.\n" + + "2. A date value\n" + + "3. A timestamp value\n" + + "4. A year-month interval value" + "Example:\n " + " > SELECT _FUNC_('2009-07-30') FROM src LIMIT 1;\n" + " 2009") @VectorizedExpressions({VectorUDFYearLong.class, VectorUDFYearString.class}) @@ -98,4 +102,12 @@ public IntWritable evaluate(TimestampWritable t) { return result; } + public IntWritable evaluate(HiveIntervalYearMonthWritable i) { + if (i == null) { + return null; + } + + result.set(i.getHiveIntervalYearMonth().getYears()); + return result; + } } diff --git a/ql/src/test/queries/clientpositive/interval_udf.q b/ql/src/test/queries/clientpositive/interval_udf.q new file mode 100644 index 0000000..3fbdb0b --- /dev/null +++ b/ql/src/test/queries/clientpositive/interval_udf.q @@ -0,0 +1,8 @@ + +select + year(iym), month(iym), day(idt), hour(idt), minute(idt), second(idt) +from ( + select interval '1-2' year to month iym, interval '3 4:5:6.789' day to second idt + from src limit 1 +) q; + diff --git a/ql/src/test/results/clientpositive/interval_udf.q.out b/ql/src/test/results/clientpositive/interval_udf.q.out new file mode 100644 index 0000000..141562b --- /dev/null +++ b/ql/src/test/results/clientpositive/interval_udf.q.out @@ -0,0 +1,19 @@ +PREHOOK: query: select + year(iym), month(iym), day(idt), hour(idt), minute(idt), second(idt) +from ( + select interval '1-2' year to month iym, interval '3 4:5:6.789' day to second idt + from src limit 1 +) q +PREHOOK: type: QUERY +PREHOOK: Input: default@src +#### A masked pattern was here #### +POSTHOOK: query: select + year(iym), month(iym), day(idt), hour(idt), minute(idt), second(idt) +from ( + select interval '1-2' year to month iym, interval '3 4:5:6.789' day to second idt + from src limit 1 +) q +POSTHOOK: type: QUERY +POSTHOOK: Input: default@src +#### A masked pattern was here #### +1 2 3 4 5 6 diff --git a/ql/src/test/results/clientpositive/udf_day.q.out b/ql/src/test/results/clientpositive/udf_day.q.out index 49e0c2e..4131531 100644 --- a/ql/src/test/results/clientpositive/udf_day.q.out +++ b/ql/src/test/results/clientpositive/udf_day.q.out @@ -2,14 +2,17 @@ PREHOOK: query: DESCRIBE FUNCTION day PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION day POSTHOOK: type: DESCFUNCTION -day(date) - Returns the date of the month of date +day(param) - Returns the day of the month of date/timestamp, or day component of interval PREHOOK: query: DESCRIBE FUNCTION EXTENDED day PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION EXTENDED day POSTHOOK: type: DESCFUNCTION -day(date) - Returns the date of the month of date +day(param) - Returns the day of the month of date/timestamp, or day component of interval Synonyms: dayofmonth -date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd'. -Example: +param can be one of: +1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd'. +2. A date value +3. A timestamp value +4. A day-time interval valueExample: > SELECT day('2009-07-30') FROM src LIMIT 1; 30 diff --git a/ql/src/test/results/clientpositive/udf_dayofmonth.q.out b/ql/src/test/results/clientpositive/udf_dayofmonth.q.out index 992ee06..e31154e 100644 --- a/ql/src/test/results/clientpositive/udf_dayofmonth.q.out +++ b/ql/src/test/results/clientpositive/udf_dayofmonth.q.out @@ -2,14 +2,17 @@ PREHOOK: query: DESCRIBE FUNCTION dayofmonth PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION dayofmonth POSTHOOK: type: DESCFUNCTION -dayofmonth(date) - Returns the date of the month of date +dayofmonth(param) - Returns the day of the month of date/timestamp, or day component of interval PREHOOK: query: DESCRIBE FUNCTION EXTENDED dayofmonth PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION EXTENDED dayofmonth POSTHOOK: type: DESCFUNCTION -dayofmonth(date) - Returns the date of the month of date +dayofmonth(param) - Returns the day of the month of date/timestamp, or day component of interval Synonyms: day -date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd'. -Example: +param can be one of: +1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd'. +2. A date value +3. A timestamp value +4. A day-time interval valueExample: > SELECT dayofmonth('2009-07-30') FROM src LIMIT 1; 30 diff --git a/ql/src/test/results/clientpositive/udf_hour.q.out b/ql/src/test/results/clientpositive/udf_hour.q.out index ab743d2..4eb5a00 100644 --- a/ql/src/test/results/clientpositive/udf_hour.q.out +++ b/ql/src/test/results/clientpositive/udf_hour.q.out @@ -2,14 +2,16 @@ PREHOOK: query: DESCRIBE FUNCTION hour PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION hour POSTHOOK: type: DESCFUNCTION -hour(date) - Returns the hour of date +hour(param) - Returns the hour componemnt of the string/timestamp/interval PREHOOK: query: DESCRIBE FUNCTION EXTENDED hour PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION EXTENDED hour POSTHOOK: type: DESCFUNCTION -hour(date) - Returns the hour of date -date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or 'HH:mm:ss'. -Example: +hour(param) - Returns the hour componemnt of the string/timestamp/interval +param can be one of: +1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'HH:mm:ss'. +2. A timestamp value +3. A day-time interval valueExample: > SELECT hour('2009-07-30 12:58:59') FROM src LIMIT 1; 12 > SELECT hour('12:58:59') FROM src LIMIT 1; diff --git a/ql/src/test/results/clientpositive/udf_minute.q.out b/ql/src/test/results/clientpositive/udf_minute.q.out index 032cbee..ebd07c5 100644 --- a/ql/src/test/results/clientpositive/udf_minute.q.out +++ b/ql/src/test/results/clientpositive/udf_minute.q.out @@ -2,14 +2,16 @@ PREHOOK: query: DESCRIBE FUNCTION minute PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION minute POSTHOOK: type: DESCFUNCTION -minute(date) - Returns the minute of date +minute(param) - Returns the minute component of the string/timestamp/interval PREHOOK: query: DESCRIBE FUNCTION EXTENDED minute PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION EXTENDED minute POSTHOOK: type: DESCFUNCTION -minute(date) - Returns the minute of date -date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or 'HH:mm:ss'. -Example: +minute(param) - Returns the minute component of the string/timestamp/interval +param can be one of: +1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'HH:mm:ss'. +2. A timestamp value +3. A day-time interval valueExample: > SELECT minute('2009-07-30 12:58:59') FROM src LIMIT 1; 58 > SELECT minute('12:58:59') FROM src LIMIT 1; diff --git a/ql/src/test/results/clientpositive/udf_month.q.out b/ql/src/test/results/clientpositive/udf_month.q.out index e8a4a12..7b81bb8 100644 --- a/ql/src/test/results/clientpositive/udf_month.q.out +++ b/ql/src/test/results/clientpositive/udf_month.q.out @@ -2,14 +2,16 @@ PREHOOK: query: DESCRIBE FUNCTION minute PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION minute POSTHOOK: type: DESCFUNCTION -minute(date) - Returns the minute of date +minute(param) - Returns the minute component of the string/timestamp/interval PREHOOK: query: DESCRIBE FUNCTION EXTENDED minute PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION EXTENDED minute POSTHOOK: type: DESCFUNCTION -minute(date) - Returns the minute of date -date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or 'HH:mm:ss'. -Example: +minute(param) - Returns the minute component of the string/timestamp/interval +param can be one of: +1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'HH:mm:ss'. +2. A timestamp value +3. A day-time interval valueExample: > SELECT minute('2009-07-30 12:58:59') FROM src LIMIT 1; 58 > SELECT minute('12:58:59') FROM src LIMIT 1; diff --git a/ql/src/test/results/clientpositive/udf_second.q.out b/ql/src/test/results/clientpositive/udf_second.q.out index 6cdbffb..fcd1143 100644 --- a/ql/src/test/results/clientpositive/udf_second.q.out +++ b/ql/src/test/results/clientpositive/udf_second.q.out @@ -2,14 +2,16 @@ PREHOOK: query: DESCRIBE FUNCTION second PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION second POSTHOOK: type: DESCFUNCTION -second(date) - Returns the second of date +second(date) - Returns the second component of the string/timestamp/interval PREHOOK: query: DESCRIBE FUNCTION EXTENDED second PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION EXTENDED second POSTHOOK: type: DESCFUNCTION -second(date) - Returns the second of date -date is a string in the format of 'yyyy-MM-dd HH:mm:ss' or 'HH:mm:ss'. -Example: +second(date) - Returns the second component of the string/timestamp/interval +param can be one of: +1. A string in the format of 'yyyy-MM-dd HH:mm:ss' or 'HH:mm:ss'. +2. A timestamp value +3. A day-time interval valueExample: > SELECT second('2009-07-30 12:58:59') FROM src LIMIT 1; 59 > SELECT second('12:58:59') FROM src LIMIT 1;