public ObjectInspector initialize(ObjectInspector[] arguments)
throws UDFArgumentException {
// Check if two arguments were passed
if (arguments.length != ARG_COUNT) {
throw new UDFArgumentException(
"The function " + FUNC_NAME + " accepts "
+ ARG_COUNT + " arguments.");
}
// Check if ARRAY_IDX argument is of category LIST
if (!arguments[ARRAY_IDX].getCategory().equals(Category.LIST)) {
throw new UDFArgumentTypeException(ARRAY_IDX,
"\"" + org.apache.hadoop.hive.serde.Constants.LIST_TYPE_NAME + "\" "
+ "expected at function ARRAY_CONTAINS, but "
+ "\"" + arguments[ARRAY_IDX].getTypeName() + "\" "
+ "is found");
}
arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
arrayElementOI = arrayOI.getListElementObjectInspector();
valueOI = arguments[VALUE_IDX];
// Check if list element and value are of same type
if (!ObjectInspectorUtils.compareTypes(arrayElementOI, valueOI)) {
throw new UDFArgumentTypeException(VALUE_IDX,
"\"" + arrayElementOI.getTypeName() + "\""
+ " expected at function ARRAY_CONTAINS, but "
+ "\"" + valueOI.getTypeName() + "\""
+ " is found");
}
// Check if the comparison is supported for this type
if (!ObjectInspectorUtils.compareSupported(valueOI)) {
throw new UDFArgumentException("The function " + FUNC_NAME
+ " does not support comparison for "
+ "\"" + valueOI.getTypeName() + "\""
+ " types");
}