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

The following examples show how to use org.apache.hadoop.hive.ql.exec.UDFArgumentException. 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 Project: flink   Author: flink-tpc-ds   File: HiveGenericUDF.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public DataType getHiveResultType(Object[] constantArguments, DataType[] argTypes) {
	LOG.info("Getting result type of HiveGenericUDF from {}", hiveFunctionWrapper.getClassName());

	try {
		ObjectInspector[] argumentInspectors = HiveInspectors.toInspectors(constantArguments, argTypes);

		ObjectInspector resultObjectInspector =
			hiveFunctionWrapper.createFunction().initializeAndFoldConstants(argumentInspectors);

		return HiveTypeUtil.toFlinkType(
			TypeInfoUtils.getTypeInfoFromObjectInspector(resultObjectInspector));
	} catch (UDFArgumentException e) {
		throw new FlinkHiveUDFException(e);
	}
}
 
Example #2
Source Project: incubator-hivemall   Author: apache   File: FMPredictGenericUDAF.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void iterate(@SuppressWarnings("deprecation") AggregationBuffer agg,
        Object[] parameters) throws HiveException {
    if (parameters[0] == null) {
        return;
    }
    FMPredictAggregationBuffer buf = (FMPredictAggregationBuffer) agg;

    double w = PrimitiveObjectInspectorUtils.getDouble(parameters[0], wOI);
    if (parameters[1] == null || /* for TD */vOI.getListLength(parameters[1]) == 0) {// Vif was null
        buf.iterate(w);
    } else {
        if (parameters[2] == null) {
            throw new UDFArgumentException("The third argument Xj must not be null");
        }
        double x = PrimitiveObjectInspectorUtils.getDouble(parameters[2], xOI);
        buf.iterate(w, x, parameters[1], vOI, vElemOI);
    }
}
 
Example #3
Source Project: incubator-hivemall   Author: apache   File: MulticlassConfidenceWeightedUDTF.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected CommandLine processOptions(ObjectInspector[] argOIs) throws UDFArgumentException {
    final CommandLine cl = super.processOptions(argOIs);

    float phi = 1.f;
    if (cl != null) {
        String phi_str = cl.getOptionValue("phi");
        if (phi_str == null) {
            String eta_str = cl.getOptionValue("eta");
            if (eta_str != null) {
                double eta = Double.parseDouble(eta_str);
                if (eta <= 0.5 || eta > 1) {
                    throw new UDFArgumentException(
                        "Confidence hyperparameter eta must be in range (0.5, 1]: " + eta_str);
                }
                phi = (float) StatsUtils.probit(eta, 5d);
            }
        } else {
            phi = Float.parseFloat(phi_str);
        }
    }

    this.phi = phi;
    return cl;
}
 
Example #4
Source Project: incubator-hivemall   Author: apache   File: MapKeyValuesUDF.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 function MAP_KEYS only accepts one argument.");
    } else if (!(arguments[0] instanceof MapObjectInspector)) {
        throw new UDFArgumentTypeException(0,
            "\"" + Category.MAP.toString().toLowerCase()
                    + "\" is expected at function MAP_KEYS, " + "but \""
                    + arguments[0].getTypeName() + "\" is found");
    }

    this.mapOI = (MapObjectInspector) arguments[0];

    List<String> structFieldNames = new ArrayList<String>();
    List<ObjectInspector> structFieldObjectInspectors = new ArrayList<ObjectInspector>();
    structFieldNames.add("key");
    structFieldObjectInspectors.add(mapOI.getMapKeyObjectInspector());
    structFieldNames.add("value");
    structFieldObjectInspectors.add(mapOI.getMapValueObjectInspector());

    return ObjectInspectorFactory.getStandardListObjectInspector(
        ObjectInspectorFactory.getStandardStructObjectInspector(structFieldNames,
            structFieldObjectInspectors));
}
 
