Search in sources :

Example 16 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFRTrim method testTrim.

public void testTrim() throws HiveException {
    GenericUDFRTrim udf = new GenericUDFRTrim();
    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 : GenericUDFRTrim(org.apache.hadoop.hive.ql.udf.generic.GenericUDFRTrim) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Example 17 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFRegexp method testConstant.

public void testConstant() throws HiveException {
    GenericUDFRegExp udf = new GenericUDFRegExp();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    Text regexText = new Text("^fo");
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.stringTypeInfo, regexText);
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    runAndVerifyConst("fofo", regexText, true, udf);
    runAndVerifyConst("fofofo", regexText, true, udf);
    runAndVerifyConst("fobar", regexText, true, udf);
    runAndVerifyConst("barfobar", regexText, false, udf);
    // null
    runAndVerifyConst(null, regexText, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Text(org.apache.hadoop.io.Text)

Example 18 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFRegexp method testEmptyConstant.

public void testEmptyConstant() throws HiveException {
    GenericUDFRegExp udf = new GenericUDFRegExp();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    Text regexText = new Text("");
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.stringTypeInfo, regexText);
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    // empty regex (should be one WARN message)
    runAndVerifyConst("foo", regexText, false, udf);
    runAndVerifyConst("bar", regexText, false, udf);
    // null
    runAndVerifyConst(null, regexText, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Text(org.apache.hadoop.io.Text)

Example 19 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFSoundex method testSoundex.

public void testSoundex() throws HiveException {
    GenericUDFSoundex udf = new GenericUDFSoundex();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI0 };
    udf.initialize(arguments);
    runAndVerify("Miller", "M460", udf);
    runAndVerify("miler", "M460", udf);
    runAndVerify("myller", "M460", udf);
    runAndVerify("muller", "M460", udf);
    runAndVerify("m", "M000", udf);
    runAndVerify("mu", "M000", udf);
    runAndVerify("mil", "M400", udf);
    runAndVerify("Peterson", "P362", udf);
    runAndVerify("Pittersen", "P362", udf);
    runAndVerify("", "", udf);
    runAndVerify(null, null, udf);
    runAndVerify("㔀㔁㔂㔃", null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Example 20 with PrimitiveObjectInspectorFactory.writableStringObjectInspector

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

the class TestGenericUDFSubstringIndex method testSubstringIndex.

public void testSubstringIndex() throws HiveException {
    GenericUDFSubstringIndex udf = new GenericUDFSubstringIndex();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
    ObjectInspector[] arguments = { valueOI0, valueOI1, valueOI2 };
    udf.initialize(arguments);
    runAndVerify("www.apache.org", ".", 3, "www.apache.org", udf);
    runAndVerify("www.apache.org", ".", 2, "www.apache", udf);
    runAndVerify("www.apache.org", ".", 1, "www", udf);
    runAndVerify("www.apache.org", ".", 0, "", udf);
    runAndVerify("www.apache.org", ".", -1, "org", udf);
    runAndVerify("www.apache.org", ".", -2, "apache.org", udf);
    runAndVerify("www.apache.org", ".", -3, "www.apache.org", udf);
    // str is empty string
    runAndVerify("", ".", 1, "", udf);
    // empty string delim
    runAndVerify("www.apache.org", "", 1, "", udf);
    // delim does not exist in str
    runAndVerify("www.apache.org", "-", 2, "www.apache.org", udf);
    // delim is 2 chars
    runAndVerify("www||apache||org", "||", 2, "www||apache", udf);
    // null
    runAndVerify(null, ".", 2, null, udf);
    runAndVerify("www.apache.org", null, 2, null, udf);
    runAndVerify("www.apache.org", ".", null, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)90 Text (org.apache.hadoop.io.Text)41 Test (org.junit.Test)29 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)27 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)15 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)15 IntWritable (org.apache.hadoop.io.IntWritable)14 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 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)9 ArrayList (java.util.ArrayList)8 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)8 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 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)5 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)4 TimestampConverter (org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter.TimestampConverter)4 LongWritable (org.apache.hadoop.io.LongWritable)4