org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException Java Examples

The following examples show how to use org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException. 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: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asLongCompatibleOI(@Nonnull final ObjectInspector argOI)
        throws UDFArgumentTypeException {
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but "
                + argOI.getTypeName() + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case LONG:
        case INT:
        case SHORT:
        case BYTE:
        case BOOLEAN:
        case FLOAT:
        case DOUBLE:
        case DECIMAL:
        case STRING:
        case TIMESTAMP:
            break;
        default:
            throw new UDFArgumentTypeException(0,
                "Unexpected type '" + argOI.getTypeName() + "' is passed.");
    }
    return oi;
}
 
Example #2
Source File: MergeAggregateBuffer.java    From hive-funnel-udf with Apache License 2.0 6 votes vote down vote up
/**
 * Add a funnel to the aggregate.
 *
 * @param funnel Funnel in the form of a list of longs.
 */
public void addFunnel(List<Long> funnel) throws HiveException {
    // If empty, just copy elements
    if (elements.isEmpty()) {
        elements.addAll(funnel);
    } else {
        // If the sizes don't match, throw an exception
        if (elements.size() != funnel.size()) {
            throw new UDFArgumentTypeException(0, "Funnels must be of the same size to merge!");
        }
        // Not empty, merge with existing list
        for (int i = 0; i < funnel.size(); i++) {
            elements.set(i, (funnel.get(i) + elements.get(i)));
        }
    }
}
 
Example #3
Source File: StrContainsUDF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 2 && argOIs.length != 3) {
        throw new UDFArgumentLengthException("str_contains expects two or three arguments");
    }

    this.queryOI = HiveUtils.asStringOI(argOIs, 0);
    if (!HiveUtils.isStringListOI(argOIs[1])) {
        throw new UDFArgumentTypeException(1,
            "Expected array<string> for the second argument but got "
                    + argOIs[1].getTypeName());
    }
    this.searchTermsOI = HiveUtils.asListOI(argOIs, 1);

    if (argOIs.length == 3) {
        this.orQueryOI = HiveUtils.asBooleanOI(argOIs, 2);
    }

    return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector;
}
 
Example #4
Source File: TransposeAndDotUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(GenericUDAFParameterInfo info)
        throws SemanticException {
    ObjectInspector[] OIs = info.getParameterObjectInspectors();

    if (OIs.length != 2) {
        throw new UDFArgumentLengthException("Specify two arguments.");
    }

    if (!HiveUtils.isNumberListOI(OIs[0])) {
        throw new UDFArgumentTypeException(0,
            "Only array<number> type argument is acceptable but " + OIs[0].getTypeName()
                    + " was passed as `matrix0_row`");
    }

    if (!HiveUtils.isNumberListOI(OIs[1])) {
        throw new UDFArgumentTypeException(1,
            "Only array<number> type argument is acceptable but " + OIs[1].getTypeName()
                    + " was passed as `matrix1_row`");
    }

    return new TransposeAndDotUDAFEvaluator();
}
 
Example #5
Source File: UDFStringSplitToMultimap.java    From hive-third-functions with Apache License 2.0 6 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 split_to_multimap(string, string, string) takes exactly " + ARG_COUNT + " arguments.");
    }

    // Check if two argument is of string
    for (int i = 0; i < 3; i++) {
        if (!ObjectInspectorUtils.compareTypes(PrimitiveObjectInspectorFactory.javaStringObjectInspector, arguments[i])) {
            throw new UDFArgumentTypeException(i,
                    "\"" + PrimitiveObjectInspectorFactory.javaStringObjectInspector.getTypeName() + "\" "
                            + "expected at function split_to_multimap, but "
                            + "\"" + arguments[i].getTypeName() + "\" "
                            + "is found");
        }
    }

    ObjectInspector mapKeyOI = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    ObjectInspector mapValueOI = ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector);

    return ObjectInspectorFactory.getStandardMapObjectInspector(mapKeyOI, mapValueOI);
}
 
Example #6
Source File: Conversion.java    From hive-funnel-udf with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 1) {
        throw new UDFArgumentLengthException("The operator 'conversion' accepts 1 argument.");
    }

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

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

    // Get the list object inspector
    listInputObjectInspector = (ListObjectInspector) arguments[0];

    // This UDF will return a list of doubles
    return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaDoubleObjectInspector);
}
 
