use of org.apache.hadoop.hive.serde2.io.DateWritableV2 in project hive by apache.
the class TestGenericUDFDate method testTimestampToDate.
@Test
public void testTimestampToDate() throws HiveException {
GenericUDFDate udf = new GenericUDFDate();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
DeferredObject valueObj = new DeferredJavaObject(new TimestampWritableV2(Timestamp.valueOf(LocalDateTime.of(109, 06, 30, 4, 17, 52, 0).toString())));
DeferredObject[] args = { valueObj };
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
assertEquals("to_date() test for TIMESTAMP failed ", "0109-06-30", output.toString());
// Try with null args
DeferredObject[] nullArgs = { new DeferredJavaObject(null) };
output = (DateWritableV2) udf.evaluate(nullArgs);
assertNull("to_date() with null TIMESTAMP", output);
}
use of org.apache.hadoop.hive.serde2.io.DateWritableV2 in project hive by apache.
the class TestGenericUDFDateDiff method testDateWritablepToDate.
@Test
public void testDateWritablepToDate() throws HiveException {
GenericUDFDateDiff udf = new GenericUDFDateDiff();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new DateWritableV2(Date.of(109, 06, 20)));
DeferredObject valueObj2 = new DeferredJavaObject(new DateWritableV2(Date.of(109, 06, 10)));
DeferredObject[] args = { valueObj1, valueObj2 };
IntWritable output = (IntWritable) udf.evaluate(args);
assertEquals("datediff() test for DATEWRITABLE failed ", "10", output.toString());
// Test with null args
args = new DeferredObject[] { new DeferredJavaObject(null), valueObj2 };
assertNull("date_add() 1st arg null", udf.evaluate(args));
args = new DeferredObject[] { valueObj1, new DeferredJavaObject(null) };
assertNull("date_add() 2nd arg null", udf.evaluate(args));
args = new DeferredObject[] { new DeferredJavaObject(null), new DeferredJavaObject(null) };
assertNull("date_add() both args null", udf.evaluate(args));
}
use of org.apache.hadoop.hive.serde2.io.DateWritableV2 in project hive by apache.
the class TestGenericUDFDateSub method testDateWritablepToDate.
@Test
public void testDateWritablepToDate() throws HiveException {
GenericUDFDateSub udf = new GenericUDFDateSub();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new DateWritableV2(Date.of(109, 06, 20)));
DeferredObject valueObj2 = new DeferredJavaObject(Integer.valueOf(4));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
assertEquals("date_sub() test for DATEWRITABLE failed ", "0109-06-16", output.toString());
// Test with null args
args = new DeferredObject[] { new DeferredJavaObject(null), valueObj2 };
assertNull("date_add() 1st arg null", udf.evaluate(args));
args = new DeferredObject[] { valueObj1, new DeferredJavaObject(null) };
assertNull("date_add() 2nd arg null", udf.evaluate(args));
args = new DeferredObject[] { new DeferredJavaObject(null), new DeferredJavaObject(null) };
assertNull("date_add() both args null", udf.evaluate(args));
}
use of org.apache.hadoop.hive.serde2.io.DateWritableV2 in project hive by apache.
the class TestGenericUDFDateSub method testShortDataTypeAsDays.
@Test
public void testShortDataTypeAsDays() throws HiveException {
GenericUDFDateSub udf = new GenericUDFDateSub();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaShortObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new DateWritableV2(Date.of(109, 06, 20)));
DeferredObject valueObj2 = new DeferredJavaObject(Short.valueOf("4"));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
assertEquals("date_add() test for SHORT failed ", "0109-06-16", output.toString());
}
use of org.apache.hadoop.hive.serde2.io.DateWritableV2 in project hive by apache.
the class TestGenericUDFDate method testVoidToDate.
@Test
public void testVoidToDate() throws HiveException {
GenericUDFDate udf = new GenericUDFDate();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableVoidObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
DeferredObject[] args = { new DeferredJavaObject(null) };
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
// Try with null VOID
assertNull("to_date() with null DATE ", output);
// Try with erroneously generated VOID
DeferredObject[] junkArgs = { new DeferredJavaObject(new Text("2015-11-22")) };
try {
udf.evaluate(junkArgs);
fail("to_date() test with VOID non-null failed");
} catch (UDFArgumentException udfae) {
assertEquals("TO_DATE() received non-null object of VOID type", udfae.getMessage());
}
}
Aggregations