Search in sources :

Example 71 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFAbs method testText.

public void testText() throws HiveException {
    GenericUDFAbs udf = new GenericUDFAbs();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf.initialize(arguments);
    DeferredObject valueObj = new DeferredJavaObject(new Text("123.45"));
    DeferredObject[] args = { valueObj };
    DoubleWritable output = (DoubleWritable) udf.evaluate(args);
    assertEquals("abs() test for String failed ", "123.45", output.toString());
    valueObj = new DeferredJavaObject(new Text("-123.45"));
    args[0] = valueObj;
    output = (DoubleWritable) udf.evaluate(args);
    assertEquals("abs() test for String failed ", "123.45", output.toString());
    valueObj = new DeferredJavaObject(new Text("foo"));
    args[0] = valueObj;
    output = (DoubleWritable) udf.evaluate(args);
    assertEquals("abs() test for String failed ", null, output);
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) GenericUDFAbs(org.apache.hadoop.hive.ql.udf.generic.GenericUDFAbs) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) Text(org.apache.hadoop.io.Text) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable)

Example 72 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFAddMonths method testAddMonthsByte.

public void testAddMonthsByte() throws HiveException {
    GenericUDFAddMonths udf = new GenericUDFAddMonths();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableByteObjectInspector;
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    // short
    runAndVerify("2014-01-14", (byte) 1, "2014-02-14", udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Example 73 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFAddMonths method testAddMonthsLong.

public void testAddMonthsLong() throws HiveException {
    @SuppressWarnings("resource") GenericUDFAddMonths udf = new GenericUDFAddMonths();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    try {
        udf.initialize(arguments);
        assertTrue("add_months exception expected", false);
    } catch (UDFArgumentTypeException e) {
        assertEquals("add_months test", "add_months only takes INT/SHORT/BYTE types as 2nd argument, got LONG", e.getMessage());
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)

Example 74 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFAesDecrypt method testAesDecKeyNullStr.

@Test
public void testAesDecKeyNullStr() throws HiveException {
    GenericUDFAesDecrypt udf = new GenericUDFAesDecrypt();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    Text keyWr = null;
    runAndVerifyStr("y6Ss+zCYObpCbgfWfyNWTw==", keyWr, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 75 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFAesEncrypt method testAesEnc128Str.

@Test
public void testAesEnc128Str() throws HiveException {
    GenericUDFAesEncrypt udf = new GenericUDFAesEncrypt();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    Text keyWr = new Text("1234567890123456");
    runAndVerifyStr("ABC", keyWr, "y6Ss+zCYObpCbgfWfyNWTw==", udf);
    runAndVerifyStr("", keyWr, "BQGHoM3lqYcsurCRq3PlUw==", udf);
    // null
    runAndVerifyStr(null, keyWr, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

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