private static Class getFunctionInClass(ExceptionalFunction functionClassName) throws ClassNotFoundException, NoSuchMethodException, IOException { return getFunctionTypeClass(functionClassName, 0); }
/** * Takes the class name of a Function, initializes it using the default constructor and passes * it to FunctionWrapperEvalFunc(ExceptionalFunction function). Functions must implement either * com.google.common.base.Function or ExceptionalFunction. * @param functionClassName function class to initialize */ public FunctionWrapperEvalFunc(String functionClassName) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException, IOException { this(initializeFunction(functionClassName)); }
@Override @SuppressWarnings("unchecked") public Object exec(Object input) throws IOException { try { return function.apply(input); } catch (Exception e) { safeIncrCounter(getCounterGroup(), e.getClass().getCanonicalName(), 1L); throw new IOException(e); } }
/** * Determines the input and output types of the Function and initializes the superclass. * Subclass and call this constructor if a Function with a non-default constructor is required. * @param function Function to be used by the UDF. */ protected FunctionWrapperEvalFunc(ExceptionalFunction function) throws IOException, ClassNotFoundException, NoSuchMethodException { super(getFunctionInClass(function), getFunctionOutClass(function)); this.function = function; String functionName = (function instanceof GoogleFunctionBridge) ? ((GoogleFunctionBridge)function).getWrappedFunction().getClass().getSimpleName() : function.getClass().getSimpleName(); this.counterGroup = getClass().getName() + ":" + functionName; }
private static Class getFunctionOutClass(ExceptionalFunction functionClassName) throws ClassNotFoundException, NoSuchMethodException, IOException { return getFunctionTypeClass(functionClassName, 1); }