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 File: BprSamplingUDTF.java    From incubator-hivemall with 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 #2
Source File: FeatureUDF.java    From incubator-hivemall with 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 #3
Source File: MulticlassConfidenceWeightedUDTF.java    From incubator-hivemall with 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 File: MapKeyValuesUDF.java    From incubator-hivemall 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 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 File: MapExcludeKeysUDF.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) {
        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 File: ConditionalEmitUDTF.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(
            "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 File: KuromojiUDF.java    From incubator-hivemall with 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 File: FMPredictGenericUDAF.java    From incubator-hivemall with 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 #9
Source File: GenerateSeriesUDTF.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 && 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 #10
Source File: UDFJsonArrayExtractScalar.java    From hive-third-functions with 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 #11
Source File: FeatureHashingUDF.java    From incubator-hivemall with 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 #12
Source File: KuromojiUDF.java    From incubator-hivemall with 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 #13
Source File: UDFWithOptions.java    From incubator-hivemall with 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 #14
Source File: VectorAddUDF.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) {
        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 #15
Source File: GuessAttributesUDF.java    From incubator-hivemall with 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 #16
Source File: MinHashUDTF.java    From incubator-hivemall with 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 #17
Source File: HiveGenericUDF.java    From flink with 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 #18
Source File: UDFRe2JRegexpExtractAll.java    From hive-third-functions with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != 2 && arguments.length != 3) {
        throw new UDFArgumentLengthException(
                "The function regexp_extract_all takes exactly 2 or 3 arguments.");
    }

    for (int i = 0; i < 2; i++) {
        if (!ObjectInspectorUtils.compareTypes(PrimitiveObjectInspectorFactory.javaStringObjectInspector, arguments[i])) {
            throw new UDFArgumentTypeException(i,
                    "\"" + PrimitiveObjectInspectorFactory.javaStringObjectInspector.getTypeName() + "\" "
                            + "expected at function regexp_extract_all, but "
                            + "\"" + arguments[i].getTypeName() + "\" "
                            + "is found");
        }
    }

    if (arguments.length == 3) {
        if (!ObjectInspectorUtils.compareTypes(PrimitiveObjectInspectorFactory.javaLongObjectInspector, arguments[2])) {
            throw new UDFArgumentTypeException(2,
                    "\"" + PrimitiveObjectInspectorFactory.javaLongObjectInspector.getTypeName() + "\" "
                            + "expected at function regexp_extract_all, but "
                            + "\"" + arguments[2].getTypeName() + "\" "
                            + "is found");
        }
    }

    ObjectInspector expectOI = PrimitiveObjectInspectorFactory.javaStringObjectInspector;

    return ObjectInspectorFactory.getStandardListObjectInspector(expectOI);
}
 
Example #19
Source File: KuromojiUDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static CharArraySet stopWords(@Nullable final String[] array)
        throws UDFArgumentException {
    if (array == null) {
        return JapaneseAnalyzer.getDefaultStopSet();
    }
    if (array.length == 0) {
        return CharArraySet.EMPTY_SET;
    }
    return new CharArraySet(Arrays.asList(array), /* ignoreCase */true);
}
 
Example #20
Source File: KuromojiUDFTest.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Test(expected = UDFArgumentException.class)
public void testUnsupportedOptionArgs()
        throws IOException, HiveException, IllegalAccessException, NoSuchFieldException {
    GenericUDF udf = new KuromojiUDF();
    ObjectInspector[] argOIs = new ObjectInspector[2];

    argOIs[0] = PrimitiveObjectInspectorFactory.javaStringObjectInspector; // line
    argOIs[1] = HiveUtils.getConstStringObjectInspector("-mode normal -unsupported_option"); // mode
    udf.initialize(argOIs);

    udf.close();
}
 
Example #21
Source File: FeatureUDFTest.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Test(expected = UDFArgumentException.class)
public void testInvalidFeatureName() throws Exception {
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    ObjectInspector weightOI = PrimitiveObjectInspectorFactory.javaDoubleObjectInspector;
    udf.initialize(new ObjectInspector[] {featureOI, weightOI});

    udf.evaluate(new GenericUDF.DeferredObject[] {new DeferredJavaObject(new Text("f:1")),
            new DeferredJavaObject(new DoubleWritable(2.5d))});

    Assert.fail();
}
 
Example #22
Source File: MFPredictionUDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
private static double mfPredict(@Nullable final double[] Pu, @Nullable final double[] Qi,
        final double Bu, final double Bi, final double mu) throws UDFArgumentException {
    if (Pu == null) {
        if (Qi == null) {
            return mu;
        } else {
            return mu + Bi;
        }
    } else if (Qi == null) {
        return mu + Bu;
    }
    // workaround for TD
    if (Pu.length == 0) {
        if (Qi.length == 0) {
            return mu;
        } else {
            return mu + Bi;
        }
    } else if (Qi.length == 0) {
        return mu + Bu;
    }

    if (Pu.length != Qi.length) {
        throw new UDFArgumentException(
            "|Pu| " + Pu.length + " was not equal to |Qi| " + Qi.length);
    }

    double ret = mu + Bu + Bi;
    for (int k = 0, size = Pu.length; k < size; k++) {
        double pu_k = Pu[k];
        double qi_k = Qi[k];
        ret += pu_k * qi_k;
    }
    return ret;
}
 
