You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by jd...@apache.org on 2015/02/10 00:06:18 UTC
svn commit: r1658600 - in /hive/trunk/ql/src:
java/org/apache/hadoop/hive/ql/exec/
java/org/apache/hadoop/hive/ql/udf/generic/
test/org/apache/hadoop/hive/ql/udf/generic/ test/queries/clientnegative/
test/queries/clientpositive/ test/results/clientnega...
Author: jdere
Date: Mon Feb 9 23:06:17 2015
New Revision: 1658600
URL: http://svn.apache.org/r1658600
Log:
HIVE-9520: Create NEXT_DAY UDF (Alexander Pivovarov via Jason Dere)
Added:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNextDay.java
hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFNextDay.java
hive/trunk/ql/src/test/queries/clientnegative/udf_next_day_error_1.q
hive/trunk/ql/src/test/queries/clientnegative/udf_next_day_error_2.q
hive/trunk/ql/src/test/queries/clientpositive/udf_next_day.q
hive/trunk/ql/src/test/results/clientnegative/udf_next_day_error_1.q.out
hive/trunk/ql/src/test/results/clientnegative/udf_next_day_error_2.q.out
hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out.orig
hive/trunk/ql/src/test/results/clientpositive/udf_next_day.q.out
Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java?rev=1658600&r1=1658599&r2=1658600&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java Mon Feb 9 23:06:17 2015
@@ -273,6 +273,7 @@ public final class FunctionRegistry {
registerGenericUDF("to_date", GenericUDFDate.class);
registerUDF("weekofyear", UDFWeekOfYear.class, false);
registerGenericUDF("last_day", GenericUDFLastDay.class);
+ registerGenericUDF("next_day", GenericUDFNextDay.class);
registerGenericUDF("date_add", GenericUDFDateAdd.class);
registerGenericUDF("date_sub", GenericUDFDateSub.class);
Added: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNextDay.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNextDay.java?rev=1658600&view=auto
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNextDay.java (added)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFNextDay.java Mon Feb 9 23:06:17 2015
@@ -0,0 +1,264 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import static org.apache.hadoop.hive.ql.udf.generic.GenericUDFNextDay.DayOfWeek.FRI;
+import static org.apache.hadoop.hive.ql.udf.generic.GenericUDFNextDay.DayOfWeek.MON;
+import static org.apache.hadoop.hive.ql.udf.generic.GenericUDFNextDay.DayOfWeek.SAT;
+import static org.apache.hadoop.hive.ql.udf.generic.GenericUDFNextDay.DayOfWeek.SUN;
+import static org.apache.hadoop.hive.ql.udf.generic.GenericUDFNextDay.DayOfWeek.THU;
+import static org.apache.hadoop.hive.ql.udf.generic.GenericUDFNextDay.DayOfWeek.TUE;
+import static org.apache.hadoop.hive.ql.udf.generic.GenericUDFNextDay.DayOfWeek.WED;
+
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.io.DateWritable;
+import org.apache.hadoop.hive.serde2.io.TimestampWritable;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter.TimestampConverter;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils.PrimitiveGrouping;
+import org.apache.hadoop.io.Text;
+
+/**
+ * GenericUDFNextDay.
+ *
+ * Returns the first date which is later than start_date and named as indicated
+ *
+ */
+@Description(name = "next_day",
+ value = "_FUNC_(start_date, day_of_week) - Returns the first date"
+ + " which is later than start_date and named as indicated.",
+ extended = "start_date is a string in the format 'yyyy-MM-dd HH:mm:ss' or"
+ + " 'yyyy-MM-dd'. day_of_week is day of the week (e.g. Mo, tue, FRIDAY)."
+ + "Example:\n " + " > SELECT _FUNC_('2015-01-14', 'TU') FROM src LIMIT 1;\n" + " '2015-01-20'")
+public class GenericUDFNextDay extends GenericUDF {
+ private transient SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
+ private transient TimestampConverter timestampConverter;
+ private transient Converter textConverter0;
+ private transient Converter textConverter1;
+ private transient Converter dateWritableConverter;
+ private transient PrimitiveCategory inputType1;
+ private transient PrimitiveCategory inputType2;
+ private final Calendar calendar = Calendar.getInstance();
+ private final Text output = new Text();
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
+ if (arguments.length != 2) {
+ throw new UDFArgumentLengthException("next_day() requires 2 argument, got "
+ + arguments.length);
+ }
+ if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
+ throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but "
+ + arguments[0].getTypeName() + " is passed as first arguments");
+ }
+ if (arguments[1].getCategory() != ObjectInspector.Category.PRIMITIVE) {
+ throw new UDFArgumentTypeException(1, "Only primitive type arguments are accepted but "
+ + arguments[1].getTypeName() + " is passed as second arguments");
+ }
+ inputType1 = ((PrimitiveObjectInspector) arguments[0]).getPrimitiveCategory();
+ ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+ switch (inputType1) {
+ case STRING:
+ case VARCHAR:
+ case CHAR:
+ inputType1 = PrimitiveCategory.STRING;
+ textConverter0 = ObjectInspectorConverters.getConverter(
+ (PrimitiveObjectInspector) arguments[0],
+ PrimitiveObjectInspectorFactory.writableStringObjectInspector);
+ break;
+ case TIMESTAMP:
+ timestampConverter = new TimestampConverter((PrimitiveObjectInspector) arguments[0],
+ PrimitiveObjectInspectorFactory.writableTimestampObjectInspector);
+ break;
+ case DATE:
+ dateWritableConverter = ObjectInspectorConverters.getConverter(
+ (PrimitiveObjectInspector) arguments[0],
+ PrimitiveObjectInspectorFactory.writableDateObjectInspector);
+ break;
+ default:
+ throw new UDFArgumentTypeException(0,
+ "next_day() only takes STRING/TIMESTAMP/DATEWRITABLE types as first argument, got "
+ + inputType1);
+ }
+ inputType2 = ((PrimitiveObjectInspector) arguments[1]).getPrimitiveCategory();
+ if (PrimitiveObjectInspectorUtils.getPrimitiveGrouping(inputType2) != PrimitiveGrouping.STRING_GROUP) {
+ throw new UDFArgumentTypeException(1,
+ "next_day() only takes STRING_GROUP types as second argument, got " + inputType2);
+ }
+ textConverter1 = ObjectInspectorConverters.getConverter(
+ (PrimitiveObjectInspector) arguments[1],
+ PrimitiveObjectInspectorFactory.writableStringObjectInspector);
+ return outputOI;
+ }
+
+ @Override
+ public Object evaluate(DeferredObject[] arguments) throws HiveException {
+ if (arguments[0].get() == null || arguments[1].get() == null) {
+ return null;
+ }
+ String dayOfWeek = textConverter1.convert(arguments[1].get()).toString();
+ int dayOfWeekInt = getIntDayOfWeek(dayOfWeek);
+ if (dayOfWeekInt == -1) {
+ return null;
+ }
+
+ Date date;
+ switch (inputType1) {
+ case STRING:
+ String dateString = textConverter0.convert(arguments[0].get()).toString();
+ try {
+ date = formatter.parse(dateString);
+ } catch (ParseException e) {
+ return null;
+ }
+ break;
+ case TIMESTAMP:
+ Timestamp ts = ((TimestampWritable) timestampConverter.convert(arguments[0].get()))
+ .getTimestamp();
+ date = ts;
+ break;
+ case DATE:
+ DateWritable dw = (DateWritable) dateWritableConverter.convert(arguments[0].get());
+ date = dw.get();
+ break;
+ default:
+ throw new UDFArgumentTypeException(0,
+ "next_day() only takes STRING/TIMESTAMP/DATEWRITABLE types, got " + inputType1);
+ }
+
+ nextDay(date, dayOfWeekInt);
+ Date newDate = calendar.getTime();
+ output.set(formatter.format(newDate));
+ return output;
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("next_day(");
+ if (children.length > 0) {
+ sb.append(children[0]);
+ for (int i = 1; i < children.length; i++) {
+ sb.append(", ");
+ sb.append(children[i]);
+ }
+ }
+ sb.append(")");
+ return sb.toString();
+ }
+
+ protected Calendar nextDay(Date date, int dayOfWeek) {
+ calendar.setTime(date);
+
+ int currDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
+
+ int daysToAdd;
+ if (currDayOfWeek < dayOfWeek) {
+ daysToAdd = dayOfWeek - currDayOfWeek;
+ } else {
+ daysToAdd = 7 - currDayOfWeek + dayOfWeek;
+ }
+
+ calendar.add(Calendar.DATE, daysToAdd);
+
+ return calendar;
+ }
+
+ protected int getIntDayOfWeek(String dayOfWeek) throws UDFArgumentException {
+ if (MON.matches(dayOfWeek)) {
+ return Calendar.MONDAY;
+ }
+ if (TUE.matches(dayOfWeek)) {
+ return Calendar.TUESDAY;
+ }
+ if (WED.matches(dayOfWeek)) {
+ return Calendar.WEDNESDAY;
+ }
+ if (THU.matches(dayOfWeek)) {
+ return Calendar.THURSDAY;
+ }
+ if (FRI.matches(dayOfWeek)) {
+ return Calendar.FRIDAY;
+ }
+ if (SAT.matches(dayOfWeek)) {
+ return Calendar.SATURDAY;
+ }
+ if (SUN.matches(dayOfWeek)) {
+ return Calendar.SUNDAY;
+ }
+ return -1;
+ }
+
+ public static enum DayOfWeek {
+ MON ("MO", "MON", "MONDAY"),
+ TUE ("TU", "TUE", "TUESDAY"),
+ WED ("WE", "WED", "WEDNESDAY"),
+ THU ("TH", "THU", "THURSDAY"),
+ FRI ("FR", "FRI", "FRIDAY"),
+ SAT ("SA", "SAT", "SATURDAY"),
+ SUN ("SU", "SUN", "SUNDAY");
+
+ private String name2;
+ private String name3;
+ private String fullName;
+
+ private DayOfWeek(String name2, String name3, String fullName) {
+ this.name2 = name2;
+ this.name3 = name3;
+ this.fullName = fullName;
+ }
+
+ public String getName2() {
+ return name2;
+ }
+
+ public String getName3() {
+ return name3;
+ }
+
+ public String getFullName() {
+ return fullName;
+ }
+
+ public boolean matches(String dayOfWeek) {
+ if (dayOfWeek.length() == 2) {
+ return name2.equalsIgnoreCase(dayOfWeek);
+ }
+ if (dayOfWeek.length() == 3) {
+ return name3.equalsIgnoreCase(dayOfWeek);
+ }
+ return fullName.equalsIgnoreCase(dayOfWeek);
+ }
+ }
+}
Added: hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFNextDay.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFNextDay.java?rev=1658600&view=auto
==============================================================================
--- hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFNextDay.java (added)
+++ hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFNextDay.java Mon Feb 9 23:06:17 2015
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import junit.framework.TestCase;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import org.apache.hadoop.io.Text;
+
+public class TestGenericUDFNextDay extends TestCase {
+
+ public void testNextDay() throws HiveException {
+ GenericUDFNextDay udf = new GenericUDFNextDay();
+ ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+ ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+ ObjectInspector[] arguments = { valueOI0, valueOI1 };
+
+ udf.initialize(arguments);
+
+ // start_date is Sun, 2 letters day name
+ runAndVerify("2015-01-11", "su", "2015-01-18", udf);
+ runAndVerify("2015-01-11", "MO", "2015-01-12", udf);
+ runAndVerify("2015-01-11", "Tu", "2015-01-13", udf);
+ runAndVerify("2015-01-11", "wE", "2015-01-14", udf);
+ runAndVerify("2015-01-11", "th", "2015-01-15", udf);
+ runAndVerify("2015-01-11", "FR", "2015-01-16", udf);
+ runAndVerify("2015-01-11", "Sa", "2015-01-17", udf);
+
+ // start_date is Sat, 3 letters day name
+ runAndVerify("2015-01-17", "sun", "2015-01-18", udf);
+ runAndVerify("2015-01-17", "MON", "2015-01-19", udf);
+ runAndVerify("2015-01-17", "Tue", "2015-01-20", udf);
+ runAndVerify("2015-01-17", "weD", "2015-01-21", udf);
+ runAndVerify("2015-01-17", "tHu", "2015-01-22", udf);
+ runAndVerify("2015-01-17", "FrI", "2015-01-23", udf);
+ runAndVerify("2015-01-17", "SAt", "2015-01-24", udf);
+
+ // start_date is Wed, full timestamp, full day name
+ runAndVerify("2015-01-14 14:04:34", "sunday", "2015-01-18", udf);
+ runAndVerify("2015-01-14 14:04:34", "Monday", "2015-01-19", udf);
+ runAndVerify("2015-01-14 14:04:34", "Tuesday", "2015-01-20", udf);
+ runAndVerify("2015-01-14 14:04:34", "wednesday", "2015-01-21", udf);
+ runAndVerify("2015-01-14 14:04:34", "thursDAY", "2015-01-15", udf);
+ runAndVerify("2015-01-14 14:04:34", "FRIDAY", "2015-01-16", udf);
+ runAndVerify("2015-01-14 14:04:34", "SATurday", "2015-01-17", udf);
+
+ // null values
+ runAndVerify("2015-01-14", null, null, udf);
+ runAndVerify(null, "SU", null, udf);
+ runAndVerify(null, null, null, udf);
+
+ // not valid values
+ runAndVerify("01/14/2015", "TU", null, udf);
+ runAndVerify("2015-01-14", "VT", null, udf);
+ }
+
+ public void testNextDayErrorArg1() throws HiveException {
+ @SuppressWarnings("resource")
+ GenericUDFNextDay udf = new GenericUDFNextDay();
+ ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
+ ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+ ObjectInspector[] arguments = { valueOI0, valueOI1 };
+
+ try {
+ udf.initialize(arguments);
+ assertTrue("UDFArgumentException expected", false);
+ } catch (UDFArgumentException e) {
+ assertEquals(
+ "next_day() only takes STRING/TIMESTAMP/DATEWRITABLE types as first argument, got LONG",
+ e.getMessage());
+ }
+ }
+
+ public void testNextDayErrorArg2() throws HiveException {
+ @SuppressWarnings("resource")
+ GenericUDFNextDay udf = new GenericUDFNextDay();
+ ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+ ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
+ ObjectInspector[] arguments = { valueOI0, valueOI1 };
+
+ try {
+ udf.initialize(arguments);
+ assertTrue("UDFArgumentException expected", false);
+ } catch (UDFArgumentException e) {
+ assertEquals("next_day() only takes STRING_GROUP types as second argument, got INT",
+ e.getMessage());
+ }
+ }
+
+ private void runAndVerify(String date, String dayOfWeek, String expResult, GenericUDF udf)
+ throws HiveException {
+ DeferredObject valueObj0 = new DeferredJavaObject(date != null ? new Text(date) : null);
+ DeferredObject valueObj1 = new DeferredJavaObject(dayOfWeek != null ? new Text(dayOfWeek)
+ : null);
+ DeferredObject[] args = { valueObj0, valueObj1 };
+ Text output = (Text) udf.evaluate(args);
+ assertEquals("next_day() test ", expResult, output != null ? output.toString() : null);
+ }
+}
Added: hive/trunk/ql/src/test/queries/clientnegative/udf_next_day_error_1.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/udf_next_day_error_1.q?rev=1658600&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/udf_next_day_error_1.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/udf_next_day_error_1.q Mon Feb 9 23:06:17 2015
@@ -0,0 +1 @@
+SELECT NEXT_DAY(145622345, 'TU');
\ No newline at end of file
Added: hive/trunk/ql/src/test/queries/clientnegative/udf_next_day_error_2.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/udf_next_day_error_2.q?rev=1658600&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/udf_next_day_error_2.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/udf_next_day_error_2.q Mon Feb 9 23:06:17 2015
@@ -0,0 +1 @@
+SELECT NEXT_DAY('2015-01-14', 4);
\ No newline at end of file
Added: hive/trunk/ql/src/test/queries/clientpositive/udf_next_day.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/udf_next_day.q?rev=1658600&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/udf_next_day.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/udf_next_day.q Mon Feb 9 23:06:17 2015
@@ -0,0 +1,46 @@
+set hive.fetch.task.conversion=more;
+
+DESCRIBE FUNCTION next_day;
+DESCRIBE FUNCTION EXTENDED next_day;
+
+EXPLAIN SELECT next_day('2014-01-14', 'MO')
+FROM src tablesample (1 rows);
+
+SELECT next_day('2015-01-11', 'su'),
+ next_day('2015-01-11', 'MO'),
+ next_day('2015-01-11', 'Tu'),
+ next_day('2015-01-11', 'wE'),
+ next_day('2015-01-11', 'th'),
+ next_day('2015-01-11', 'FR'),
+ next_day('2015-01-11', 'Sa')
+FROM src tablesample (1 rows);
+
+SELECT next_day('2015-01-17 00:02:30', 'sun'),
+ next_day('2015-01-17 00:02:30', 'MON'),
+ next_day('2015-01-17 00:02:30', 'Tue'),
+ next_day('2015-01-17 00:02:30', 'weD'),
+ next_day('2015-01-17 00:02:30', 'tHu'),
+ next_day('2015-01-17 00:02:30', 'FrI'),
+ next_day('2015-01-17 00:02:30', 'SAt')
+FROM src tablesample (1 rows);
+
+SELECT next_day(cast('2015-01-14 14:04:34' as timestamp), 'sunday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'Monday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'Tuesday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'wednesday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'thursDAY'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'FRIDAY'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'SATurday')
+FROM src tablesample (1 rows);
+
+SELECT next_day(cast(null as string), 'MO'),
+ next_day(cast(null as timestamp), 'MO'),
+ next_day('2015-01-11', cast(null as string)),
+ next_day(cast(null as string), cast(null as string)),
+ next_day(cast(null as timestamp), cast(null as string))
+FROM src tablesample (1 rows);
+
+SELECT next_day('2015-02-02', 'VT'),
+ next_day('2015-02-30', 'WE'),
+ next_day('02/15/2015', 'WE')
+FROM src tablesample (1 rows);
Added: hive/trunk/ql/src/test/results/clientnegative/udf_next_day_error_1.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/udf_next_day_error_1.q.out?rev=1658600&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/udf_next_day_error_1.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/udf_next_day_error_1.q.out Mon Feb 9 23:06:17 2015
@@ -0,0 +1 @@
+FAILED: SemanticException [Error 10016]: Line 1:16 Argument type mismatch '145622345': next_day() only takes STRING/TIMESTAMP/DATEWRITABLE types as first argument, got INT
Added: hive/trunk/ql/src/test/results/clientnegative/udf_next_day_error_2.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/udf_next_day_error_2.q.out?rev=1658600&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/udf_next_day_error_2.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/udf_next_day_error_2.q.out Mon Feb 9 23:06:17 2015
@@ -0,0 +1 @@
+FAILED: SemanticException [Error 10016]: Line 1:30 Argument type mismatch '4': next_day() only takes STRING_GROUP types as second argument, got INT
Modified: hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out?rev=1658600&r1=1658599&r2=1658600&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out Mon Feb 9 23:06:17 2015
@@ -124,6 +124,7 @@ minute
month
named_struct
negative
+next_day
ngrams
noop
noopstreaming
Added: hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out.orig
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out.orig?rev=1658600&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out.orig (added)
+++ hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out.orig Mon Feb 9 23:06:17 2015
@@ -0,0 +1,367 @@
+PREHOOK: query: SHOW FUNCTIONS
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS
+POSTHOOK: type: SHOWFUNCTIONS
+!
+!=
+%
+&
+*
++
+-
+/
+<
+<=
+<=>
+<>
+=
+==
+>
+>=
+^
+abs
+acos
+add_months
+and
+array
+array_contains
+ascii
+asin
+assert_true
+atan
+avg
+base64
+between
+bin
+case
+ceil
+ceiling
+coalesce
+collect_list
+collect_set
+compute_stats
+concat
+concat_ws
+context_ngrams
+conv
+corr
+cos
+count
+covar_pop
+covar_samp
+create_union
+cume_dist
+current_database
+current_date
+current_timestamp
+current_user
+date_add
+date_sub
+datediff
+day
+dayofmonth
+decode
+default.qtest_get_java_boolean
+degrees
+dense_rank
+div
+e
+elt
+encode
+ewah_bitmap
+ewah_bitmap_and
+ewah_bitmap_empty
+ewah_bitmap_or
+exp
+explode
+field
+find_in_set
+first_value
+floor
+format_number
+from_unixtime
+from_utc_timestamp
+get_json_object
+greatest
+hash
+hex
+histogram_numeric
+hour
+if
+in
+in_file
+index
+initcap
+inline
+instr
+isnotnull
+isnull
+java_method
+json_tuple
+lag
+last_day
+last_value
+lcase
+lead
+least
+length
+like
+ln
+locate
+log
+log10
+log2
+lower
+lpad
+ltrim
+map
+map_keys
+map_values
+matchpath
+max
+min
+minute
+month
+named_struct
+negative
+ngrams
+noop
+noopstreaming
+noopwithmap
+noopwithmapstreaming
+not
+ntile
+nvl
+or
+parse_url
+parse_url_tuple
+percent_rank
+percentile
+percentile_approx
+pi
+pmod
+posexplode
+positive
+pow
+power
+printf
+radians
+rand
+rank
+reflect
+reflect2
+regexp
+regexp_extract
+regexp_replace
+repeat
+reverse
+rlike
+round
+row_number
+rpad
+rtrim
+second
+sentences
+sign
+sin
+size
+sort_array
+space
+split
+sqrt
+stack
+std
+stddev
+stddev_pop
+stddev_samp
+str_to_map
+struct
+substr
+substring
+sum
+tan
+to_date
+to_unix_timestamp
+to_utc_timestamp
+translate
+trim
+ucase
+unbase64
+unhex
+unix_timestamp
+upper
+var_pop
+var_samp
+variance
+weekofyear
+when
+windowingtablefunction
+xpath
+xpath_boolean
+xpath_double
+xpath_float
+xpath_int
+xpath_long
+xpath_number
+xpath_short
+xpath_string
+year
+|
+~
+PREHOOK: query: SHOW FUNCTIONS '^c.*'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS '^c.*'
+POSTHOOK: type: SHOWFUNCTIONS
+case
+ceil
+ceiling
+coalesce
+collect_list
+collect_set
+compute_stats
+concat
+concat_ws
+context_ngrams
+conv
+corr
+cos
+count
+covar_pop
+covar_samp
+create_union
+cume_dist
+current_database
+current_date
+current_timestamp
+current_user
+PREHOOK: query: SHOW FUNCTIONS '.*e$'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS '.*e$'
+POSTHOOK: type: SHOWFUNCTIONS
+assert_true
+case
+coalesce
+current_database
+current_date
+decode
+e
+encode
+explode
+first_value
+from_unixtime
+in_file
+inline
+json_tuple
+last_value
+lcase
+like
+locate
+minute
+negative
+ntile
+parse_url_tuple
+percentile
+posexplode
+positive
+regexp_replace
+reverse
+rlike
+size
+space
+to_date
+translate
+ucase
+variance
+xpath_double
+PREHOOK: query: SHOW FUNCTIONS 'log.*'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS 'log.*'
+POSTHOOK: type: SHOWFUNCTIONS
+log
+log10
+log2
+PREHOOK: query: SHOW FUNCTIONS '.*date.*'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS '.*date.*'
+POSTHOOK: type: SHOWFUNCTIONS
+current_date
+date_add
+date_sub
+datediff
+to_date
+PREHOOK: query: SHOW FUNCTIONS '***'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS '***'
+POSTHOOK: type: SHOWFUNCTIONS
+PREHOOK: query: SHOW FUNCTIONS LIKE 'When'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'When'
+POSTHOOK: type: SHOWFUNCTIONS
+when
+PREHOOK: query: SHOW FUNCTIONS LIKE 'max|min'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'max|min'
+POSTHOOK: type: SHOWFUNCTIONS
+max
+min
+PREHOOK: query: SHOW FUNCTIONS LIKE 'xpath*|m*'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'xpath*|m*'
+POSTHOOK: type: SHOWFUNCTIONS
+map
+map_keys
+map_values
+matchpath
+max
+min
+minute
+month
+xpath
+xpath_boolean
+xpath_double
+xpath_float
+xpath_int
+xpath_long
+xpath_number
+xpath_short
+xpath_string
+PREHOOK: query: SHOW FUNCTIONS LIKE 'nomatch'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'nomatch'
+POSTHOOK: type: SHOWFUNCTIONS
+PREHOOK: query: SHOW FUNCTIONS LIKE "log"
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE "log"
+POSTHOOK: type: SHOWFUNCTIONS
+log
+PREHOOK: query: SHOW FUNCTIONS LIKE 'log'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'log'
+POSTHOOK: type: SHOWFUNCTIONS
+log
+PREHOOK: query: SHOW FUNCTIONS LIKE `log`
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE `log`
+POSTHOOK: type: SHOWFUNCTIONS
+log
+PREHOOK: query: SHOW FUNCTIONS LIKE 'log*'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'log*'
+POSTHOOK: type: SHOWFUNCTIONS
+log
+log10
+log2
+PREHOOK: query: SHOW FUNCTIONS LIKE "log*"
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE "log*"
+POSTHOOK: type: SHOWFUNCTIONS
+log
+log10
+log2
+PREHOOK: query: SHOW FUNCTIONS LIKE `log*`
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE `log*`
+POSTHOOK: type: SHOWFUNCTIONS
+log
+log10
+log2
Added: hive/trunk/ql/src/test/results/clientpositive/udf_next_day.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf_next_day.q.out?rev=1658600&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf_next_day.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/udf_next_day.q.out Mon Feb 9 23:06:17 2015
@@ -0,0 +1,140 @@
+PREHOOK: query: DESCRIBE FUNCTION next_day
+PREHOOK: type: DESCFUNCTION
+POSTHOOK: query: DESCRIBE FUNCTION next_day
+POSTHOOK: type: DESCFUNCTION
+next_day(start_date, day_of_week) - Returns the first date which is later than start_date and named as indicated.
+PREHOOK: query: DESCRIBE FUNCTION EXTENDED next_day
+PREHOOK: type: DESCFUNCTION
+POSTHOOK: query: DESCRIBE FUNCTION EXTENDED next_day
+POSTHOOK: type: DESCFUNCTION
+next_day(start_date, day_of_week) - Returns the first date which is later than start_date and named as indicated.
+start_date is a string in the format 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd'. day_of_week is day of the week (e.g. Mo, tue, FRIDAY).Example:
+ > SELECT next_day('2015-01-14', 'TU') FROM src LIMIT 1;
+ '2015-01-20'
+PREHOOK: query: EXPLAIN SELECT next_day('2014-01-14', 'MO')
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+POSTHOOK: query: EXPLAIN SELECT next_day('2014-01-14', 'MO')
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+STAGE DEPENDENCIES:
+ Stage-0 is a root stage
+
+STAGE PLANS:
+ Stage: Stage-0
+ Fetch Operator
+ limit: -1
+ Processor Tree:
+ TableScan
+ alias: src
+ Row Limit Per Split: 1
+ Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE Column stats: COMPLETE
+ Select Operator
+ expressions: '2014-01-20' (type: string)
+ outputColumnNames: _col0
+ Statistics: Num rows: 500 Data size: 47000 Basic stats: COMPLETE Column stats: COMPLETE
+ ListSink
+
+PREHOOK: query: SELECT next_day('2015-01-11', 'su'),
+ next_day('2015-01-11', 'MO'),
+ next_day('2015-01-11', 'Tu'),
+ next_day('2015-01-11', 'wE'),
+ next_day('2015-01-11', 'th'),
+ next_day('2015-01-11', 'FR'),
+ next_day('2015-01-11', 'Sa')
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT next_day('2015-01-11', 'su'),
+ next_day('2015-01-11', 'MO'),
+ next_day('2015-01-11', 'Tu'),
+ next_day('2015-01-11', 'wE'),
+ next_day('2015-01-11', 'th'),
+ next_day('2015-01-11', 'FR'),
+ next_day('2015-01-11', 'Sa')
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+2015-01-18 2015-01-12 2015-01-13 2015-01-14 2015-01-15 2015-01-16 2015-01-17
+PREHOOK: query: SELECT next_day('2015-01-17 00:02:30', 'sun'),
+ next_day('2015-01-17 00:02:30', 'MON'),
+ next_day('2015-01-17 00:02:30', 'Tue'),
+ next_day('2015-01-17 00:02:30', 'weD'),
+ next_day('2015-01-17 00:02:30', 'tHu'),
+ next_day('2015-01-17 00:02:30', 'FrI'),
+ next_day('2015-01-17 00:02:30', 'SAt')
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT next_day('2015-01-17 00:02:30', 'sun'),
+ next_day('2015-01-17 00:02:30', 'MON'),
+ next_day('2015-01-17 00:02:30', 'Tue'),
+ next_day('2015-01-17 00:02:30', 'weD'),
+ next_day('2015-01-17 00:02:30', 'tHu'),
+ next_day('2015-01-17 00:02:30', 'FrI'),
+ next_day('2015-01-17 00:02:30', 'SAt')
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+2015-01-18 2015-01-19 2015-01-20 2015-01-21 2015-01-22 2015-01-23 2015-01-24
+PREHOOK: query: SELECT next_day(cast('2015-01-14 14:04:34' as timestamp), 'sunday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'Monday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'Tuesday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'wednesday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'thursDAY'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'FRIDAY'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'SATurday')
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT next_day(cast('2015-01-14 14:04:34' as timestamp), 'sunday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'Monday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'Tuesday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'wednesday'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'thursDAY'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'FRIDAY'),
+ next_day(cast('2015-01-14 14:04:34' as timestamp), 'SATurday')
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+2015-01-18 2015-01-19 2015-01-20 2015-01-21 2015-01-15 2015-01-16 2015-01-17
+PREHOOK: query: SELECT next_day(cast(null as string), 'MO'),
+ next_day(cast(null as timestamp), 'MO'),
+ next_day('2015-01-11', cast(null as string)),
+ next_day(cast(null as string), cast(null as string)),
+ next_day(cast(null as timestamp), cast(null as string))
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT next_day(cast(null as string), 'MO'),
+ next_day(cast(null as timestamp), 'MO'),
+ next_day('2015-01-11', cast(null as string)),
+ next_day(cast(null as string), cast(null as string)),
+ next_day(cast(null as timestamp), cast(null as string))
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+NULL NULL NULL NULL NULL
+PREHOOK: query: SELECT next_day('2015-02-02', 'VT'),
+ next_day('2015-02-30', 'WE'),
+ next_day('02/15/2015', 'WE')
+FROM src tablesample (1 rows)
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT next_day('2015-02-02', 'VT'),
+ next_day('2015-02-30', 'WE'),
+ next_day('02/15/2015', 'WE')
+FROM src tablesample (1 rows)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+NULL 2015-03-04 NULL