use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.
the class GenericUDFMapKeys method initialize.
@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");
}
mapOI = (MapObjectInspector) arguments[0];
ObjectInspector mapKeyOI = mapOI.getMapKeyObjectInspector();
return ObjectInspectorFactory.getStandardListObjectInspector(mapKeyOI);
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.
the class GenericUDFIn method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length < 2) {
throw new UDFArgumentLengthException("The function IN requires at least two arguments, got " + arguments.length);
}
argumentOIs = arguments;
// We want to use the ReturnObjectInspectorResolver because otherwise
// ObjectInspectorUtils.compare() will return != for two objects that have
// different object inspectors, e.g. 238 and "238". The ROIR will help convert
// both values to a common type so that they can be compared reasonably.
conversionHelper = new GenericUDFUtils.ReturnObjectInspectorResolver(true);
for (ObjectInspector oi : arguments) {
if (!conversionHelper.update(oi)) {
StringBuilder sb = new StringBuilder();
sb.append("The arguments for IN should be the same type! Types are: {");
sb.append(arguments[0].getTypeName());
sb.append(" IN (");
for (int i = 1; i < arguments.length; i++) {
if (i != 1) {
sb.append(", ");
}
sb.append(arguments[i].getTypeName());
}
sb.append(")}");
throw new UDFArgumentException(sb.toString());
}
}
compareOI = conversionHelper.get();
checkIfInSetConstant();
return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.
the class GenericUDFSoundex method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 1) {
throw new UDFArgumentLengthException(getFuncName() + " requires 1 argument, got " + arguments.length);
}
checkIfPrimitive(arguments, 0, "1st");
checkIfStringGroup(arguments, 0, "1st");
getStringConverter(arguments, 0, "1st");
ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
return outputOI;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.
the class GenericUDFSplit method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 2) {
throw new UDFArgumentLengthException("The function SPLIT(s, regexp) 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);
}
ObjectInspector rightArg = arguments[1];
if (rightArg instanceof ConstantObjectInspector) {
constPattern = Pattern.compile(((ConstantObjectInspector) rightArg).getWritableConstantValue().toString());
}
return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in project hive by apache.
the class GenericUDFMapValues method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 1) {
throw new UDFArgumentLengthException("The function MAP_VALUES only accepts 1 argument.");
} else if (!(arguments[0] instanceof MapObjectInspector)) {
throw new UDFArgumentTypeException(0, "\"" + Category.MAP.toString().toLowerCase() + "\" is expected at function MAP_VALUES, " + "but \"" + arguments[0].getTypeName() + "\" is found");
}
mapOI = (MapObjectInspector) arguments[0];
ObjectInspector mapValueOI = mapOI.getMapValueObjectInspector();
return ObjectInspectorFactory.getStandardListObjectInspector(mapValueOI);
}
Aggregations