Search in sources :

Example 86 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFToUnixTimestamp method testString.

public void testString() throws HiveException {
    GenericUDFToUnixTimeStamp udf1 = new GenericUDFToUnixTimeStamp();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf1.initialize(arguments);
    String val = "2001-01-01 01:02:03";
    runAndVerify(udf1, new Text(val), new LongWritable(Timestamp.valueOf(val).getTime() / 1000));
    // test null values
    runAndVerify(udf1, null, null);
    // Try 2-arg version
    GenericUDFToUnixTimeStamp udf2 = new GenericUDFToUnixTimeStamp();
    ObjectInspector[] args2 = { valueOI, valueOI };
    udf2.initialize(args2);
    val = "2001-01-01";
    String format = "yyyy-MM-dd";
    runAndVerify(udf2, new Text(val), new Text(format), new LongWritable(Date.valueOf(val).getTime() / 1000));
    // test null values
    runAndVerify(udf2, null, null, null);
    runAndVerify(udf2, null, new Text(format), null);
    runAndVerify(udf2, new Text(val), null, null);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Text(org.apache.hadoop.io.Text) LongWritable(org.apache.hadoop.io.LongWritable)

Example 87 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFTrim method testTrim.

public void testTrim() throws HiveException {
    GenericUDFTrim udf = new GenericUDFTrim();
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI };
    udf.initialize(arguments);
    runAndVerify(" Hello World! ", "Hello World!", udf);
    runAndVerify("Hello World! ", "Hello World!", udf);
    runAndVerify(" Hello World!", "Hello World!", udf);
    runAndVerify("Hello World!", "Hello World!", udf);
    runAndVerify("   ", "", udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) GenericUDFTrim(org.apache.hadoop.hive.ql.udf.generic.GenericUDFTrim)

Example 88 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFRpad method testRpad.

public void testRpad() throws HiveException {
    GenericUDFRpad udf = new GenericUDFRpad();
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
    ObjectInspector valueOI3 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI1, valueOI2, valueOI3 };
    udf.initialize(arguments);
    runAndVerify("hi", 5, "??", "hi???", udf);
    runAndVerify("hi", 1, "??", "h", udf);
    runAndVerify("hi", 5, "??", "hi???", udf);
    runAndVerify("hi", 1, "??", "h", udf);
    runAndVerify("hi", 3, "", null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Example 89 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFSha2 method testSha200Str.

public void testSha200Str() throws HiveException {
    GenericUDFSha2 udf = new GenericUDFSha2();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    IntWritable lenWr = new IntWritable(200);
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, lenWr);
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    runAndVerifyStr("ABC", lenWr, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) IntWritable(org.apache.hadoop.io.IntWritable)

Example 90 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFSha2 method testSha512Str.

public void testSha512Str() throws HiveException {
    GenericUDFSha2 udf = new GenericUDFSha2();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    IntWritable lenWr = new IntWritable(512);
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, lenWr);
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    runAndVerifyStr("ABC", lenWr, "397118fdac8d83ad98813c50759c85b8c47565d8268bf10da483153b747a74743a58a90e85aa9f705ce6984ffc128db567489817e4092d050d8a1cc596ddc119", udf);
    runAndVerifyStr("", lenWr, "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", udf);
    // null
    runAndVerifyStr(null, lenWr, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) IntWritable(org.apache.hadoop.io.IntWritable)

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