class UserDefinedFunctionHelper {

	@SuppressWarnings({"unchecked", "rawtypes"})
	public static UserDefinedFunction instantiateFunction(
			ClassLoader classLoader,
			@Nullable ReadableConfig config,
			String name,
			CatalogFunction catalogFunction) {
		try {
			switch (catalogFunction.getFunctionLanguage()) {
				case PYTHON:
					if (config == null) {
						throw new IllegalStateException("Python functions are not supported at this location.");
					}
					return (UserDefinedFunction) PythonFunctionUtils.getPythonFunction(
						catalogFunction.getClassName(),
						config);
				case JAVA:
				case SCALA:
					final Class<?> functionClass = classLoader.loadClass(catalogFunction.getClassName());
					return UserDefinedFunctionHelper.instantiateFunction((Class) functionClass);
				default:
					throw new IllegalArgumentException(
						"Unknown function language: " + catalogFunction.getFunctionLanguage());
			}
		} catch (Exception e) {
			throw new ValidationException(
				String.format("Cannot instantiate user-defined function '%s'.", name),
				e);
		}
	}

	private  UserDefinedFunctionHelper();

}