hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jd...@apache.org
Subject svn commit: r1658591 - in /hive/trunk/ql/src: java/org/apache/hadoop/hive/ql/udf/generic/ test/org/apache/hadoop/hive/ql/udf/generic/ test/queries/clientnegative/ test/queries/clientpositive/ test/results/clientnegative/ test/results/clientpositive/
Date Mon, 09 Feb 2015 22:10:27 GMT
Author: jdere
Date: Mon Feb  9 22:10:26 2015
New Revision: 1658591

URL: http://svn.apache.org/r1658591
Log:
HIVE-9590: add qtests for ADD_MONTHS UDF (Alexander Pivovarov via Jason Dere)

Added:
    hive/trunk/ql/src/test/queries/clientnegative/udf_add_months_error_1.q
    hive/trunk/ql/src/test/queries/clientnegative/udf_add_months_error_2.q
    hive/trunk/ql/src/test/results/clientnegative/udf_add_months_error_1.q.out
    hive/trunk/ql/src/test/results/clientnegative/udf_add_months_error_2.q.out
Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java
    hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAddMonths.java
    hive/trunk/ql/src/test/queries/clientpositive/udf_add_months.q
    hive/trunk/ql/src/test/results/clientpositive/udf_add_months.q.out

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java?rev=1658591&r1=1658590&r2=1658591&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java
(original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java
Mon Feb  9 22:10:26 2015
@@ -73,11 +73,11 @@ public class GenericUDFAddMonths extends
     }
     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");
+          + 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[2].getTypeName() + " is passed. as second arguments");
+          + arguments[1].getTypeName() + " is passed as second arguments");
     }
     inputType1 = ((PrimitiveObjectInspector) arguments[0]).getPrimitiveCategory();
     ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
@@ -100,14 +100,14 @@ public class GenericUDFAddMonths extends
           PrimitiveObjectInspectorFactory.writableDateObjectInspector);
       break;
     default:
-      throw new UDFArgumentException(
-          " ADD_MONTHS() only takes STRING/TIMESTAMP/DATEWRITABLE types as first argument,
got "
+      throw new UDFArgumentTypeException(0,
+          "ADD_MONTHS() only takes STRING/TIMESTAMP/DATEWRITABLE types as first argument,
got "
               + inputType1);
     }
     inputType2 = ((PrimitiveObjectInspector) arguments[1]).getPrimitiveCategory();
     if (inputType2 != PrimitiveCategory.INT) {
-      throw new UDFArgumentException(" ADD_MONTHS() only takes INT types as second argument,
got "
-          + inputType2);
+      throw new UDFArgumentTypeException(1,
+          "ADD_MONTHS() only takes INT types as second argument, got " + inputType2);
     }
     intWritableConverter = ObjectInspectorConverters.getConverter(
         (PrimitiveObjectInspector) arguments[1],
@@ -144,7 +144,7 @@ public class GenericUDFAddMonths extends
       date = dw.get();
       break;
     default:
-      throw new UDFArgumentException(
+      throw new UDFArgumentTypeException(0,
           "ADD_MONTHS() only takes STRING/TIMESTAMP/DATEWRITABLE types, got " + inputType1);
     }
     int numMonth = toBeAdded.get();

Modified: hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAddMonths.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAddMonths.java?rev=1658591&r1=1658590&r2=1658591&view=diff
==============================================================================
--- hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAddMonths.java
(original)
+++ hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAddMonths.java
Mon Feb  9 22:10:26 2015
@@ -46,6 +46,7 @@ public class TestGenericUDFAddMonths ext
     runAndVerify("2016-02-29", -12, "2015-02-28", udf);
     runAndVerify("2016-01-29", 1, "2016-02-29", udf);
     runAndVerify("2016-02-29", -1, "2016-01-31", udf);
+    runAndVerify("2014-01-32", 1, "2014-03-01", udf);
   }
 
   private void runAndVerify(String str, int months, String expResult, GenericUDF udf)

Added: hive/trunk/ql/src/test/queries/clientnegative/udf_add_months_error_1.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/udf_add_months_error_1.q?rev=1658591&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/udf_add_months_error_1.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/udf_add_months_error_1.q Mon Feb  9 22:10:26
2015
@@ -0,0 +1 @@
+select add_months(14567893456, 3);
\ No newline at end of file

Added: hive/trunk/ql/src/test/queries/clientnegative/udf_add_months_error_2.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/udf_add_months_error_2.q?rev=1658591&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/udf_add_months_error_2.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/udf_add_months_error_2.q Mon Feb  9 22:10:26
2015
@@ -0,0 +1 @@
+select add_months('2015-02-03', 2.4);
\ No newline at end of file