Example #23
Source File: TreePredictUDFv1.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
JavascriptEvaluator() throws UDFArgumentException {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByExtension("js");
    if (!(engine instanceof Compilable)) {
        throw new UDFArgumentException(
            "ScriptEngine was not compilable: " + engine.getFactory().getEngineName()
                    + " version " + engine.getFactory().getEngineVersion());
    }
    this.scriptEngine = engine;
    this.compilableEngine = (Compilable) engine;
}
 
Example #24
Source File: XGBoostTrainUDTFTest.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Test(expected = UDFArgumentException.class)
public void testNoObjective() throws HiveException {
    XGBoostTrainUDTF udtf = new XGBoostTrainUDTF();
    udtf.initialize(
        new ObjectInspector[] {
                ObjectInspectorFactory.getStandardListObjectInspector(
                    PrimitiveObjectInspectorFactory.javaStringObjectInspector),
                PrimitiveObjectInspectorFactory.javaFloatObjectInspector,
                ObjectInspectorUtils.getConstantObjectInspector(
                    PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                    "-num_class 4")});
}
 
Example #25
Source File: MAPUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public void iterate(@SuppressWarnings("deprecation") AggregationBuffer agg,
        Object[] parameters) throws HiveException {
    MAPAggregationBuffer myAggr = (MAPAggregationBuffer) agg;

    List<?> recommendList = recommendListOI.getList(parameters[0]);
    if (recommendList == null) {
        recommendList = Collections.emptyList();
    }
    List<?> truthList = truthListOI.getList(parameters[1]);
    if (truthList == null) {
        return;
    }

    int recommendSize = recommendList.size();
    if (parameters.length == 3) {
        recommendSize =
                PrimitiveObjectInspectorUtils.getInt(parameters[2], recommendSizeOI);
        if (recommendSize < 0) {
            throw new UDFArgumentException(
                "The third argument `int recommendSize` must be in greater than or equals to 0: "
                        + recommendSize);
        }
    }

    myAggr.iterate(recommendList, truthList, recommendSize);
}
 
Example #26
Source File: RaiseErrorUDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 0 && argOIs.length != 1) {
        throw new UDFArgumentLengthException(
            "Expected one or two arguments for raise_error UDF: " + argOIs.length);
    }

    return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
 
Example #27
Source File: PLSAPredictUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Nullable
protected CommandLine processOptions(ObjectInspector[] argOIs) throws UDFArgumentException {
    CommandLine cl = null;

    if (argOIs.length >= 5) {
        String rawArgs = HiveUtils.getConstString(argOIs[4]);
        cl = parseOptions(rawArgs);

        this.topics =
                Primitives.parseInt(cl.getOptionValue("topics"), PLSAUDTF.DEFAULT_TOPICS);
        if (topics < 1) {
            throw new UDFArgumentException(
                "A positive integer MUST be set to an option `-topics`: " + topics);
        }

        this.alpha =
                Primitives.parseFloat(cl.getOptionValue("alpha"), PLSAUDTF.DEFAULT_ALPHA);
        this.delta =
                Primitives.parseDouble(cl.getOptionValue("delta"), PLSAUDTF.DEFAULT_DELTA);
    } else {
        this.topics = PLSAUDTF.DEFAULT_TOPICS;
        this.alpha = PLSAUDTF.DEFAULT_ALPHA;
        this.delta = PLSAUDTF.DEFAULT_DELTA;
    }

    return cl;
}
 
Example #28
Source File: ItemPairsSamplingUDTF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public StructObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 2 && argOIs.length != 3) {
        throw new UDFArgumentException(
            "_FUNC_(array<long>, const long max_item_id [, const string options])"
                    + " takes at least two arguments");
    }
    this.listOI = HiveUtils.asListOI(argOIs[0]);
    this.listElemOI =
            HiveUtils.asPrimitiveObjectInspector(listOI.getListElementObjectInspector());
    processOptions(argOIs);

    this.maxItemId = HiveUtils.getAsConstInt(argOIs[1]);
    if (maxItemId <= 0) {
        throw new UDFArgumentException("maxItemId MUST be greater than 0: " + maxItemId);
    }

    this.posItemId = new IntWritable();
    this.negItemId = new IntWritable();
    this.forwardObjs = new Object[] {posItemId, negItemId};

    ArrayList<String> fieldNames = new ArrayList<String>();
    ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>();
    fieldNames.add("pos_item");
    fieldOIs.add(PrimitiveObjectInspectorFactory.writableIntObjectInspector);
    fieldNames.add("neg_item");
    fieldOIs.add(PrimitiveObjectInspectorFactory.writableIntObjectInspector);

    return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
}
 
Example #29
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static BooleanObjectInspector asBooleanOI(@Nonnull final ObjectInspector[] argOIs,
        final int argIndex) throws UDFArgumentException {
    ObjectInspector argOI = getObjectInspector(argOIs, argIndex);
    if (!BOOLEAN_TYPE_NAME.equals(argOI.getTypeName())) {
        throw new UDFArgumentTypeException(argIndex,
            "Argument type must be Boolean: " + argOI.getTypeName());
    }
    return (BooleanObjectInspector) argOI;
}
 
Example #30
Source File: KuromojiUDFTest.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
public void testExpectedMode() throws UDFArgumentException, IOException {
    GenericUDF udf = new KuromojiUDF();
    ObjectInspector[] argOIs = new ObjectInspector[2];
    // line
    argOIs[0] = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    // mode
    PrimitiveTypeInfo stringType = new PrimitiveTypeInfo();
    stringType.setTypeName("string");
    argOIs[1] = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(
        stringType, new Text("normal"));
    udf.initialize(argOIs);
    udf.close();
}