Example #7
Source File: SignalNoiseRatioUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(GenericUDAFParameterInfo info)
        throws SemanticException {
    final ObjectInspector[] OIs = info.getParameterObjectInspectors();

    if (OIs.length != 2) {
        throw new UDFArgumentLengthException("Specify two arguments: " + OIs.length);
    }
    if (!HiveUtils.isNumberListOI(OIs[0])) {
        throw new UDFArgumentTypeException(0,
            "Only array<number> type argument is acceptable but " + OIs[0].getTypeName()
                    + " was passed as `features`");
    }
    if (!HiveUtils.isListOI(OIs[1]) || !HiveUtils.isIntegerOI(
        ((ListObjectInspector) OIs[1]).getListElementObjectInspector())) {
        throw new UDFArgumentTypeException(1, "Only array<int> type argument is acceptable but "
                + OIs[1].getTypeName() + " was passed as `labels`");
    }

    return new SignalNoiseRatioUDAFEvaluator();
}
 
Example #8
Source File: Fallout.java    From hive-funnel-udf with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 1) {
        throw new UDFArgumentLengthException("The operator 'fallout' accepts 1 argument.");
    }

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

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

    // Get the list object inspector
    listInputObjectInspector = (ListObjectInspector) arguments[0];

    // This UDF will return a list of doubles
    return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaDoubleObjectInspector);
}
 
Example #9
Source File: FMPredictGenericUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public Evaluator getEvaluator(TypeInfo[] typeInfo) throws SemanticException {
    if (typeInfo.length != 3) {
        throw new UDFArgumentLengthException(
            "Expected argument length is 3 but given argument length was " + typeInfo.length);
    }
    if (!HiveUtils.isNumberTypeInfo(typeInfo[0])) {
        throw new UDFArgumentTypeException(0,
            "Number type is expected for the first argument Wj: " + typeInfo[0].getTypeName());
    }
    if (typeInfo[1].getCategory() != Category.LIST) {
        throw new UDFArgumentTypeException(1,
            "List type is expected for the second argument Vjf: " + typeInfo[1].getTypeName());
    }
    ListTypeInfo typeInfo1 = (ListTypeInfo) typeInfo[1];
    if (!HiveUtils.isNumberTypeInfo(typeInfo1.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(1,
            "Number type is expected for the element type of list Vjf: "
                    + typeInfo1.getTypeName());
    }
    if (!HiveUtils.isNumberTypeInfo(typeInfo[2])) {
        throw new UDFArgumentTypeException(2,
            "Number type is expected for the third argument Xj: " + typeInfo[2].getTypeName());
    }
    return new Evaluator();
}
 
Example #10
Source File: MulticlassOnlineClassifierUDTF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public StructObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length < 2) {
        throw new UDFArgumentException(getClass().getSimpleName()
                + " takes 2 arguments: List<Int|BigInt|Text> features, {Int|BitInt|Text} label [, constant text options]");
    }
    PrimitiveObjectInspector featureInputOI = processFeaturesOI(argOIs[0]);
    this.labelInputOI = HiveUtils.asPrimitiveObjectInspector(argOIs[1]);
    String labelTypeName = labelInputOI.getTypeName();
    if (!STRING_TYPE_NAME.equals(labelTypeName) && !INT_TYPE_NAME.equals(labelTypeName)
            && !BIGINT_TYPE_NAME.equals(labelTypeName)) {
        throw new UDFArgumentTypeException(0,
            "label must be a type [Int|BigInt|Text]: " + labelTypeName);
    }

    processOptions(argOIs);

    this.label2model = new HashMap<Object, PredictionModel>(64);
    this.count = 0;

    return getReturnOI(labelInputOI, getFeatureOutputOI(featureInputOI));
}
 
Example #11
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asNumberOI(@Nonnull final ObjectInspector argOI)
        throws UDFArgumentTypeException {
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but "
                + argOI.getTypeName() + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
        case FLOAT:
        case DOUBLE:
        case DECIMAL:
            break;
        default:
            throw new UDFArgumentTypeException(0,
                "Only numeric argument is accepted but " + argOI.getTypeName() + " is passed.");
    }
    return oi;
}
 
Example #12
Source File: AUCUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo)
        throws SemanticException {
    if (typeInfo.length != 2 && typeInfo.length != 3) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "_FUNC_ takes two or three arguments");
    }

    if (HiveUtils.isNumberTypeInfo(typeInfo[0]) && HiveUtils.isIntegerTypeInfo(typeInfo[1])) {
        return new ClassificationEvaluator();
    } else {
        ListTypeInfo arg1type = HiveUtils.asListTypeInfo(typeInfo[0]);
        if (!HiveUtils.isPrimitiveTypeInfo(arg1type.getListElementTypeInfo())) {
            throw new UDFArgumentTypeException(0,
                "The first argument `array rankItems` is invalid form: " + typeInfo[0]);
        }

        ListTypeInfo arg2type = HiveUtils.asListTypeInfo(typeInfo[1]);
        if (!HiveUtils.isPrimitiveTypeInfo(arg2type.getListElementTypeInfo())) {
            throw new UDFArgumentTypeException(1,
                "The second argument `array correctItems` is invalid form: " + typeInfo[1]);
        }

        return new RankingEvaluator();
    }
}
 