Modified: hive/trunk/ql/src/test/queries/clientpositive/udf_add_months.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/udf_add_months.q?rev=1658591&r1=1658590&r2=1658591&view=diff
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/udf_add_months.q (original)
+++ hive/trunk/ql/src/test/queries/clientpositive/udf_add_months.q Mon Feb  9 22:10:26 2015
@@ -1,2 +1,43 @@
 DESCRIBE FUNCTION add_months;
 DESCRIBE FUNCTION EXTENDED add_months;
+
+explain select add_months('2014-01-14', 1);
+
+select
+add_months('2014-01-14', 1),
+add_months('2014-01-31', 1),
+add_months('2014-02-28', -1),
+add_months('2014-02-28', 2),
+add_months('2014-04-30', -2),
+add_months('2015-02-28', 12),
+add_months('2016-02-29', -12),
+add_months('2016-01-29', 1),
+add_months('2016-02-29', -1),
+add_months('2014-01-32', 1),
+add_months('01/14/2014', 1),
+add_months(cast(null as string), 1),
+add_months('2014-01-14', cast(null as int));
+
+select
+add_months('2014-01-14 10:30:00', 1),
+add_months('2014-01-31 10:30:00', 1),
+add_months('2014-02-28 10:30:00', -1),
+add_months('2014-02-28 16:30:00', 2),
+add_months('2014-04-30 10:30:00', -2),
+add_months('2015-02-28 10:30:00', 12),
+add_months('2016-02-29 10:30:00', -12),
+add_months('2016-01-29 10:30:00', 1),
+add_months('2016-02-29 10:30:00', -1),
+add_months('2014-01-32 10:30:00', 1);
+
+select
+add_months(cast('2014-01-14 10:30:00' as timestamp), 1),
+add_months(cast('2014-01-31 10:30:00' as timestamp), 1),
+add_months(cast('2014-02-28 10:30:00' as timestamp), -1),
+add_months(cast('2014-02-28 16:30:00' as timestamp), 2),
+add_months(cast('2014-04-30 10:30:00' as timestamp), -2),
+add_months(cast('2015-02-28 10:30:00' as timestamp), 12),
+add_months(cast('2016-02-29 10:30:00' as timestamp), -12),
+add_months(cast('2016-01-29 10:30:00' as timestamp), 1),
+add_months(cast('2016-02-29 10:30:00' as timestamp), -1),
+add_months(cast(null as timestamp), 1);
\ No newline at end of file

Added: hive/trunk/ql/src/test/results/clientnegative/udf_add_months_error_1.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/udf_add_months_error_1.q.out?rev=1658591&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/udf_add_months_error_1.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/udf_add_months_error_1.q.out Mon Feb  9
22:10:26 2015
@@ -0,0 +1 @@
+FAILED: SemanticException [Error 10016]: Line 1:18 Argument type mismatch '14567893456':
ADD_MONTHS() only takes STRING/TIMESTAMP/DATEWRITABLE types as first argument, got LONG

Added: hive/trunk/ql/src/test/results/clientnegative/udf_add_months_error_2.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/udf_add_months_error_2.q.out?rev=1658591&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/udf_add_months_error_2.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/udf_add_months_error_2.q.out Mon Feb  9
22:10:26 2015
@@ -0,0 +1 @@
+FAILED: SemanticException [Error 10016]: Line 1:32 Argument type mismatch '2.4': ADD_MONTHS()
only takes INT types as second argument, got DOUBLE

Modified: hive/trunk/ql/src/test/results/clientpositive/udf_add_months.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf_add_months.q.out?rev=1658591&r1=1658590&r2=1658591&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf_add_months.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/udf_add_months.q.out Mon Feb  9 22:10:26
2015
@@ -12,3 +12,118 @@ start_date is a string in the format 'yy
 Example:
   > SELECT add_months('2009-08-31', 1) FROM src LIMIT 1;
  '2009-09-30'
