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

The following examples show how to use org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException. These examples are extracted from open source projects. 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
@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 2
Source Project: hive-funnel-udf   Source File: MergeAggregateBuffer.java    License: 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
@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 4
Source Project: hive-funnel-udf   Source File: Conversion.java    License: 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 5
Source Project: hive-funnel-udf   Source File: Fallout.java    License: 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 6
Source Project: incubator-hivemall   Source File: FMPredictGenericUDAF.java    License: 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 7
Source Project: incubator-hivemall   Source File: AUCUDAF.java    License: 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 8
Source Project: incubator-hivemall   Source File: PrecisionUDAF.java    License: 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 9
Source Project: incubator-hivemall   Source File: MAPUDAF.java    License: 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 10
Source Project: incubator-hivemall   Source File: RecallUDAF.java    License: 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 11
Source Project: incubator-hivemall   Source File: NDCGUDAF.java    License: 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 12
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: 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 13
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: 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 14
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: 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 15
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: 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 16
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: 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 17
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: 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 18
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: 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 19
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: 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 20
@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 21
Source Project: incubator-hivemall   Source File: SignalNoiseRatioUDAF.java    License: 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 22
Source Project: incubator-hivemall   Source File: StrContainsUDF.java    License: 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 23
Source Project: incubator-hivemall   Source File: TransposeAndDotUDAF.java    License: 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 24
Source Project: hive-third-functions   Source File: UDFArrayJoin.java    License: 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 > MAX_ARG_COUNT || arguments.length < MIN_ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function array_join(array, delimiter) or array_join(array, delimiter, null_replacement) takes exactly "
                        + MIN_ARG_COUNT + " or " + MAX_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_join, but "
                        + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" "
                        + "is found");
    }

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

    delimiterOI = arguments[DELIMITER_IDX];
    delimiterConvert = ObjectInspectorConverters.getConverter(delimiterOI, PrimitiveObjectInspectorFactory.writableStringObjectInspector);
    if (arguments.length == MAX_ARG_COUNT) {
        nullReplaceOI = arguments[NULL_REPLACE_IDX];
        nullReplaceConvert = ObjectInspectorConverters.getConverter(nullReplaceOI, PrimitiveObjectInspectorFactory.writableStringObjectInspector);
    }

    result = new Text();

    return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
 
Example 25
Source Project: hive-funnel-udf   Source File: ConversionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = UDFArgumentTypeException.class)
public void testBadInputType() throws HiveException {
    Conversion udf = new Conversion();

    ObjectInspector[] inputOiList = new ObjectInspector[]{
        PrimitiveObjectInspectorFactory.javaLongObjectInspector
    };

    udf.initialize(inputOiList);
}
 
Example 26
Source Project: hive-funnel-udf   Source File: MergeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = UDFArgumentTypeException.class)
public void testArrayOfNonPrimitives() throws HiveException {
    Merge udaf = new Merge();
    ObjectInspector[] inputObjectInspectorList = new ObjectInspector[]{
            ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaLongObjectInspector))
    };

    GenericUDAFParameterInfo paramInfo = new SimpleGenericUDAFParameterInfo(inputObjectInspectorList, false, false);
    GenericUDAFEvaluator udafEvaluator = udaf.getEvaluator(paramInfo);
}
 
Example 27
Source Project: hive-third-functions   Source File: UDFArrayShuffle.java    License: 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_shuffle(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_shuffle, 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_shuffle"
                + " does not support comparison for "
                + "\"" + arrayElementOI.getTypeName() + "\""
                + " types");
    }

    converter = ObjectInspectorConverters.getConverter(arrayElementOI, arrayElementOI);

    return ObjectInspectorFactory.getStandardListObjectInspector(arrayElementOI);
}
 
Example 28
Source Project: hive-third-functions   Source File: UDFArrayMax.java    License: 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 29
Source Project: hive-third-functions   Source File: UDFArrayMin.java    License: 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 30
Source Project: hive-third-functions   Source File: UDFArraySlice.java    License: 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_slice(array, start, length) 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_slice, but "
                        + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" "
                        + "is found");
    }

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

    ObjectInspector expectOI = PrimitiveObjectInspectorFactory.writableIntObjectInspector;

    // Check if value and expect are of same type
    for (int i = 1; i < 3; i++) {
        if (!ObjectInspectorUtils.compareTypes(expectOI, arguments[i])) {
            throw new UDFArgumentTypeException(i,
                    "\"" + expectOI.getTypeName() + "\""
                            + " expected at function array_slice, but "
                            + "\"" + arguments[i].getTypeName() + "\""
                            + " is found");
        }
    }

    return ObjectInspectorFactory.getStandardListObjectInspector(arrayElementOI);
}