Example #13
Source File: MAPUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo)
        throws SemanticException {
    if (typeInfo.length != 2 && typeInfo.length != 3) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "_FUNC_ takes two or three arguments");
    }

    ListTypeInfo arg1type = HiveUtils.asListTypeInfo(typeInfo[0]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg1type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(0,
            "The first argument `array rankItems` is invalid form: " + typeInfo[0]);
    }
    ListTypeInfo arg2type = HiveUtils.asListTypeInfo(typeInfo[1]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg2type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(1,
            "The second argument `array correctItems` is invalid form: " + typeInfo[1]);
    }

    return new Evaluator();
}
 
Example #14
Source File: UDAFCollectAction.java    From 163-bigdate-note with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException {
        //判断参数个数
        if (parameters.length != 2) {
            throw new UDFArgumentTypeException(parameters.length - 1, "Two argument is excepted.");
        }

        ObjectInspector oi = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(parameters[0]);
//        ObjectInspector oi1 = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(parameters[1]);
        if (oi.getCategory() != ObjectInspector.Category.PRIMITIVE) {
            throw new UDFArgumentTypeException(0, "Argument must be PRIMITIVE, but"
                + oi.getCategory().name()
                + " was passed.");
        }

//        PrimitiveObjectInspector inputOI = (PrimitiveObjectInspector) oi;
//        if (inputOI.getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING) {
//            throw new UDFArgumentTypeException(0, "Argument must be String, but"
//                    + inputOI.getPrimitiveCategory().name()
//                    + " was passed.");
//        }

        return new AllActionsOfThisPeople30MinBefore();
    }
 
Example #15
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asIntegerOI(@Nonnull final ObjectInspector argOI)
        throws UDFArgumentTypeException {
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but "
                + argOI.getTypeName() + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case INT:
        case SHORT:
        case LONG:
        case BYTE:
            break;
        default:
            throw new UDFArgumentTypeException(0,
                "Unexpected type '" + argOI.getTypeName() + "' is passed.");
    }
    return oi;
}
 
Example #16
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asIntCompatibleOI(@Nonnull final ObjectInspector argOI)
        throws UDFArgumentTypeException {
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but "
                + argOI.getTypeName() + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case INT:
        case SHORT:
        case LONG:
        case FLOAT:
        case DOUBLE:
        case DECIMAL:
        case BOOLEAN:
        case BYTE:
        case STRING:
            break;
        default:
            throw new UDFArgumentTypeException(0,
                "Unexpected type '" + argOI.getTypeName() + "' is passed.");
    }
    return oi;
}
 
Example #17
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asIntegerOI(@Nonnull final ObjectInspector[] argOIs,
        final int argIndex) throws UDFArgumentException {
    final ObjectInspector argOI = getObjectInspector(argOIs, argIndex);
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(argIndex,
            "Only primitive type arguments are accepted but " + argOI.getTypeName()
                    + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case INT:
        case SHORT:
        case LONG:
        case BYTE:
            break;
        default:
            throw new UDFArgumentTypeException(argIndex,
                "Unexpected type '" + argOI.getTypeName() + "' is passed.");
    }
    return oi;
}
 
Example #18
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asDoubleCompatibleOI(
        @Nonnull final ObjectInspector argOI) throws UDFArgumentTypeException {
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but "
                + argOI.getTypeName() + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
        case FLOAT:
        case DOUBLE:
        case DECIMAL:
        case STRING:
        case TIMESTAMP:
            break;
        default:
            throw new UDFArgumentTypeException(0,
                "Only numeric or string type arguments are accepted but " + argOI.getTypeName()
                        + " is passed.");
    }
    return oi;
}
 
Example #19
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asFloatingPointOI(@Nonnull final ObjectInspector argOI)
        throws UDFArgumentTypeException {
    if (argOI.getCategory() != Category.PRIMITIVE) {
        throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted but "
                + argOI.getTypeName() + " is passed.");
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case FLOAT:
        case DOUBLE:
        case DECIMAL:
            break;
        default:
            throw new UDFArgumentTypeException(0, "Only floating point number is accepted but "
                    + argOI.getTypeName() + " is passed.");
    }
    return oi;
}
 
Example #20
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PrimitiveObjectInspector asNumberOI(@Nonnull final ObjectInspector[] argOIs,
        final int argIndex) throws UDFArgumentException {
    final PrimitiveObjectInspector oi = asPrimitiveObjectInspector(argOIs, argIndex);
    switch (oi.getPrimitiveCategory()) {
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
        case FLOAT:
        case DOUBLE:
        case DECIMAL:
            break;
        default:
            throw new UDFArgumentTypeException(argIndex,
                "Only numeric argument is accepted but " + oi.getTypeName() + " is passed.");
    }
    return oi;
}
 