+PREHOOK: query: explain select add_months('2014-01-14', 1)
+PREHOOK: type: QUERY
+POSTHOOK: query: explain select add_months('2014-01-14', 1)
+POSTHOOK: type: QUERY
+STAGE DEPENDENCIES:
+  Stage-0 is a root stage
+
+STAGE PLANS:
+  Stage: Stage-0
+    Fetch Operator
+      limit: -1
+      Processor Tree:
+        TableScan
+          alias: _dummy_table
+          Row Limit Per Split: 1
+          Statistics: Num rows: 0 Data size: 1 Basic stats: PARTIAL Column stats: COMPLETE
+          Select Operator
+            expressions: '2014-02-14' (type: string)
+            outputColumnNames: _col0
+            Statistics: Num rows: 0 Data size: 1 Basic stats: PARTIAL Column stats: COMPLETE
+            ListSink
+
+PREHOOK: query: select
+add_months('2014-01-14', 1),
+add_months('2014-01-31', 1),
+add_months('2014-02-28', -1),
+add_months('2014-02-28', 2),
+add_months('2014-04-30', -2),
+add_months('2015-02-28', 12),
+add_months('2016-02-29', -12),
+add_months('2016-01-29', 1),
+add_months('2016-02-29', -1),
+add_months('2014-01-32', 1),
+add_months('01/14/2014', 1),
+add_months(cast(null as string), 1),
+add_months('2014-01-14', cast(null as int))
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: select
+add_months('2014-01-14', 1),
+add_months('2014-01-31', 1),
+add_months('2014-02-28', -1),
+add_months('2014-02-28', 2),
+add_months('2014-04-30', -2),
+add_months('2015-02-28', 12),
+add_months('2016-02-29', -12),
+add_months('2016-01-29', 1),
+add_months('2016-02-29', -1),
+add_months('2014-01-32', 1),
+add_months('01/14/2014', 1),
+add_months(cast(null as string), 1),
+add_months('2014-01-14', cast(null as int))
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+2014-02-14	2014-02-28	2014-01-31	2014-04-30	2014-02-28	2016-02-29	2015-02-28	2016-02-29	2016-01-31
2014-03-01	NULL	NULL	NULL
+PREHOOK: query: select
+add_months('2014-01-14 10:30:00', 1),
+add_months('2014-01-31 10:30:00', 1),
+add_months('2014-02-28 10:30:00', -1),
+add_months('2014-02-28 16:30:00', 2),
+add_months('2014-04-30 10:30:00', -2),
+add_months('2015-02-28 10:30:00', 12),
+add_months('2016-02-29 10:30:00', -12),
+add_months('2016-01-29 10:30:00', 1),
+add_months('2016-02-29 10:30:00', -1),
+add_months('2014-01-32 10:30:00', 1)
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: select
+add_months('2014-01-14 10:30:00', 1),
+add_months('2014-01-31 10:30:00', 1),
+add_months('2014-02-28 10:30:00', -1),
+add_months('2014-02-28 16:30:00', 2),
+add_months('2014-04-30 10:30:00', -2),
+add_months('2015-02-28 10:30:00', 12),
+add_months('2016-02-29 10:30:00', -12),
+add_months('2016-01-29 10:30:00', 1),
+add_months('2016-02-29 10:30:00', -1),
+add_months('2014-01-32 10:30:00', 1)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+2014-02-14	2014-02-28	2014-01-31	2014-04-30	2014-02-28	2016-02-29	2015-02-28	2016-02-29	2016-01-31
2014-03-01
+PREHOOK: query: select
+add_months(cast('2014-01-14 10:30:00' as timestamp), 1),
+add_months(cast('2014-01-31 10:30:00' as timestamp), 1),
+add_months(cast('2014-02-28 10:30:00' as timestamp), -1),
+add_months(cast('2014-02-28 16:30:00' as timestamp), 2),
+add_months(cast('2014-04-30 10:30:00' as timestamp), -2),
+add_months(cast('2015-02-28 10:30:00' as timestamp), 12),
+add_months(cast('2016-02-29 10:30:00' as timestamp), -12),
+add_months(cast('2016-01-29 10:30:00' as timestamp), 1),
+add_months(cast('2016-02-29 10:30:00' as timestamp), -1),
+add_months(cast(null as timestamp), 1)
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: select
+add_months(cast('2014-01-14 10:30:00' as timestamp), 1),
+add_months(cast('2014-01-31 10:30:00' as timestamp), 1),
+add_months(cast('2014-02-28 10:30:00' as timestamp), -1),
+add_months(cast('2014-02-28 16:30:00' as timestamp), 2),
+add_months(cast('2014-04-30 10:30:00' as timestamp), -2),
+add_months(cast('2015-02-28 10:30:00' as timestamp), 12),
+add_months(cast('2016-02-29 10:30:00' as timestamp), -12),
+add_months(cast('2016-01-29 10:30:00' as timestamp), 1),
+add_months(cast('2016-02-29 10:30:00' as timestamp), -1),
+add_months(cast(null as timestamp), 1)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+2014-02-14	2014-02-28	2014-01-31	2014-04-30	2014-02-28	2016-02-29	2015-02-28	2016-02-29	2016-01-31
NULL



Mime
View raw message