use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableTimestampObjectInspector in project hive by apache.
the class TestGenericUDFDateAdd method testTimestampToDate.
@Test
public void testTimestampToDate() throws HiveException {
GenericUDFDateAdd udf = new GenericUDFDateAdd();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
ObjectInspector[] arguments = { valueOI1, valueOI2 };
udf.initialize(arguments);
DeferredObject valueObj1 = new DeferredJavaObject(new TimestampWritableV2(Timestamp.valueOf(LocalDateTime.of(109, 06, 20, 4, 17, 52, 0).toString())));
DeferredObject valueObj2 = new DeferredJavaObject(Integer.valueOf("3"));
DeferredObject[] args = { valueObj1, valueObj2 };
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
assertEquals("date_add() test for TIMESTAMP failed ", "0109-06-23", 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.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableTimestampObjectInspector in project hive by apache.
the class TestGenericUDFCastFormat method testTimestampToStringTypesWithFormat.
@Test
public void testTimestampToStringTypesWithFormat() throws HiveException {
ObjectInspector inputOI = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
testCast(STRING, inputOI, timestamp("2009-07-30 00:00:08"), "yyyy-MM-dd HH24:mi:ss", "2009-07-30 00:00:08");
testCast(STRING, inputOI, timestamp("2009-07-30 11:02:00"), "MM/dd/yyyy hh24miss", "07/30/2009 110200");
testCast(STRING, inputOI, timestamp("2009-07-30 01:02:03"), "MM", "07");
testCast(STRING, inputOI, timestamp("1969-07-30 00:00:00"), "yy", "69");
testCast(CHAR, 3, inputOI, timestamp("2009-07-30 00:00:08"), "yyyy-MM-dd HH24:mi:ss", "200");
testCast(CHAR, 3, inputOI, timestamp("2009-07-30 11:02:00"), "MM/dd/yyyy hh24miss", "07/");
testCast(CHAR, 3, inputOI, timestamp("2009-07-30 01:02:03"), "MM", "07 ");
testCast(CHAR, 3, inputOI, timestamp("1969-07-30 00:00:00"), "yy", "69 ");
testCast(VARCHAR, 3, inputOI, timestamp("2009-07-30 00:00:08"), "yyyy-MM-dd HH24:mi:ss", "200");
testCast(VARCHAR, 3, inputOI, timestamp("2009-07-30 11:02:00"), "MM/dd/yyyy hh24miss", "07/");
testCast(VARCHAR, 3, inputOI, timestamp("2009-07-30 01:02:03"), "MM", "07");
testCast(VARCHAR, 3, inputOI, timestamp("1969-07-30 00:00:00"), "yy", "69");
}
Aggregations