Example #5
Source Project: incubator-hivemall   Author: apache   File: MapExcludeKeysUDF.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 2) {
        throw new UDFArgumentLengthException(
            "Expected two arguments for map_filter_keys: " + argOIs.length);
    }

    this.mapOI = HiveUtils.asMapOI(argOIs[0]);
    this.listOI = HiveUtils.asListOI(argOIs[1]);

    ObjectInspector mapKeyOI = mapOI.getMapKeyObjectInspector();
    ObjectInspector filterKeyOI = listOI.getListElementObjectInspector();

    if (!ObjectInspectorUtils.compareTypes(mapKeyOI, filterKeyOI)) {
        throw new UDFArgumentException("Element types does not match: mapKey "
                + mapKeyOI.getTypeName() + ", filterKey" + filterKeyOI.getTypeName());
    }

    return ObjectInspectorUtils.getStandardObjectInspector(mapOI,
        ObjectInspectorCopyOption.WRITABLE);
}
 
Example #6
Source Project: incubator-hivemall   Author: apache   File: ConditionalEmitUDTF.java    License: 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(
            "conditional_emit takes 2 arguments: array<boolean>, array<primitive>");
    }

    this.conditionsOI = HiveUtils.asListOI(argOIs[0]);
    this.condElemOI = HiveUtils.asBooleanOI(conditionsOI.getListElementObjectInspector());

    this.featuresOI = HiveUtils.asListOI(argOIs[1]);
    this.featureElemOI =
            HiveUtils.asPrimitiveObjectInspector(featuresOI.getListElementObjectInspector());

    List<String> fieldNames = Arrays.asList("feature");
    List<ObjectInspector> fieldOIs = Arrays.<ObjectInspector>asList(featureElemOI);

    return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
}
 
Example #7
Source Project: incubator-hivemall   Author: apache   File: KuromojiUDF.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Set<String> stopTags(@Nonnull final ObjectInspector oi)
        throws UDFArgumentException {
    if (HiveUtils.isVoidOI(oi)) {
        return JapaneseAnalyzer.getDefaultStopTags();
    }
    final String[] array = HiveUtils.getConstStringArray(oi);
    if (array == null) {
        return JapaneseAnalyzer.getDefaultStopTags();
    }
    final int length = array.length;
    if (length == 0) {
        return Collections.emptySet();
    }
    final Set<String> results = new HashSet<String>(length);
    for (int i = 0; i < length; i++) {
        String s = array[i];
        if (s != null) {
            results.add(s);
        }
    }
    return results;
}
 
Example #8
Source Project: incubator-hivemall   Author: apache   File: UDFWithOptions.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
protected final CommandLine parseOptions(@Nonnull String optionValue)
        throws UDFArgumentException {
    String[] args = optionValue.split("\\s+");
    Options opts = getOptions();
    opts.addOption("help", false, "Show function help");

    final CommandLine cl;
    try {
        cl = CommandLineUtils.parseOptions(args, opts);
    } catch (IllegalArgumentException e) {
        throw new UDFArgumentException(e);
    }

    if (cl.hasOption("help")) {
        showHelp(opts);
    }

    return cl;
}
 
Example #9
Source Project: incubator-hivemall   Author: apache   File: BprSamplingUDTF.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private void addFeedback(final int userId, @Nonnull final Object arg)
        throws UDFArgumentException {
    final int size = itemListOI.getListLength(arg);
    if (size == 0) {
        return;
    }

    int maxItemId = feedback.getMaxItemId();
    final IntArrayList posItems = new IntArrayList(size);
    for (int i = 0; i < size; i++) {
        Object elem = itemListOI.getListElement(arg, i);
        if (elem == null) {
            continue;
        }
        int index = PrimitiveObjectInspectorUtils.getInt(elem, itemElemOI);
        validateIndex(index);
        maxItemId = Math.max(index, maxItemId);
        posItems.add(index);
    }

    feedback.addFeedback(userId, posItems);
    feedback.setMaxItemId(maxItemId);
}
 