Example #21
Source File: NDCGUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo)
        throws SemanticException {
    if (typeInfo.length != 2 && typeInfo.length != 3) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "_FUNC_ takes two or three arguments");
    }

    ListTypeInfo arg1type = HiveUtils.asListTypeInfo(typeInfo[0]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg1type.getListElementTypeInfo())
            && !HiveUtils.isStructTypeInfo(arg1type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(0,
            "The first argument `array rankItems` is invalid form: " + typeInfo[0]);
    }
    ListTypeInfo arg2type = HiveUtils.asListTypeInfo(typeInfo[1]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg2type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(1,
            "The second argument `array correctItems` is invalid form: " + typeInfo[1]);
    }

    return new Evaluator();
}
 
Example #22
Source File: RecallUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo)
        throws SemanticException {
    if (typeInfo.length != 2 && typeInfo.length != 3) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "_FUNC_ takes two or three arguments");
    }

    ListTypeInfo arg1type = HiveUtils.asListTypeInfo(typeInfo[0]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg1type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(0,
            "The first argument `array rankItems` is invalid form: " + typeInfo[0]);
    }
    ListTypeInfo arg2type = HiveUtils.asListTypeInfo(typeInfo[1]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg2type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(1,
            "The second argument `array correctItems` is invalid form: " + typeInfo[1]);
    }

    return new Evaluator();
}
 
Example #23
Source File: PrecisionUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] typeInfo)
        throws SemanticException {
    if (typeInfo.length != 2 && typeInfo.length != 3) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "_FUNC_ takes two or three arguments");
    }

    ListTypeInfo arg1type = HiveUtils.asListTypeInfo(typeInfo[0]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg1type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(0,
            "The first argument `array rankItems` is invalid form: " + typeInfo[0]);
    }
    ListTypeInfo arg2type = HiveUtils.asListTypeInfo(typeInfo[1]);
    if (!HiveUtils.isPrimitiveTypeInfo(arg2type.getListElementTypeInfo())) {
        throw new UDFArgumentTypeException(1,
            "The second argument `array correctItems` is invalid form: " + typeInfo[1]);
    }

    return new Evaluator();
}
 
Example #24
Source File: VectorDotUDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
Dot2DVectors(@Nonnull ListObjectInspector xListOI, @Nonnull ListObjectInspector yListOI)
        throws UDFArgumentTypeException {
    this.xListOI = xListOI;
    this.yListOI = yListOI;
    this.xElemOI = HiveUtils.asNumberOI(xListOI.getListElementObjectInspector());
    this.yElemOI = HiveUtils.asNumberOI(yListOI.getListElementObjectInspector());
}
 
Example #25
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 #26
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 #27
Source File: MapGetUDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 2) {
        throw new UDFArgumentLengthException("map_get accepts exactly 2 arguments.");
    }

    if (arguments[0] instanceof MapObjectInspector) {
        this.mapOI = (MapObjectInspector) arguments[0];
    } else {
        throw new UDFArgumentTypeException(0,
            "\"map\" is expected for the first argument, 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 indexOI =
            ObjectInspectorConverters.getConvertedOI(inputOI, mapOI.getMapKeyObjectInspector());
    this.converter = ObjectInspectorConverters.getConverter(inputOI, indexOI);

    return mapOI.getMapValueObjectInspector();
}
 
Example #28
Source File: FunnelTest.java    From hive-funnel-udf with Apache License 2.0 5 votes vote down vote up
@Test(expected = UDFArgumentTypeException.class)
public void testComplexParamPosition4() throws HiveException {
    Funnel udaf = new Funnel();
    ObjectInspector[] inputObjectInspectorList = new ObjectInspector[]{
        PrimitiveObjectInspectorFactory.javaStringObjectInspector,
        PrimitiveObjectInspectorFactory.javaStringObjectInspector,
        PrimitiveObjectInspectorFactory.javaStringObjectInspector,
        ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaLongObjectInspector)
    };

    GenericUDAFParameterInfo paramInfo = new SimpleGenericUDAFParameterInfo(inputObjectInspectorList, false, false);
    GenericUDAFEvaluator udafEvaluator = udaf.getEvaluator(paramInfo);
}
 
Example #29
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 #30
Source File: UDAFToMap.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public GenericUDAFEvaluator getEvaluator(TypeInfo[] typeInfo) throws SemanticException {
    if (typeInfo.length != 2) {
        throw new UDFArgumentTypeException(typeInfo.length - 1,
            "Expecting exactly two 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.");
    }

    return new UDAFToMapEvaluator();
}