Search in sources :

Example 31 with PrimitiveObjectInspectorFactory.writableIntObjectInspector

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

the class GenericUDFSize method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 1) {
        throw new UDFArgumentLengthException("The function SIZE only accepts 1 argument.");
    }
    Category category = arguments[0].getCategory();
    String typeName = arguments[0].getTypeName();
    if (category != Category.MAP && category != Category.LIST && !typeName.equals(serdeConstants.VOID_TYPE_NAME)) {
        throw new UDFArgumentTypeException(0, "\"" + Category.MAP.toString().toLowerCase() + "\" or \"" + Category.LIST.toString().toLowerCase() + "\" is expected at function SIZE, " + "but \"" + arguments[0].getTypeName() + "\" is found");
    }
    returnOI = arguments[0];
    return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
}
Also used : Category(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)

Example 32 with PrimitiveObjectInspectorFactory.writableIntObjectInspector

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

the class GenericUDFAbs method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 1) {
        throw new UDFArgumentLengthException("ABS() requires 1 argument, got " + arguments.length);
    }
    if (arguments[0].getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentException("ABS only takes primitive types, got " + arguments[0].getTypeName());
    }
    argumentOI = (PrimitiveObjectInspector) arguments[0];
    inputType = argumentOI.getPrimitiveCategory();
    ObjectInspector outputOI = null;
    switch(inputType) {
        case SHORT:
        case BYTE:
        case INT:
            inputConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableIntObjectInspector);
            outputOI = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
            break;
        case LONG:
            inputConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableLongObjectInspector);
            outputOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
            break;
        case FLOAT:
        case STRING:
        case DOUBLE:
            inputConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
            outputOI = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
            break;
        case DECIMAL:
            outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(((PrimitiveObjectInspector) arguments[0]).getTypeInfo());
            inputConverter = ObjectInspectorConverters.getConverter(arguments[0], outputOI);
            break;
        default:
            throw new UDFArgumentException("ABS only takes SHORT/BYTE/INT/LONG/DOUBLE/FLOAT/STRING/DECIMAL types, got " + inputType);
    }
    return outputOI;
}
Also used : UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) HiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveDecimalObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)

Example 33 with PrimitiveObjectInspectorFactory.writableIntObjectInspector

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

the class GenericUDFBasePad method checkIntArguments.

private Converter checkIntArguments(ObjectInspector[] arguments, int i) throws UDFArgumentException {
    if (arguments[i].getCategory() != ObjectInspector.Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(i, "Only primitive type arguments are accepted but " + arguments[i].getTypeName() + " is passed.");
    }
    PrimitiveCategory inputType = ((PrimitiveObjectInspector) arguments[i]).getPrimitiveCategory();
    Converter converter;
    switch(inputType) {
        case INT:
        case SHORT:
        case BYTE:
            converter = ObjectInspectorConverters.getConverter((PrimitiveObjectInspector) arguments[i], PrimitiveObjectInspectorFactory.writableIntObjectInspector);
            break;
        default:
            throw new UDFArgumentTypeException(i + 1, udfName + " only takes INT/SHORT/BYTE types as " + (i + 1) + "-ths argument, got " + inputType);
    }
    return converter;
}
Also used : UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException) Converter(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters.Converter) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)

Example 34 with PrimitiveObjectInspectorFactory.writableIntObjectInspector

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

the class GenericUDFIndex method initialize.

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 2) {
        throw new UDFArgumentLengthException("The function INDEX accepts exactly 2 arguments.");
    }
    if (arguments[0] instanceof MapObjectInspector) {
        // index into a map
        mapOI = (MapObjectInspector) arguments[0];
        listOI = null;
    } else if (arguments[0] instanceof ListObjectInspector) {
        // index into a list
        listOI = (ListObjectInspector) arguments[0];
        mapOI = null;
    } else {
        throw new UDFArgumentTypeException(0, "\"" + Category.MAP.toString().toLowerCase() + "\" or \"" + Category.LIST.toString().toLowerCase() + "\" is expected at function INDEX, but \"" + arguments[0].getTypeName() + "\" is found");
    }
    // index has to be a primitive
    if (!(arguments[1] instanceof PrimitiveObjectInspector)) {
        throw new UDFArgumentTypeException(1, "Primitive Type is expected but " + arguments[1].getTypeName() + "\" is found");
    }
    PrimitiveObjectInspector inputOI = (PrimitiveObjectInspector) arguments[1];
    ObjectInspector returnOI;
    ObjectInspector indexOI;
    if (mapOI != null) {
        indexOI = ObjectInspectorConverters.getConvertedOI(inputOI, mapOI.getMapKeyObjectInspector());
        returnOI = mapOI.getMapValueObjectInspector();
    } else {
        indexOI = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
        returnOI = listOI.getListElementObjectInspector();
    }
    converter = ObjectInspectorConverters.getConverter(inputOI, indexOI);
    return returnOI;
}
Also used : ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)

Example 35 with PrimitiveObjectInspectorFactory.writableIntObjectInspector

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

the class GenericUDAFNTile method getEvaluator.

@Override
public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException {
    if (parameters.length != 1) {
        throw new UDFArgumentTypeException(parameters.length - 1, "Exactly one argument is expected.");
    }
    ObjectInspector oi = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(parameters[0]);
    boolean c = ObjectInspectorUtils.compareTypes(oi, PrimitiveObjectInspectorFactory.writableIntObjectInspector);
    if (!c) {
        throw new UDFArgumentTypeException(0, "Number of tiles must be an int expression");
    }
    return new GenericUDAFNTileEvaluator();
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)

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