Example #10
Source Project: incubator-hivemall   Author: apache   File: FeatureHashingUDF.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(@Nonnull ObjectInspector[] argOIs)
        throws UDFArgumentException {
    if (argOIs.length != 1 && argOIs.length != 2) {
        showHelp("The feature_hashing function takes 1 or 2 arguments: " + argOIs.length);
    }
    ObjectInspector argOI0 = argOIs[0];
    this._listOI = HiveUtils.isListOI(argOI0) ? (ListObjectInspector) argOI0 : null;

    if (argOIs.length == 2) {
        String opts = HiveUtils.getConstString(argOIs[1]);
        processOptions(opts);
    }

    if (_listOI == null) {
        return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    } else {
        return ObjectInspectorFactory.getStandardListObjectInspector(
            PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    }
}
 
Example #11
Source Project: hive-third-functions   Author: aaronshan   File: UDFJsonArrayExtractScalar.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 2) {
        throw new UDFArgumentLengthException(
                "The function json_array_extract_scalar(json, json_path) takes exactly 2 arguments.");
    }

    converters = new ObjectInspectorConverters.Converter[arguments.length];
    for (int i = 0; i < arguments.length; i++) {
        converters[i] = ObjectInspectorConverters.getConverter(arguments[i],
                PrimitiveObjectInspectorFactory.writableStringObjectInspector);
    }

    return ObjectInspectorFactory
            .getStandardListObjectInspector(PrimitiveObjectInspectorFactory
                    .writableStringObjectInspector);
}
 
Example #12
Source Project: incubator-hivemall   Author: apache   File: GenerateSeriesUDTF.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public StructObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 2 && argOIs.length != 3) {
        throw new UDFArgumentException(
            "Expected number of arguments is 2 or 3: " + argOIs.length);
    }
    this.startOI = HiveUtils.asIntegerOI(argOIs, 0);
    this.endOI = HiveUtils.asIntegerOI(argOIs, 1);

    if (argOIs.length == 3) {
        this.stepOI = HiveUtils.asIntegerOI(argOIs, 2);
    }

    this.returnLong = HiveUtils.isBigIntOI(startOI) || HiveUtils.isBigIntOI(endOI);

    List<String> fieldNames = new ArrayList<>(1);
    fieldNames.add("value");
    List<ObjectInspector> fieldOIs = new ArrayList<>(1);
    if (returnLong) {
        fieldOIs.add(PrimitiveObjectInspectorFactory.writableLongObjectInspector);
    } else {
        fieldOIs.add(PrimitiveObjectInspectorFactory.writableIntObjectInspector);
    }
    return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
}
 
Example #13
Source Project: incubator-hivemall   Author: apache   File: FeatureUDF.java    License: Apache License 2.0 6 votes vote down vote up
private static void validateFeatureOI(@Nonnull ObjectInspector argOI)
        throws UDFArgumentException {
    if (!HiveUtils.isPrimitiveOI(argOI)) {
        throw new UDFArgumentException(
            "_FUNC_ expects integer type or string for `feature` but got "
                    + argOI.getTypeName());
    }
    final PrimitiveObjectInspector oi = (PrimitiveObjectInspector) argOI;
    switch (oi.getPrimitiveCategory()) {
        case INT:
        case SHORT:
        case LONG:
        case BYTE:
        case STRING:
            break;
        default: {
            throw new UDFArgumentException(
                "_FUNC_ expects integer type or string for `feature` but got "
                        + argOI.getTypeName());
        }
    }
}
 
Example #14
Source Project: incubator-hivemall   Author: apache   File: MinHashUDTF.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected CommandLine processOptions(ObjectInspector[] argOIs) throws UDFArgumentException {
    CommandLine cl = null;
    if (argOIs.length >= 3) {
        String rawArgs = HiveUtils.getConstString(argOIs[2]);
        cl = parseOptions(rawArgs);

        String numHashes = cl.getOptionValue("hashes");
        if (numHashes != null) {
            this.num_hashes = Integer.parseInt(numHashes);
        }

        String numKeygroups = cl.getOptionValue("keygroups");
        if (numKeygroups != null) {
            this.num_keygroups = Integer.parseInt(numKeygroups);
        }
    }

    this.hashFuncs = HashFunctionFactory.create(num_hashes);

    return cl;
}
 
