Java Code Examples for org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo#getParameters()

The following examples show how to use org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo#getParameters() . 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: UDAFToOrderedList.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(GenericUDAFParameterInfo info)
        throws SemanticException {
    @SuppressWarnings("deprecation")
    TypeInfo[] typeInfo = info.getParameters();
    ObjectInspector[] argOIs = info.getParameterObjectInspectors();
    if ((typeInfo.length == 1)
            || (typeInfo.length == 2 && HiveUtils.isConstString(argOIs[1]))) {
        // sort values by value itself w/o key
        if (typeInfo[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
            throw new UDFArgumentTypeException(0,
                "Only primitive type arguments are accepted for value but "
                        + typeInfo[0].getTypeName() + " was passed as the first parameter.");
        }
    } else if ((typeInfo.length == 2)
            || (typeInfo.length == 3 && HiveUtils.isConstString(argOIs[2]))) {
        // sort values by key
        if (typeInfo[1].getCategory() != ObjectInspector.Category.PRIMITIVE) {
            throw new UDFArgumentTypeException(1,
                "Only primitive type arguments are accepted for key but "
                        + typeInfo[1].getTypeName() + " was passed as the second parameter.");
        }
    } else {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "Number of arguments must be in [1, 3] including constant string for options: "
                    + typeInfo.length);
    }
    return new UDAFToOrderedListEvaluator();
}
 
Example 2
Source File: Merge.java    From hive-funnel-udf with Apache License 2.0 5 votes vote down vote up
@Override
public MergeEvaluator getEvaluator(GenericUDAFParameterInfo info) throws SemanticException {
    // Get the parameters
    TypeInfo [] parameters = info.getParameters();

    // Check number of arguments
    if (parameters.length != 1) {
        throw new UDFArgumentLengthException("Please specify the funnel column.");
    }

    // Check if the parameter is not a list
    if (parameters[0].getCategory() != ObjectInspector.Category.LIST) {
        throw new UDFArgumentTypeException(0, "Only list type arguments are accepted but " + parameters[0].getTypeName() + " was passed as the first parameter.");
    }

    // Check that the list is an array of primitives
    if (((ListTypeInfo) parameters[0]).getListElementTypeInfo().getCategory() != ObjectInspector.Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "A long array argument should be passed, but " + parameters[0].getTypeName() + " was passed instead.");
    }

    // Check that the list is of type long
    // May want to add support for int/double/float later
    switch (((PrimitiveTypeInfo) ((ListTypeInfo) parameters[0]).getListElementTypeInfo()).getPrimitiveCategory()) {
        case LONG:
            break;
        default:
            throw new UDFArgumentTypeException(0, "A long array argument should be passed, but " + parameters[0].getTypeName() + " was passed instead.");
    }

    return new MergeEvaluator();
}
 
Example 3
Source File: Funnel.java    From hive-funnel-udf with Apache License 2.0 5 votes vote down vote up
@Override
public FunnelEvaluator getEvaluator(GenericUDAFParameterInfo info) throws SemanticException {
    // Get the parameters
    TypeInfo [] parameters = info.getParameters();

    // Check number of arguments
    if (parameters.length < 3) {
        throw new UDFArgumentLengthException("Please specify the action column, the timestamp column, and at least one funnel.");
    }

    // Check the action_column type and enforce that all funnel steps are the same type
    if (parameters[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but " + parameters[0].getTypeName() + " was passed.");
    }
    PrimitiveCategory actionColumnCategory = ((PrimitiveTypeInfo) parameters[0]).getPrimitiveCategory();

    // Check the timestamp_column type
    if (parameters[1].getCategory() != ObjectInspector.Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(1, "Only primitive type arguments are accepted but " + parameters[0].getTypeName() + " was passed.");
    }

    // Check that all funnel steps are the same type as the action_column
    for (int i = 2; i < parameters.length; i++) {
        switch (parameters[i].getCategory()) {
            case LIST:
                // Check that the list is of primitives of the same type as the action column
                TypeInfo typeInfo = ((ListTypeInfo) parameters[i]).getListElementTypeInfo();
                if (typeInfo.getCategory() != ObjectInspector.Category.PRIMITIVE || ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory() != actionColumnCategory) {
                    throw new UDFArgumentTypeException(i, "Funnel list parameter " + Integer.toString(i) + " of type " + parameters[i].getTypeName() + " does not match expected type " + parameters[0].getTypeName() + ".");
                }
                break;
            default:
                throw new UDFArgumentTypeException(i, "Funnel list parameter " + Integer.toString(i) + " of type " + parameters[i].getTypeName() + " should be a list.");
        }
    }

    return new FunnelEvaluator();
}
 
Example 4
Source File: UDAFToOrderedMap.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(GenericUDAFParameterInfo info)
        throws SemanticException {
    @SuppressWarnings("deprecation")
    final TypeInfo[] typeInfo = info.getParameters();
    if (typeInfo.length != 2 && typeInfo.length != 3) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "Expecting two or three arguments: " + typeInfo.length);
    }
    if (typeInfo[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0,
            "Only primitive type arguments are accepted for the key but "
                    + typeInfo[0].getTypeName() + " was passed as parameter 1.");
    }

    boolean reverseOrder = false;
    int size = 0;
    if (typeInfo.length == 3) {
        ObjectInspector[] argOIs = info.getParameterObjectInspectors();
        ObjectInspector argOI2 = argOIs[2];
        if (HiveUtils.isConstBoolean(argOI2)) {
            reverseOrder = HiveUtils.getConstBoolean(argOI2);
        } else if (HiveUtils.isConstInteger(argOI2)) {
            size = HiveUtils.getConstInt(argOI2);
            if (size == 0) {
                throw new UDFArgumentException("Map size must be non-zero value: " + size);
            }
            reverseOrder = (size > 0); // positive size => top-k
        } else {
            throw new UDFArgumentTypeException(2,
                "The third argument must be boolean or int type: " + typeInfo[2].getTypeName());
        }
    }

    if (reverseOrder) { // descending
        if (size == 0) {
            return new ReverseOrderedMapEvaluator();
        } else {
            return new TopKOrderedMapEvaluator();
        }
    } else { // ascending
        if (size == 0) {
            return new NaturalOrderedMapEvaluator();
        } else {
            return new TailKOrderedMapEvaluator();
        }
    }
}