Search in sources :

Example 41 with PrimitiveObjectInspectorFactory.writableTimestampObjectInspector

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));
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) Test(org.junit.Test)

Example 42 with PrimitiveObjectInspectorFactory.writableTimestampObjectInspector

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");
}
Also used : ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Test(org.junit.Test)

Aggregations

TimestampWritableV2 (org.apache.hadoop.hive.serde2.io.TimestampWritableV2)27 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)27 Test (org.junit.Test)25 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)13 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)13 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)11 IntWritable (org.apache.hadoop.io.IntWritable)10 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)6 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)5 TimestampConverter (org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter.TimestampConverter)5 Text (org.apache.hadoop.io.Text)5 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)4 Timestamp (org.apache.hadoop.hive.common.type.Timestamp)3 DateWritableV2 (org.apache.hadoop.hive.serde2.io.DateWritableV2)3 HiveIntervalDayTimeWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable)3 HiveIntervalYearMonthWritable (org.apache.hadoop.hive.serde2.io.HiveIntervalYearMonthWritable)3 ConstantObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)3 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)3 OrderExpressionDef (org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef)2 PTFExpressionDef (org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef)2