@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length == 1) { sourceOI = arguments[0]; return objectInspectorConverter.convert(sourceOI); } if (arguments.length == 2 && (arguments[0] instanceof UnionObjectInspector) && (arguments[1] instanceof WritableConstantIntObjectInspector)) { tag = ((WritableConstantIntObjectInspector) arguments[1]).getWritableConstantValue().get(); unionOI = (UnionObjectInspector) arguments[0]; List<ObjectInspector> fieldOIs = ((UnionObjectInspector) arguments[0]).getObjectInspectors(); if (tag < 0 || tag >= fieldOIs.size()) { throw new UDFArgumentException( "int constant must be a valid union tag for " + unionOI.getTypeName() + ". Expected 0-" + (fieldOIs.size() - 1) + " got: " + tag); } return fieldOIs.get(tag); } String argumentTypes = "nothing"; if (arguments.length > 0) { List<String> typeNames = new ArrayList<>(); for (ObjectInspector oi : arguments) { typeNames.add(oi.getTypeName()); } argumentTypes = typeNames.toString(); } throw new UDFArgumentException( "Unsupported arguments. Expected a type containing a union or a union and an int constant, got: " + argumentTypes); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length == 1) { sourceOI = arguments[0]; return objectInspectorConverter.convert(sourceOI); } if (arguments.length == 2 && (arguments[0] instanceof UnionObjectInspector) && (arguments[1] instanceof WritableConstantIntObjectInspector)) { tag = ((WritableConstantIntObjectInspector) arguments[1]).getWritableConstantValue().get(); unionOI = (UnionObjectInspector) arguments[0]; List<ObjectInspector> fieldOIs = ((UnionObjectInspector) arguments[0]).getObjectInspectors(); if (tag < 0 || tag >= fieldOIs.size()) { throw new UDFArgumentException( "int constant must be a valid union tag for " + unionOI.getTypeName() + ". Expected 0-" + (fieldOIs.size() - 1) + " got: " + tag); } return fieldOIs.get(tag); } String argumentTypes = "nothing"; if (arguments.length > 0) { List<String> typeNames = new ArrayList<>(); for (ObjectInspector oi : arguments) { typeNames.add(oi.getTypeName()); } argumentTypes = typeNames.toString(); } throw new UDFArgumentException( "Unsupported arguments. Expected a type containing a union or a union and an int constant, got: " + argumentTypes); }
assertEquals("Italian", uoi.getField(val)); uoi.getTypeName();