Search in sources :

Example 51 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.

the class TestGenericUDFLikeAll method testNull.

@Test
public void testNull() throws HiveException {
    udf = new GenericUDFLikeAll();
    ObjectInspector valueOIOne = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOITwo = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOIThree = PrimitiveObjectInspectorFactory.writableVoidObjectInspector;
    ObjectInspector[] arguments = { valueOIOne, valueOITwo, valueOIThree };
    udf.initialize(arguments);
    DeferredObject valueObjOne = new DeferredJavaObject(new Text("linkedin"));
    DeferredObject valueObjTwo = new DeferredJavaObject(new Text("%oo%"));
    DeferredObject valueObjThree = new DeferredJavaObject(NullWritable.get());
    DeferredObject[] args = { valueObjOne, valueObjTwo, valueObjThree };
    BooleanWritable output = (BooleanWritable) udf.evaluate(args);
    assertEquals(null, output);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) BooleanWritable(org.apache.hadoop.io.BooleanWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 52 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.

the class TestGenericUDFLikeAll method expectException.

@Test(expected = UDFArgumentException.class)
public void expectException() throws HiveException {
    udf = new GenericUDFLikeAll();
    ObjectInspector valueOIOne = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOIOne };
    udf.initialize(arguments);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Test(org.junit.Test)

Example 53 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.

the class TestGenericUDFLikeAny method testNull.

@Test
public void testNull() throws HiveException {
    udf = new GenericUDFLikeAny();
    ObjectInspector valueOIOne = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOITwo = PrimitiveObjectInspectorFactory.writableVoidObjectInspector;
    ObjectInspector valueOIThree = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOIOne, valueOITwo, valueOIThree };
    udf.initialize(arguments);
    DeferredObject valueObjOne = new DeferredJavaObject(new Text("abc"));
    DeferredObject valueObjTwo = new DeferredJavaObject(NullWritable.get());
    DeferredObject valueObjThree = new DeferredJavaObject(new Text("%b%"));
    DeferredObject[] args = { valueObjOne, valueObjTwo, valueObjThree };
    BooleanWritable output = (BooleanWritable) udf.evaluate(args);
    assertEquals(null, output);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) BooleanWritable(org.apache.hadoop.io.BooleanWritable) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 54 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.

the class TestGenericUDFLikeAny method testTrue.

@Test
public void testTrue() throws HiveException {
    udf = new GenericUDFLikeAny();
    ObjectInspector valueOIOne = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOITwo = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOIThree = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOIOne, valueOITwo, valueOIThree };
    udf.initialize(arguments);
    DeferredJavaObject valueObjOne = new DeferredJavaObject(new Text("abc"));
    DeferredJavaObject valueObjTwo = new DeferredJavaObject(new Text("%b%"));
    HiveVarchar vc = new HiveVarchar();
    vc.setValue("a%");
    GenericUDF.DeferredJavaObject[] args = { valueObjOne, valueObjTwo, new GenericUDF.DeferredJavaObject(new HiveVarcharWritable(vc)) };
    BooleanWritable output = (BooleanWritable) udf.evaluate(args);
    assertEquals(true, output.get());
}
Also used : DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) BooleanWritable(org.apache.hadoop.io.BooleanWritable) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) Text(org.apache.hadoop.io.Text) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) Test(org.junit.Test)

Example 55 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector in project hive by apache.

the class TestGenericUDFNextDay method testNextDay.

public void testNextDay() throws HiveException {
    GenericUDFNextDay udf = new GenericUDFNextDay();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    // start_date is Sun, 2 letters day name
    runAndVerify("2015-01-11", "su", "2015-01-18", udf);
    runAndVerify("2015-01-11", "MO", "2015-01-12", udf);
    runAndVerify("2015-01-11", "Tu", "2015-01-13", udf);
    runAndVerify("2015-01-11", "wE", "2015-01-14", udf);
    runAndVerify("2015-01-11", "th", "2015-01-15", udf);
    runAndVerify("2015-01-11", "FR", "2015-01-16", udf);
    runAndVerify("2015-01-11", "Sa", "2015-01-17", udf);
    // start_date is Sat, 3 letters day name
    runAndVerify("2015-01-17", "sun", "2015-01-18", udf);
    runAndVerify("2015-01-17", "MON", "2015-01-19", udf);
    runAndVerify("2015-01-17", "Tue", "2015-01-20", udf);
    runAndVerify("2015-01-17", "weD", "2015-01-21", udf);
    runAndVerify("2015-01-17", "tHu", "2015-01-22", udf);
    runAndVerify("2015-01-17", "FrI", "2015-01-23", udf);
    runAndVerify("2015-01-17", "SAt", "2015-01-24", udf);
    // start_date is Wed, full timestamp, full day name
    runAndVerify("2015-01-14 14:04:34", "sunday", "2015-01-18", udf);
    runAndVerify("2015-01-14 14:04:34.1", "Monday", "2015-01-19", udf);
    runAndVerify("2015-01-14 14:04:34.100", "Tuesday", "2015-01-20", udf);
    runAndVerify("2015-01-14 14:04:34.001", "wednesday", "2015-01-21", udf);
    runAndVerify("2015-01-14 14:04:34.000000001", "thursDAY", "2015-01-15", udf);
    runAndVerify("2015-01-14 14:04:34", "FRIDAY", "2015-01-16", udf);
    runAndVerify("2015-01-14 14:04:34", "SATurday", "2015-01-17", udf);
    // null values
    runAndVerify("2015-01-14", null, null, udf);
    runAndVerify(null, "SU", null, udf);
    runAndVerify(null, null, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)105 Text (org.apache.hadoop.io.Text)46 Test (org.junit.Test)36 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)27 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)19 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)17 IntWritable (org.apache.hadoop.io.IntWritable)15 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)13 ConstantObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)12 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)10 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)10 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)9 ArrayList (java.util.ArrayList)8 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)8 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)7 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)7 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)6 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)6 BooleanWritable (org.apache.hadoop.io.BooleanWritable)6 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)4