use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.
the class GenericUDFAdd10 method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 1) {
throw new UDFArgumentLengthException("ADD10() requires 1 argument, got " + arguments.length);
}
if (arguments[0].getCategory() != Category.PRIMITIVE) {
throw new UDFArgumentException("ADD10 only takes primitive types, got " + arguments[0].getTypeName());
}
argumentOI = (PrimitiveObjectInspector) arguments[0];
inputType = argumentOI.getPrimitiveCategory();
ObjectInspector outputOI = null;
switch(inputType) {
case SHORT:
case BYTE:
case INT:
inputConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableIntObjectInspector);
outputOI = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
break;
case LONG:
inputConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableLongObjectInspector);
outputOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
break;
case FLOAT:
case STRING:
case DOUBLE:
inputConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
outputOI = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
break;
case DECIMAL:
outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(((PrimitiveObjectInspector) arguments[0]).getTypeInfo());
inputConverter = ObjectInspectorConverters.getConverter(arguments[0], outputOI);
break;
default:
throw new UDFArgumentException("ADD10 only takes SHORT/BYTE/INT/LONG/DOUBLE/FLOAT/STRING/DECIMAL types, got " + inputType);
}
return outputOI;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.
the class TestGenericUDFSoundex method testSoundexWrongLength.
public void testSoundexWrongLength() throws HiveException {
@SuppressWarnings("resource") GenericUDFSoundex udf = new GenericUDFSoundex();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector;
ObjectInspector[] arguments = { valueOI0, valueOI1 };
try {
udf.initialize(arguments);
assertTrue("soundex test. UDFArgumentLengthException is expected", false);
} catch (UDFArgumentLengthException e) {
assertEquals("soundex test", "soundex requires 1 argument, got 2", e.getMessage());
}
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.
the class GenericUDFAssertTrueOOM method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
HiveConf conf = SessionState.getSessionConf();
if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_IN_TEST)) {
throw new RuntimeException("this UDF is only available in testmode");
}
if (arguments.length != 1) {
throw new UDFArgumentLengthException("ASSERT_TRUE_OOM() expects one argument.");
}
if (arguments[0].getCategory() != Category.PRIMITIVE) {
throw new UDFArgumentTypeException(0, "Argument to ASSERT_TRUE_OOM() should be primitive.");
}
conditionConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableBooleanObjectInspector);
return PrimitiveObjectInspectorFactory.writableVoidObjectInspector;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.
the class GenericUDFGrouping method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length < 2) {
throw new UDFArgumentLengthException("grouping() requires at least 2 argument, got " + arguments.length);
}
if (arguments[0].getCategory() != Category.PRIMITIVE) {
throw new UDFArgumentTypeException(0, "The first argument to grouping() must be primitive");
}
PrimitiveObjectInspector arg1OI = (PrimitiveObjectInspector) arguments[0];
// INT can happen in cases where grouping() is used without grouping sets, in all other cases it should be LONG.
if (!(arg1OI.getPrimitiveCategory() == PrimitiveCategory.INT || arg1OI.getPrimitiveCategory() == PrimitiveCategory.LONG)) {
throw new UDFArgumentTypeException(0, "The first argument to grouping() must be an int/long. Got: " + arg1OI.getPrimitiveCategory());
}
groupingIdOI = arg1OI;
indices = new int[arguments.length - 1];
for (int i = 1; i < arguments.length; i++) {
PrimitiveObjectInspector arg2OI = (PrimitiveObjectInspector) arguments[i];
if (!(arg2OI instanceof ConstantObjectInspector)) {
throw new UDFArgumentTypeException(i, "Must be a constant. Got: " + arg2OI.getClass().getSimpleName());
}
indices[i - 1] = PrimitiveObjectInspectorUtils.getInt(((ConstantObjectInspector) arguments[i]).getWritableConstantValue(), arg2OI);
}
return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.
the class GenericUDFLikeAny method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length < 2) {
throw new UDFArgumentLengthException("The like any operator requires at least one pattern for matching, got " + (arguments.length - 1));
}
inputTypes = new PrimitiveCategory[arguments.length];
converters = new Converter[arguments.length];
/**
*expects string and null arguments
*/
for (int idx = 0; idx < arguments.length; idx++) {
checkArgPrimitive(arguments, idx);
checkArgGroups(arguments, idx, inputTypes, PrimitiveGrouping.STRING_GROUP, PrimitiveGrouping.VOID_GROUP);
PrimitiveCategory inputType = ((PrimitiveObjectInspector) arguments[idx]).getPrimitiveCategory();
if (arguments[idx] instanceof ConstantObjectInspector && idx != 0) {
Object constValue = ((ConstantObjectInspector) arguments[idx]).getWritableConstantValue();
if (!isConstantNullPatternContain && constValue == null) {
isConstantNullPatternContain = true;
}
} else if (idx != 0 && isAllPatternsConstant) {
isAllPatternsConstant = false;
}
converters[idx] = ObjectInspectorConverters.getConverter(arguments[idx], getOutputOI(inputType));
inputTypes[idx] = inputType;
}
return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
Aggregations