Search in sources :

Example 1 with SpecializedContext

use of org.apache.flink.table.functions.SpecializedFunction.SpecializedContext in project flink by apache.

the class UserDefinedFunctionHelper method createSpecializedFunction.

/**
 * Creates the runtime implementation of a {@link FunctionDefinition} as an instance of {@link
 * UserDefinedFunction}.
 *
 * @see SpecializedFunction
 */
public static UserDefinedFunction createSpecializedFunction(String functionName, FunctionDefinition definition, CallContext callContext, ClassLoader builtInClassLoader, @Nullable ReadableConfig configuration) {
    if (definition instanceof SpecializedFunction) {
        final SpecializedFunction specialized = (SpecializedFunction) definition;
        final SpecializedContext specializedContext = new SpecializedContext() {

            @Override
            public CallContext getCallContext() {
                return callContext;
            }

            @Override
            public ReadableConfig getConfiguration() {
                if (configuration == null) {
                    throw new TableException("Access to configuration is currently not supported for all kinds of calls.");
                }
                return configuration;
            }

            @Override
            public ClassLoader getBuiltInClassLoader() {
                return builtInClassLoader;
            }
        };
        final UserDefinedFunction udf = specialized.specialize(specializedContext);
        checkState(udf.getKind() == definition.getKind(), "Function kind must not change during specialization.");
        return udf;
    } else if (definition instanceof UserDefinedFunction) {
        return (UserDefinedFunction) definition;
    } else {
        throw new TableException(String.format("Could not find a runtime implementation for function definition '%s'.", functionName));
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) SpecializedContext(org.apache.flink.table.functions.SpecializedFunction.SpecializedContext)

Aggregations

TableException (org.apache.flink.table.api.TableException)1 SpecializedContext (org.apache.flink.table.functions.SpecializedFunction.SpecializedContext)1