Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils#compareSupported()

The following examples show how to use org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils#compareSupported() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UDFArrayMax.java    From hive-third-functions with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function array_max(array) takes exactly " + ARG_COUNT + "arguments.");
    }

    // Check if two argument is of category LIST
    if (!arguments[0].getCategory().equals(ObjectInspector.Category.LIST)) {
        throw new UDFArgumentTypeException(0,
                "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" "
                        + "expected at function array_max, but "
                        + "\"" + arguments[0].getTypeName() + "\" "
                        + "is found");
    }

    arrayOI = (ListObjectInspector) arguments[0];
    arrayElementOI = arrayOI.getListElementObjectInspector();

    // Check if the comparison is supported for this type
    if (!ObjectInspectorUtils.compareSupported(arrayElementOI)) {
        throw new UDFArgumentException("The function array_max"
                + " does not support comparison for "
                + "\"" + arrayElementOI.getTypeName() + "\""
                + " types");
    }

    return arrayElementOI;
}
 
Example 2
Source File: UDFArrayMin.java    From hive-third-functions with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function array_min(array) takes exactly " + ARG_COUNT + "arguments.");
    }

    // Check if two argument is of category LIST
    if (!arguments[0].getCategory().equals(ObjectInspector.Category.LIST)) {
        throw new UDFArgumentTypeException(0,
                "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" "
                        + "expected at function array_min, but "
                        + "\"" + arguments[0].getTypeName() + "\" "
                        + "is found");
    }

    arrayOI = (ListObjectInspector) arguments[0];
    arrayElementOI = arrayOI.getListElementObjectInspector();

    // Check if the comparison is supported for this type
    if (!ObjectInspectorUtils.compareSupported(arrayElementOI)) {
        throw new UDFArgumentException("The function array_min"
                + " does not support comparison for "
                + "\"" + arrayElementOI.getTypeName() + "\""
                + " types");
    }

    return arrayElementOI;
}
 
Example 3
Source File: MaxRowUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException {
    ObjectInspector oi =
            TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(parameters[0]);
    if (!ObjectInspectorUtils.compareSupported(oi)) {
        throw new UDFArgumentTypeException(0,
            "Cannot support comparison of map<> type or complex type containing map<>.");
    }
    return new GenericUDAFMaxRowEvaluator();
}
 
Example 4
Source File: MinByUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] argTypes)
        throws SemanticException {
    if (argTypes.length != 2) {
        throw new UDFArgumentLengthException(
            "Exactly two arguments are expected: " + argTypes.length);
    }
    ObjectInspector yOI = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(argTypes[1]);
    if (!ObjectInspectorUtils.compareSupported(yOI)) {
        throw new UDFArgumentTypeException(1,
            "Cannot support comparison of map<> type or complex type containing map<>.");
    }
    return new Evaluator();
}
 
Example 5
Source File: MaxByUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] argTypes)
        throws SemanticException {
    if (argTypes.length != 2) {
        throw new UDFArgumentLengthException(
            "Exactly two arguments are expected: " + argTypes.length);
    }
    ObjectInspector yOI = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(argTypes[1]);
    if (!ObjectInspectorUtils.compareSupported(yOI)) {
        throw new UDFArgumentTypeException(1,
            "Cannot support comparison of map<> type or complex type containing map<>.");
    }
    return new Evaluator();
}
 
Example 6
Source File: ArrayContains.java    From Apache-Hive-Essentials-Second-Edition with MIT License 4 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != ARG_COUNT) {
        throw new UDFArgumentException(
                "The function " + FUNC_NAME + " accepts "
                        + ARG_COUNT + " arguments.");
    }

    // Check if ARRAY_IDX argument is of category LIST
    if (!arguments[ARRAY_IDX].getCategory().equals(Category.LIST)) {
        throw new UDFArgumentTypeException(ARRAY_IDX,
                "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" "
                        + "expected at function ARRAY_CONTAINS, but "
                        + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" "
                        + "is found");
    }

    arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
    arrayElementOI = arrayOI.getListElementObjectInspector();

    valueOI = arguments[VALUE_IDX];

    // Check if list element and value are of same type
    if (!ObjectInspectorUtils.compareTypes(arrayElementOI, valueOI)) {
        throw new UDFArgumentTypeException(VALUE_IDX,
                "\"" + arrayElementOI.getTypeName() + "\""
                        + " expected at function ARRAY_CONTAINS, but "
                        + "\"" + valueOI.getTypeName() + "\""
                        + " is found");
    }

    // Check if the comparison is supported for this type
    if (!ObjectInspectorUtils.compareSupported(valueOI)) {
        throw new UDFArgumentException("The function " + FUNC_NAME
                + " does not support comparison for "
                + "\"" + valueOI.getTypeName() + "\""
                + " types");
    }

    result = new BooleanWritable(false);

    return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
 
