Search in sources :

Example 1 with GenericUDFDate

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFDate in project hive by apache.

the class TestGenericUDFDate method testDateWritablepToDate.

public void testDateWritablepToDate() throws HiveException {
    GenericUDFDate udf = new GenericUDFDate();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf.initialize(arguments);
    DeferredObject valueObj = new DeferredJavaObject(new DateWritable(new Date(109, 06, 30)));
    DeferredObject[] args = { valueObj };
    DateWritable output = (DateWritable) udf.evaluate(args);
    assertEquals("to_date() test for DATEWRITABLE failed ", "2009-07-30", output.toString());
    // Try with null args
    DeferredObject[] nullArgs = { new DeferredJavaObject(null) };
    output = (DateWritable) udf.evaluate(nullArgs);
    assertNull("to_date() with null DATE", output);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) GenericUDFDate(org.apache.hadoop.hive.ql.udf.generic.GenericUDFDate) GenericUDFDate(org.apache.hadoop.hive.ql.udf.generic.GenericUDFDate) Date(java.sql.Date)

Example 2 with GenericUDFDate

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFDate in project hive by apache.

the class TestGenericUDFDate method testStringToDate.

public void testStringToDate() throws HiveException {
    GenericUDFDate udf = new GenericUDFDate();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf.initialize(arguments);
    DeferredObject valueObj = new DeferredJavaObject(new Text("2009-07-30"));
    DeferredObject[] args = { valueObj };
    DateWritable output = (DateWritable) udf.evaluate(args);
    assertEquals("to_date() test for STRING failed ", "2009-07-30", output.toString());
    // Try with null args
    DeferredObject[] nullArgs = { new DeferredJavaObject(null) };
    output = (DateWritable) udf.evaluate(nullArgs);
    assertNull("to_date() with null STRING", output);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) GenericUDFDate(org.apache.hadoop.hive.ql.udf.generic.GenericUDFDate) Text(org.apache.hadoop.io.Text)

Example 3 with GenericUDFDate

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFDate in project hive by apache.

the class TestGenericUDFDate method testTimestampToDate.

public void testTimestampToDate() throws HiveException {
    GenericUDFDate udf = new GenericUDFDate();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf.initialize(arguments);
    DeferredObject valueObj = new DeferredJavaObject(new TimestampWritable(new Timestamp(109, 06, 30, 4, 17, 52, 0)));
    DeferredObject[] args = { valueObj };
    DateWritable output = (DateWritable) udf.evaluate(args);
    assertEquals("to_date() test for TIMESTAMP failed ", "2009-07-30", output.toString());
    // Try with null args
    DeferredObject[] nullArgs = { new DeferredJavaObject(null) };
    output = (DateWritable) udf.evaluate(nullArgs);
    assertNull("to_date() with null TIMESTAMP", output);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) GenericUDFDate(org.apache.hadoop.hive.ql.udf.generic.GenericUDFDate) Timestamp(java.sql.Timestamp)

Example 4 with GenericUDFDate

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFDate in project hive by apache.

the class TestGenericUDFDate method testVoidToDate.

public void testVoidToDate() throws HiveException {
    GenericUDFDate udf = new GenericUDFDate();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableVoidObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf.initialize(arguments);
    DeferredObject[] args = { new DeferredJavaObject(null) };
    DateWritable output = (DateWritable) 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());
    }
}
Also used : UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) GenericUDFDate(org.apache.hadoop.hive.ql.udf.generic.GenericUDFDate) Text(org.apache.hadoop.io.Text)

Aggregations

DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)4 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)4 GenericUDFDate (org.apache.hadoop.hive.ql.udf.generic.GenericUDFDate)4 DateWritable (org.apache.hadoop.hive.serde2.io.DateWritable)4 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)4 Text (org.apache.hadoop.io.Text)2 Date (java.sql.Date)1 Timestamp (java.sql.Timestamp)1 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)1 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)1