Search in sources :

Example 46 with PrimitiveObjectInspectorFactory.writableIntObjectInspector

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

the class TestGenericUDFSoundex method testSoundexWrongType0.

public void testSoundexWrongType0() throws HiveException {
    @SuppressWarnings("resource") GenericUDFSoundex udf = new GenericUDFSoundex();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
    ObjectInspector[] arguments = { valueOI0 };
    try {
        udf.initialize(arguments);
        assertTrue("soundex test. UDFArgumentTypeException is expected", false);
    } catch (UDFArgumentTypeException e) {
        assertEquals("soundex test", "soundex only takes STRING_GROUP types as 1st argument, got INT", e.getMessage());
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)

Example 47 with PrimitiveObjectInspectorFactory.writableIntObjectInspector

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

the class TestGenericUDFLevenshtein method testLevenshteinWrongType0.

public void testLevenshteinWrongType0() throws HiveException {
    @SuppressWarnings("resource") GenericUDFLevenshtein udf = new GenericUDFLevenshtein();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    try {
        udf.initialize(arguments);
        assertTrue("levenshtein test. UDFArgumentTypeException is expected", false);
    } catch (UDFArgumentTypeException e) {
        assertEquals("levenshtein test", "levenshtein only takes STRING_GROUP, VOID_GROUP types as 1st argument, got INT", e.getMessage());
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)

Example 48 with PrimitiveObjectInspectorFactory.writableIntObjectInspector

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

the class GenericUDFWidthBucket method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    this.objectInspectors = arguments;
    checkArgsSize(arguments, 4, 4);
    checkArgPrimitive(arguments, 0);
    checkArgPrimitive(arguments, 1);
    checkArgPrimitive(arguments, 2);
    checkArgPrimitive(arguments, 3);
    PrimitiveObjectInspector.PrimitiveCategory[] inputTypes = new PrimitiveObjectInspector.PrimitiveCategory[4];
    checkArgGroups(arguments, 0, inputTypes, NUMERIC_GROUP, VOID_GROUP);
    checkArgGroups(arguments, 1, inputTypes, NUMERIC_GROUP, VOID_GROUP);
    checkArgGroups(arguments, 2, inputTypes, NUMERIC_GROUP, VOID_GROUP);
    checkArgGroups(arguments, 3, inputTypes, NUMERIC_GROUP, VOID_GROUP);
    TypeInfo exprTypeInfo = TypeInfoUtils.getTypeInfoFromObjectInspector(this.objectInspectors[0]);
    TypeInfo minValueTypeInfo = TypeInfoUtils.getTypeInfoFromObjectInspector(this.objectInspectors[1]);
    TypeInfo maxValueTypeInfo = TypeInfoUtils.getTypeInfoFromObjectInspector(this.objectInspectors[2]);
    TypeInfo commonExprMinMaxTypeInfo = FunctionRegistry.getCommonClassForComparison(exprTypeInfo, FunctionRegistry.getCommonClassForComparison(minValueTypeInfo, maxValueTypeInfo));
    this.commonExprMinMaxOI = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(commonExprMinMaxTypeInfo);
    this.epxrConverterOI = ObjectInspectorConverters.getConverter(this.objectInspectors[0], this.commonExprMinMaxOI);
    this.minValueConverterOI = ObjectInspectorConverters.getConverter(this.objectInspectors[1], this.commonExprMinMaxOI);
    this.maxValueConverterOI = ObjectInspectorConverters.getConverter(this.objectInspectors[2], this.commonExprMinMaxOI);
    return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
}
Also used : TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)42 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)25 IntWritable (org.apache.hadoop.io.IntWritable)17 Test (org.junit.Test)14 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)12 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)12 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)10 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)10 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)8 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)8 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)6 LongWritable (org.apache.hadoop.io.LongWritable)4 Text (org.apache.hadoop.io.Text)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)3 Converter (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter)3 PrimitiveObjectInspectorConverter (org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter)3 ArrayList (java.util.ArrayList)2 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)2 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)2 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)2