public void testWrongTsStr() throws HiveException { GenericUDFAddMonths udf = new GenericUDFAddMonths(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector[] arguments = { valueOI0, valueOI1 }; udf.initialize(arguments); runAndVerify("2014-02-30 10:30:00", 1, "2014-04-02", udf); runAndVerify("2014-02-32 10:30:00", 1, "2014-04-04", udf); runAndVerify("2014/01/31 10:30:00", 1, null, udf); runAndVerify("2014-01-31T10:30:00", 1, "2014-02-28", udf); }
public void testAddMonthsInt() throws HiveException { GenericUDFAddMonths udf = new GenericUDFAddMonths(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector[] arguments = { valueOI0, valueOI1 }; udf.initialize(arguments); // date str runAndVerify("2014-01-14", 1, "2014-02-14", udf); runAndVerify("2014-01-31", 1, "2014-02-28", udf); runAndVerify("2014-02-28", -1, "2014-01-31", udf); runAndVerify("2014-02-28", 2, "2014-04-30", udf); runAndVerify("2014-04-30", -2, "2014-02-28", udf); runAndVerify("2015-02-28", 12, "2016-02-29", udf); 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); // ts str runAndVerify("2014-01-14 10:30:00", 1, "2014-02-14", udf); runAndVerify("2014-01-31 10:30:00", 1, "2014-02-28", udf); runAndVerify("2014-02-28 10:30:00.1", -1, "2014-01-31", udf); runAndVerify("2014-02-28 10:30:00.100", 2, "2014-04-30", udf); runAndVerify("2014-04-30 10:30:00.001", -2, "2014-02-28", udf); runAndVerify("2015-02-28 10:30:00.000000001", 12, "2016-02-29", udf); runAndVerify("2016-02-29 10:30:00", -12, "2015-02-28", udf); runAndVerify("2016-01-29 10:30:00", 1, "2016-02-29", udf); runAndVerify("2016-02-29 10:30:00", -1, "2016-01-31", udf); runAndVerify("2016-02-29 10:30:00", -1, fmtTextWithoutTime, "2016-01-31", udf); }
public void testWrongDateStr() throws HiveException { GenericUDFAddMonths udf = new GenericUDFAddMonths(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector[] arguments = { valueOI0, valueOI1 }; udf.initialize(arguments); runAndVerify("2014-02-30", 1, "2014-04-02", udf); runAndVerify("2014-02-32", 1, "2014-04-04", udf); runAndVerify("2014-01", 1, null, udf); }
public void testAddMonthsStringWithTime() throws HiveException { GenericUDFAddMonths udf = new GenericUDFAddMonths(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory .getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.stringTypeInfo, fmtTextWithTime); ObjectInspector[] arguments = {valueOI0, valueOI1, valueOI2}; udf.initialize(arguments); runAndVerify("2018-05-10 08:15:12", -1, fmtTextWithTime, "2018-04-10 08:15:12", udf); runAndVerify("2017-12-31 14:15:16", 2, fmtTextWithTime, "2018-02-28 14:15:16", udf); runAndVerify("2017-12-31 14:15:16.001", 2, fmtTextWithTime, "2018-02-28 14:15:16", udf); }
public void testAddMonthsStringWithTimeWithms() throws HiveException { GenericUDFAddMonths udf = new GenericUDFAddMonths(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory .getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.stringTypeInfo, fmtTextWithTimeAndms); ObjectInspector[] arguments = {valueOI0, valueOI1, valueOI2}; udf.initialize(arguments); runAndVerify("2017-12-31 14:15:16.350", 2, fmtTextWithTimeAndms, "2018-02-28 14:15:16.350", udf); runAndVerify("2017-12-31 14:15:16.001", 2, fmtTextWithTimeAndms, "2018-02-28 14:15:16.001", udf); //Try to parse ms where there is no millisecond part in input, expected to return .000 as ms runAndVerify("2017-12-31 14:15:16", 2, fmtTextWithTimeAndms, "2018-02-28 14:15:16.000", udf); }
public void testAddMonthsWithNullFormatter() throws HiveException { GenericUDFAddMonths udf = new GenericUDFAddMonths(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory .getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.stringTypeInfo, null); ObjectInspector[] arguments = {valueOI0, valueOI1, valueOI2}; udf.initialize(arguments); runAndVerify("2017-12-31 14:15:16.350", 2, null, "2018-02-28", udf); runAndVerify("2017-12-31", 2, null, "2018-02-28", udf); } public void testAddMonthsTimestamp() throws HiveException {
public void testAddMonthsByte() throws HiveException { GenericUDFAddMonths udf = new GenericUDFAddMonths(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableByteObjectInspector; ObjectInspector[] arguments = { valueOI0, valueOI1 }; udf.initialize(arguments); // short runAndVerify("2014-01-14", (byte) 1, "2014-02-14", udf); }
public void testAddMonthsShort() throws HiveException { GenericUDFAddMonths udf = new GenericUDFAddMonths(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableShortObjectInspector; ObjectInspector[] arguments = { valueOI0, valueOI1 }; udf.initialize(arguments); // short runAndVerify("2014-01-14", (short) 1, "2014-02-14", udf); }
public void testAddMonthsTimestamp() throws HiveException { GenericUDFAddMonths udf = new GenericUDFAddMonths(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector; ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory .getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.stringTypeInfo, fmtTextWithTime); ObjectInspector[] arguments = {valueOI0, valueOI1, valueOI2}; udf.initialize(arguments); runAndVerify(Timestamp.valueOf("2018-05-10 08:15:12"), 1, fmtTextWithTime, "2018-06-10 08:15:12", udf); runAndVerify(Timestamp.valueOf("2017-12-31 14:15:16"), 2, fmtTextWithTime, "2018-02-28 14:15:16", udf); }