Example #15
Source Project: incubator-hivemall   Author: apache   File: KuromojiUDF.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static UserDictionary userDictionary(@Nullable final String[] userDictArray)
        throws UDFArgumentException {
    if (userDictArray == null) {
        return null;
    }

    final StringBuilder builder = new StringBuilder();
    for (String row : userDictArray) {
        builder.append(row).append('\n');
    }
    final Reader reader = new StringReader(builder.toString());
    try {
        return UserDictionary.open(reader); // return null if empty
    } catch (Throwable e) {
        throw new UDFArgumentException(
            "Failed to create user dictionary based on the given array<string>: "
                    + builder.toString() + '\n' + ExceptionUtils.prettyPrintStackTrace(e));
    }
}
 
Example #16
Source Project: incubator-hivemall   Author: apache   File: VectorAddUDF.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 2) {
        throw new UDFArgumentLengthException("Expected 2 arguments, but got " + argOIs.length);
    }

    this.xOI = HiveUtils.asListOI(argOIs[0]);
    this.yOI = HiveUtils.asListOI(argOIs[1]);
    this.xElemOI = HiveUtils.asNumberOI(xOI.getListElementObjectInspector());
    this.yElemOI = HiveUtils.asNumberOI(yOI.getListElementObjectInspector());

    if (HiveUtils.isIntegerOI(xElemOI) && HiveUtils.isIntegerOI(yElemOI)) {
        this.floatingPoints = false;
        return ObjectInspectorFactory.getStandardListObjectInspector(
            PrimitiveObjectInspectorFactory.javaLongObjectInspector);
    } else {
        this.floatingPoints = true;
        return ObjectInspectorFactory.getStandardListObjectInspector(
            PrimitiveObjectInspectorFactory.javaDoubleObjectInspector);
    }
}
 
Example #17
Source Project: incubator-hivemall   Author: apache   File: GuessAttributesUDF.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    final StringBuilder buf = new StringBuilder(128);
    final int numArgs = argOIs.length;
    final int last = numArgs - 1;
    for (int i = 0; i < numArgs; i++) {
        if (HiveUtils.isNumberOI(argOIs[i])) {
            buf.append('Q'); // quantitative
        } else {
            buf.append('C'); // categorical            
        }
        if (i != last) {
            buf.append(',');
        }
    }
    String value = buf.toString();
    return ObjectInspectorUtils.getConstantObjectInspector(
        PrimitiveObjectInspectorFactory.javaStringObjectInspector, value);
}
 
Example #18
Source Project: incubator-hivemall   Author: apache   File: KernelExpansionPassiveAggressiveUDTF.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected CommandLine processOptions(ObjectInspector[] argOIs) throws UDFArgumentException {
    float pkc = 1.f;
    float c = 1.f;
    String algo = "pa1";

    final CommandLine cl = super.processOptions(argOIs);
    if (cl != null) {
        String pkc_str = cl.getOptionValue("pkc");
        if (pkc_str != null) {
            pkc = Float.parseFloat(pkc_str);
        }
        String c_str = cl.getOptionValue("c");
        if (c_str != null) {
            c = Float.parseFloat(c_str);
            if (c <= 0.f) {
                throw new UDFArgumentException(
                    "Aggressiveness parameter C must be C > 0: " + c);
            }
        }
        algo = cl.getOptionValue("algo", algo);
    }

    if ("pa1".equalsIgnoreCase(algo)) {
        this._algo = new PA1(c);
    } else if ("pa2".equalsIgnoreCase(algo)) {
        this._algo = new PA2(c);
    } else if ("pa".equalsIgnoreCase(algo)) {
        this._algo = new PA();
    } else {
        throw new UDFArgumentException("Unsupported algorithm: " + algo);
    }
    this._pkc = pkc;

    return cl;
}
 
Example #19
Source Project: incubator-hivemall   Author: apache   File: HiveUtils.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static DoubleObjectInspector asDoubleOI(@Nonnull final ObjectInspector[] argOIs,
        final int argIndex) throws UDFArgumentException {
    ObjectInspector argOI = getObjectInspector(argOIs, argIndex);
    if (!DOUBLE_TYPE_NAME.equals(argOI.getTypeName())) {
        throw new UDFArgumentTypeException(argIndex,
            "Argument type must be DOUBLE: " + argOI.getTypeName());
    }
    return (DoubleObjectInspector) argOI;
}
 