Example 7
Source File: UDFArrayContains.java    From hive-third-functions with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function array_contains(array, value) takes exactly " + ARG_COUNT + " arguments.");
    }

    // Check if ARRAY_IDX argument is of category LIST
    if (!arguments[ARRAY_IDX].getCategory().equals(ObjectInspector.Category.LIST)) {
        throw new UDFArgumentTypeException(ARRAY_IDX,
                "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" "
                        + "expected at function array_contains, but "
                        + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" "
                        + "is found");
    }

    arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
    arrayElementOI = arrayOI.getListElementObjectInspector();

    valueOI = arguments[VALUE_IDX];

    // Check if list element and value are of same type
    if (!ObjectInspectorUtils.compareTypes(arrayElementOI, valueOI)) {
        throw new UDFArgumentTypeException(VALUE_IDX,
                "\"" + arrayElementOI.getTypeName() + "\""
                        + " expected at function array_contains, but "
                        + "\"" + valueOI.getTypeName() + "\""
                        + " is found");
    }

    // Check if the comparison is supported for this type
    if (!ObjectInspectorUtils.compareSupported(valueOI)) {
        throw new UDFArgumentException("The function array_contains"
                + " does not support comparison for "
                + "\"" + valueOI.getTypeName() + "\""
                + " types");
    }

    result = new BooleanWritable(false);

    return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
 
Example 8
Source File: UDFArrayValueCount.java    From hive-third-functions with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function array_value_count(array, value) takes exactly " + ARG_COUNT + " arguments.");
    }

    // Check if ARRAY_IDX argument is of category LIST
    if (!arguments[ARRAY_IDX].getCategory().equals(ObjectInspector.Category.LIST)) {
        throw new UDFArgumentTypeException(ARRAY_IDX,
                "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" "
                        + "expected at function array_value_count, but "
                        + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" "
                        + "is found");
    }

    arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
    arrayElementOI = arrayOI.getListElementObjectInspector();

    valueOI = arguments[VALUE_IDX];

    // Check if list element and value are of same type
    if (!ObjectInspectorUtils.compareTypes(arrayElementOI, valueOI)) {
        throw new UDFArgumentTypeException(VALUE_IDX,
                "\"" + arrayElementOI.getTypeName() + "\""
                        + " expected at function array_value_count, but "
                        + "\"" + valueOI.getTypeName() + "\""
                        + " is found");
    }

    // Check if the comparison is supported for this type
    if (!ObjectInspectorUtils.compareSupported(valueOI)) {
        throw new UDFArgumentException("The function array_value_count"
                + " does not support comparison for "
                + "\"" + valueOI.getTypeName() + "\""
                + " types");
    }

    result = new LongWritable(0L);

    return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
}
 
Example 9
Source File: UDFArrayRemove.java    From hive-third-functions with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function array_remove(array, value) takes exactly " + ARG_COUNT + " arguments.");
    }

    // Check if ARRAY_IDX argument is of category LIST
    if (!arguments[ARRAY_IDX].getCategory().equals(ObjectInspector.Category.LIST)) {
        throw new UDFArgumentTypeException(ARRAY_IDX,
                "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" "
                        + "expected at function array_remove, but "
                        + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" "
                        + "is found");
    }

    arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
    arrayElementOI = arrayOI.getListElementObjectInspector();

    valueOI = arguments[VALUE_IDX];

    // Check if list element and value are of same type
    if (!ObjectInspectorUtils.compareTypes(arrayElementOI, valueOI)) {
        throw new UDFArgumentTypeException(VALUE_IDX,
                "\"" + arrayElementOI.getTypeName() + "\""
                        + " expected at function array_remove, but "
                        + "\"" + valueOI.getTypeName() + "\""
                        + " is found");
    }

    // Check if the comparison is supported for this type
    if (!ObjectInspectorUtils.compareSupported(valueOI)) {
        throw new UDFArgumentException("The function array_remove"
                + " does not support comparison for "
                + "\"" + valueOI.getTypeName() + "\""
                + " types");
    }

    return ObjectInspectorFactory.getStandardListObjectInspector(arrayElementOI);
}
 
