Search in sources :

Example 91 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector in project hive by apache.

the class TestGenericUDFQuarter method testQuarterDt.

public void testQuarterDt() throws HiveException {
    GenericUDFQuarter udf = new GenericUDFQuarter();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
    ObjectInspector[] arguments = { valueOI0 };
    udf.initialize(arguments);
    // positive Unix time
    runAndVerifyDt("2014-01-01", 1, udf);
    runAndVerifyDt("2014-02-10", 1, udf);
    runAndVerifyDt("2014-03-31", 1, udf);
    runAndVerifyDt("2014-04-02", 2, udf);
    runAndVerifyDt("2014-05-28", 2, udf);
    runAndVerifyDt("2016-06-03", 2, udf);
    runAndVerifyDt("2016-07-28", 3, udf);
    runAndVerifyDt("2016-08-29", 3, udf);
    runAndVerifyDt("2016-09-29", 3, udf);
    runAndVerifyDt("2016-10-29", 4, udf);
    runAndVerifyDt("2016-11-29", 4, udf);
    runAndVerifyDt("2016-12-31", 4, udf);
    // negative Unix time
    runAndVerifyDt("1966-01-01", 1, udf);
    runAndVerifyDt("1966-03-31", 1, udf);
    runAndVerifyDt("1966-04-01", 2, udf);
    runAndVerifyDt("1966-12-31", 4, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Example 92 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector 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 93 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector 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 94 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector 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 95 with ObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector 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)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)700 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)299 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)261 Test (org.junit.Test)241 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)163 ArrayList (java.util.ArrayList)159 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)159 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)107 Text (org.apache.hadoop.io.Text)103 MapObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector)89 StringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)75 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)73 StructField (org.apache.hadoop.hive.serde2.objectinspector.StructField)66 IntWritable (org.apache.hadoop.io.IntWritable)65 LongObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector)58 LongWritable (org.apache.hadoop.io.LongWritable)54 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)53 IntObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector)53 DoubleObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector)51 BytesWritable (org.apache.hadoop.io.BytesWritable)51