Example #20
Source Project: incubator-hivemall   Author: apache   File: FirstElementUDF.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 1) {
        throw new UDFArgumentException("first_element takes an array as an argument.");
    }
    this.listInspector = HiveUtils.asListOI(argOIs[0]);

    return listInspector.getListElementObjectInspector();
}
 
Example #21
Source Project: incubator-hivemall   Author: apache   File: MulticlassAROWClassifierUDTF.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StructObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    final int numArgs = argOIs.length;
    if (numArgs != 2 && numArgs != 3) {
        throw new UDFArgumentException(
            "_FUNC_ takes 2 or 3 arguments: List<String|Int|BitInt> features, {Int|String} label [, constant String options]");
    }

    return super.initialize(argOIs);
}
 
Example #22
Source Project: incubator-hivemall   Author: apache   File: HiveUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static long getConstLong(@Nonnull final ObjectInspector oi) throws UDFArgumentException {
    if (!isBigIntOI(oi)) {
        throw new UDFArgumentException("argument must be a BigInt value: "
                + TypeInfoUtils.getTypeInfoFromObjectInspector(oi));
    }
    LongWritable v = getConstValue(oi);
    return v.get();
}
 
Example #23
Source Project: incubator-hivemall   Author: apache   File: ArrayConcatUDF.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length < 1) {
        throw new UDFArgumentLengthException(
            "_FUNC_(array1, array2) needs at least 1 argument.");
    }
    final int nargs = arguments.length;
    for (int i = 0; i < nargs; i++) {
        switch (arguments[i].getCategory()) {
            case LIST:
                if (((ListObjectInspector) (arguments[i])).getListElementObjectInspector()
                                                          .getCategory()
                                                          .equals(Category.PRIMITIVE)) {
                    break;
                }
            default:
                throw new UDFArgumentTypeException(0,
                    "Argument " + i + " of function CONCAT_ARRAY must be " + LIST_TYPE_NAME
                            + "<" + Category.PRIMITIVE + ">, but " + arguments[0].getTypeName()
                            + " was found.");
        }
    }

    ListObjectInspector[] listOIs = new ListObjectInspector[nargs];
    for (int i = 0; i < nargs; i++) {
        listOIs[i] = (ListObjectInspector) arguments[i];
    }
    this.argumentOIs = listOIs;

    ObjectInspector firstElemOI = listOIs[0].getListElementObjectInspector();
    ObjectInspector returnElemOI = ObjectInspectorUtils.getStandardObjectInspector(firstElemOI,
        ObjectInspectorCopyOption.WRITABLE);

    return ObjectInspectorFactory.getStandardListObjectInspector(returnElemOI);
}
 
Example #24
Source Project: incubator-hivemall   Author: apache   File: SmartcnUDFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testOneArgument() throws UDFArgumentException, IOException {
    GenericUDF udf = new SmartcnUDF();
    ObjectInspector[] argOIs = new ObjectInspector[1];
    // line
    argOIs[0] = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    udf.initialize(argOIs);
    udf.close();
}
 
Example #25
Source Project: incubator-hivemall   Author: apache   File: AdaDeltaUDTF.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected CommandLine processOptions(ObjectInspector[] argOIs) throws UDFArgumentException {
    CommandLine cl = super.processOptions(argOIs);
    if (cl == null) {
        this.decay = 0.95f;
        this.eps = 1e-6f;
        this.scaling = 100f;
    } else {
        this.decay = Primitives.parseFloat(cl.getOptionValue("decay"), 0.95f);
        this.eps = Primitives.parseFloat(cl.getOptionValue("eps"), 1E-6f);
        this.scaling = Primitives.parseFloat(cl.getOptionValue("scale"), 100f);
    }
    return cl;
}
 
Example #26
Source Project: incubator-hivemall   Author: apache   File: HiveUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean getConstBoolean(@Nonnull final ObjectInspector oi)
        throws UDFArgumentException {
    if (!isBooleanOI(oi)) {
        throw new UDFArgumentException("argument must be a Boolean value: "
                + TypeInfoUtils.getTypeInfoFromObjectInspector(oi));
    }
    BooleanWritable v = getConstValue(oi);
    return v.get();
}
 