Example 10
Source File: UDFArrayEquals.java    From hive-third-functions with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function array_equals(array, array) takes exactly " + ARG_COUNT + " arguments.");
    }

    // Check if two argument is of category LIST
    for (int i = 0; i < 2; i++) {
        if (!arguments[i].getCategory().equals(ObjectInspector.Category.LIST)) {
            throw new UDFArgumentTypeException(i,
                    "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" "
                            + "expected at function array_equals, but "
                            + "\"" + arguments[i].getTypeName() + "\" "
                            + "is found");
        }
    }

    leftArrayOI = (ListObjectInspector) arguments[0];
    rightArrayOI = (ListObjectInspector) arguments[1];

    leftArrayElementOI = leftArrayOI.getListElementObjectInspector();
    rightArrayElementOI = rightArrayOI.getListElementObjectInspector();

    // Check if two array are of same type
    if (!ObjectInspectorUtils.compareTypes(leftArrayElementOI, rightArrayElementOI)) {
        throw new UDFArgumentTypeException(1,
                "\"" + leftArrayElementOI.getTypeName() + "\""
                        + " expected at function array_equals, but "
                        + "\"" + rightArrayElementOI.getTypeName() + "\""
                        + " is found");
    }

    // Check if the comparison is supported for this type
    if (!ObjectInspectorUtils.compareSupported(leftArrayElementOI)) {
        throw new UDFArgumentException("The function array_equals"
                + " does not support comparison for "
                + "\"" + leftArrayElementOI.getTypeName() + "\""
                + " types");
    }

    result = new BooleanWritable(false);
    return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
 
Example 11
Source File: UDFArrayPosition.java    From hive-third-functions with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function array_position(array, value) takes exactly " + ARG_COUNT + " arguments.");
    }

    // Check if ARRAY_IDX argument is of category LIST
    if (!arguments[ARRAY_IDX].getCategory().equals(ObjectInspector.Category.LIST)) {
        throw new UDFArgumentTypeException(ARRAY_IDX,
                "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" "
                        + "expected at function array_position, but "
                        + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" "
                        + "is found");
    }

    arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
    arrayElementOI = arrayOI.getListElementObjectInspector();

    valueOI = arguments[VALUE_IDX];

    // Check if list element and value are of same type
    if (!ObjectInspectorUtils.compareTypes(arrayElementOI, valueOI)) {
        throw new UDFArgumentTypeException(VALUE_IDX,
                "\"" + arrayElementOI.getTypeName() + "\""
                        + " expected at function array_position, but "
                        + "\"" + valueOI.getTypeName() + "\""
                        + " is found");
    }

    // Check if the comparison is supported for this type
    if (!ObjectInspectorUtils.compareSupported(valueOI)) {
        throw new UDFArgumentException("The function array_position"
                + " does not support comparison for "
                + "\"" + valueOI.getTypeName() + "\""
                + " types");
    }

    result = new LongWritable(0L);

    return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
}
 
Example 12
Source File: UDFMapEquals.java    From hive-third-functions with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function map_equals(map, map) takes exactly " + ARG_COUNT + " arguments.");
    }

    // Check if two argument is of category LIST
    for (int i = 0; i < 2; i++) {
        if (!arguments[i].getCategory().equals(ObjectInspector.Category.MAP)) {
            throw new UDFArgumentTypeException(i,
                    "\"" + serdeConstants.MAP_TYPE_NAME + "\" "
                            + "expected at function map_equals, but "
                            + "\"" + arguments[i].getTypeName() + "\" "
                            + "is found");
        }
    }

    leftMapOI = (MapObjectInspector) arguments[0];
    rightMapOI = (MapObjectInspector) arguments[1];

    ObjectInspector leftMapKeyOI = leftMapOI.getMapKeyObjectInspector();
    ObjectInspector leftMapValueOI = leftMapOI.getMapValueObjectInspector();
    ObjectInspector rightMapKeyOI = rightMapOI.getMapKeyObjectInspector();
    ObjectInspector rightMapValueOI = rightMapOI.getMapValueObjectInspector();

    // Check if two map are of same key and value type
    if (!ObjectInspectorUtils.compareTypes(leftMapKeyOI, rightMapKeyOI)) {
        throw new UDFArgumentTypeException(1,
                "\"" + leftMapKeyOI.getTypeName() + "\""
                        + " expected at function map_equals key, but "
                        + "\"" + rightMapKeyOI.getTypeName() + "\""
                        + " is found");
    }

    if (!ObjectInspectorUtils.compareTypes(leftMapValueOI, rightMapValueOI)) {
        throw new UDFArgumentTypeException(1,
                "\"" + leftMapValueOI.getTypeName() + "\""
                        + " expected at function map_equals value, but "
                        + "\"" + rightMapValueOI.getTypeName() + "\""
                        + " is found");
    }

    // Check if the comparison is supported for this type
    if (!ObjectInspectorUtils.compareSupported(leftMapValueOI)) {
        throw new UDFArgumentException("The function map_equals"
                + " does not support comparison for "
                + "\"" + leftMapValueOI.getTypeName() + "\""
                + " types");
    }

    result = new BooleanWritable(false);
    return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
 
Example 13
Source File: MinByUDAF.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectInspector init(Mode mode, ObjectInspector[] argOIs) throws HiveException {
    super.init(mode, argOIs);

    // initialize input
    if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) {// from original data
        this.xInputOI = argOIs[0];
        this.yInputOI = argOIs[1];
        if (!ObjectInspectorUtils.compareSupported(yInputOI)) {
            throw new UDFArgumentTypeException(1,
                "Cannot support comparison of map<> type or complex type containing map<>.");
        }
    } else {// from partial aggregation
        this.partialInputOI = (StructObjectInspector) argOIs[0];
        this.xField = partialInputOI.getStructFieldRef("x");
        this.xInputOI = xField.getFieldObjectInspector();
        this.yField = partialInputOI.getStructFieldRef("y");
        this.yInputOI = yField.getFieldObjectInspector();
    }
    this.xOutputOI = ObjectInspectorUtils.getStandardObjectInspector(xInputOI,
        ObjectInspectorCopyOption.JAVA);
    this.yOutputOI = ObjectInspectorUtils.getStandardObjectInspector(yInputOI,
        ObjectInspectorCopyOption.JAVA);

    // initialize output
    final ObjectInspector outputOI;
    if (mode == Mode.PARTIAL1 || mode == Mode.PARTIAL2) {// terminatePartial
        List<String> fieldNames = new ArrayList<>(2);
        List<ObjectInspector> fieldOIs = new ArrayList<>(2);
        fieldNames.add("x");
        fieldOIs.add(xOutputOI);
        fieldNames.add("y");
        fieldOIs.add(yOutputOI);
        return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames,
            fieldOIs);
    } else {// terminate
        // Copy to Java object because that saves object creation time.
        outputOI = ObjectInspectorUtils.getStandardObjectInspector(xInputOI,
            ObjectInspectorCopyOption.JAVA);
    }
    return outputOI;
}
 
Example 14
Source File: MaxByUDAF.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectInspector init(Mode mode, ObjectInspector[] argOIs) throws HiveException {
    super.init(mode, argOIs);

    // initialize input
    if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) {// from original data
        this.xInputOI = argOIs[0];
        this.yInputOI = argOIs[1];
        if (!ObjectInspectorUtils.compareSupported(yInputOI)) {
            throw new UDFArgumentTypeException(1,
                "Cannot support comparison of map<> type or complex type containing map<>.");
        }
    } else {// from partial aggregation
        this.partialInputOI = (StructObjectInspector) argOIs[0];
        this.xField = partialInputOI.getStructFieldRef("x");
        this.xInputOI = xField.getFieldObjectInspector();
        this.yField = partialInputOI.getStructFieldRef("y");
        this.yInputOI = yField.getFieldObjectInspector();
    }
    this.xOutputOI = ObjectInspectorUtils.getStandardObjectInspector(xInputOI,
        ObjectInspectorCopyOption.JAVA);
    this.yOutputOI = ObjectInspectorUtils.getStandardObjectInspector(yInputOI,
        ObjectInspectorCopyOption.JAVA);

    // initialize output
    final ObjectInspector outputOI;
    if (mode == Mode.PARTIAL1 || mode == Mode.PARTIAL2) {// terminatePartial
        List<String> fieldNames = new ArrayList<>(2);
        List<ObjectInspector> fieldOIs = new ArrayList<>(2);
        fieldNames.add("x");
        fieldOIs.add(xOutputOI);
        fieldNames.add("y");
        fieldOIs.add(yOutputOI);
        return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames,
            fieldOIs);
    } else {// terminate
        // Copy to Java object because that saves object creation time.
        outputOI = ObjectInspectorUtils.getStandardObjectInspector(xInputOI,
            ObjectInspectorCopyOption.JAVA);
    }
    return outputOI;
}