Example #27
Source Project: incubator-hivemall   Author: apache   File: MulticlassConfidenceWeightedUDTF.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public StructObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    final int numArgs = argOIs.length;
    if (numArgs != 2 && numArgs != 3) {
        throw new UDFArgumentException(
            "_FUNC_ takes 2 or 3 arguments: List<String|Int|BitInt> features, {Int|String} label [, constant String options]");
    }

    return super.initialize(argOIs);
}
 
Example #28
Source Project: incubator-hivemall   Author: apache   File: GeneralClassifierUDTFTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = UDFArgumentException.class)
public void testUnsupportedOptimizer() throws Exception {
    GeneralClassifierUDTF udtf = new GeneralClassifierUDTF();
    ObjectInspector intOI = PrimitiveObjectInspectorFactory.javaIntObjectInspector;
    ObjectInspector stringOI = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    ListObjectInspector stringListOI =
            ObjectInspectorFactory.getStandardListObjectInspector(stringOI);
    ObjectInspector params = ObjectInspectorUtils.getConstantObjectInspector(
        PrimitiveObjectInspectorFactory.javaStringObjectInspector, "-opt UnsupportedOpt");

    udtf.initialize(new ObjectInspector[] {stringListOI, intOI, params});
}
 
Example #29
Source Project: incubator-hivemall   Author: apache   File: SingularSpectrumTransformUDF.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected CommandLine processOptions(String optionValues) throws UDFArgumentException {
    CommandLine cl = parseOptions(optionValues);

    this._params.w = Primitives.parseInt(cl.getOptionValue("w"), _params.w);
    this._params.n = Primitives.parseInt(cl.getOptionValue("n"), _params.w);
    this._params.m = Primitives.parseInt(cl.getOptionValue("m"), _params.w);
    this._params.g = Primitives.parseInt(cl.getOptionValue("g"), -1 * _params.w);
    this._params.r = Primitives.parseInt(cl.getOptionValue("r"), _params.r);
    this._params.k = Primitives.parseInt(cl.getOptionValue("k"),
        (_params.r % 2 == 0) ? (2 * _params.r) : (2 * _params.r - 1));

    this._params.scoreFunc =
            ScoreFunction.resolve(cl.getOptionValue("scorefunc", ScoreFunction.svd.name()));
    if ((_params.w != _params.n || _params.w != _params.m)
            && _params.scoreFunc == ScoreFunction.ika) {
        throw new UDFArgumentException("IKA-based efficient SST requires w = n = m");
    }

    this._params.changepointThreshold =
            Primitives.parseDouble(cl.getOptionValue("th"), _params.changepointThreshold);

    Preconditions.checkArgument(_params.w >= 2, UDFArgumentException.class,
        "w must be greater than 1: " + _params.w);
    Preconditions.checkArgument(_params.r >= 1, UDFArgumentException.class,
        "r must be greater than 0: " + _params.r);
    Preconditions.checkArgument(_params.k >= 1, UDFArgumentException.class,
        "k must be greater than 0: " + _params.k);
    Preconditions.checkArgument(_params.k >= _params.r, UDFArgumentException.class,
        "k must be equals to or greater than r: k=" + _params.k + ", r" + _params.r);
    Preconditions.checkArgument(
        _params.changepointThreshold > 0.d && _params.changepointThreshold < 1.d,
        UDFArgumentException.class,
        "changepointThreshold must be in range (0, 1): " + _params.changepointThreshold);

    return cl;
}
 
Example #30
Source Project: incubator-hivemall   Author: apache   File: TreeExportUDF.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected CommandLine processOptions(@Nonnull String opts) throws UDFArgumentException {
    CommandLine cl = parseOptions(opts);

    OutputType outputType = OutputType.resolve(cl.getOptionValue("type"));
    boolean regression = cl.hasOption("regression");
    String outputName = cl.getOptionValue("output_name", "predicted");
    this.evaluator = new Evaluator(outputType, outputName, regression);

    return cl;
}