Package org.apache.flink.table.functions
Class UserDefinedFunctionHelper
java.lang.Object
org.apache.flink.table.functions.UserDefinedFunctionHelper
Utility for dealing with subclasses of
UserDefinedFunction. The purpose of this class is
to keep the user-facing APIs clean and offer methods/constants from here.
It contains methods for instantiating, validating and extracting types during function registration in a catalog.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic UserDefinedFunctioncreateSpecializedFunction(String functionName, FunctionDefinition definition, CallContext callContext, ClassLoader builtInClassLoader, org.apache.flink.configuration.ReadableConfig configuration, SpecializedFunction.ExpressionEvaluatorFactory evaluatorFactory) Creates the runtime implementation of aFunctionDefinitionas an instance ofUserDefinedFunction.static StringName for anonymous, inline functions.static <T,ACC> org.apache.flink.api.common.typeinfo.TypeInformation<ACC> getAccumulatorTypeOfAggregateFunction(ImperativeAggregateFunction<T, ACC> aggregateFunction) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static <T,ACC> org.apache.flink.api.common.typeinfo.TypeInformation<ACC> getAccumulatorTypeOfAggregateFunction(ImperativeAggregateFunction<T, ACC> aggregateFunction, org.apache.flink.api.common.typeinfo.TypeInformation<ACC> scalaType) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static <T,ACC> org.apache.flink.api.common.typeinfo.TypeInformation<T> getReturnTypeOfAggregateFunction(ImperativeAggregateFunction<T, ACC> aggregateFunction) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static <T,ACC> org.apache.flink.api.common.typeinfo.TypeInformation<T> getReturnTypeOfAggregateFunction(ImperativeAggregateFunction<T, ACC> aggregateFunction, org.apache.flink.api.common.typeinfo.TypeInformation<T> scalaType) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static <T> org.apache.flink.api.common.typeinfo.TypeInformation<T>getReturnTypeOfTableFunction(TableFunction<T> tableFunction) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static <T> org.apache.flink.api.common.typeinfo.TypeInformation<T>getReturnTypeOfTableFunction(TableFunction<T> tableFunction, org.apache.flink.api.common.typeinfo.TypeInformation<T> scalaType) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static UserDefinedFunctioninstantiateFunction(Class<?> functionClass) Instantiates aUserDefinedFunctionassuming a JVM function with default constructor.static UserDefinedFunctioninstantiateFunction(ClassLoader classLoader, org.apache.flink.configuration.ReadableConfig config, String name, CatalogFunction catalogFunction) Instantiates aUserDefinedFunctionfrom aCatalogFunction.static booleanisClassNameSerializable(UserDefinedFunction function) Returns whether aUserDefinedFunctioncan be easily serialized and identified by only a fully qualified class name.static voidprepareInstance(org.apache.flink.configuration.ReadableConfig config, UserDefinedFunction function) Prepares aUserDefinedFunctioninstance for usage in the API.static voidvalidateClass(Class<? extends UserDefinedFunction> functionClass) Validates aUserDefinedFunctionclass for usage in the API.static voidvalidateClassForRuntime(Class<? extends UserDefinedFunction> functionClass, String methodName, Class<?>[] argumentClasses, Class<?> outputClass, String functionName) Validates aUserDefinedFunctionclass for usage in the runtime.
-
Field Details
-
SCALAR_EVAL
- See Also:
-
ASYNC_SCALAR_EVAL
- See Also:
-
TABLE_EVAL
- See Also:
-
AGGREGATE_ACCUMULATE
- See Also:
-
AGGREGATE_RETRACT
- See Also:
-
AGGREGATE_MERGE
- See Also:
-
TABLE_AGGREGATE_ACCUMULATE
- See Also:
-
TABLE_AGGREGATE_RETRACT
- See Also:
-
TABLE_AGGREGATE_MERGE
- See Also:
-
TABLE_AGGREGATE_EMIT
- See Also:
-
TABLE_AGGREGATE_EMIT_RETRACT
- See Also:
-
ASYNC_TABLE_EVAL
- See Also:
-
PROCESS_TABLE_EVAL
- See Also:
-
-
Method Details
-
getReturnTypeOfAggregateFunction
public static <T,ACC> org.apache.flink.api.common.typeinfo.TypeInformation<T> getReturnTypeOfAggregateFunction(ImperativeAggregateFunction<T, ACC> aggregateFunction) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.- Parameters:
aggregateFunction- The AggregateFunction for which the accumulator type is inferred.- Returns:
- The inferred accumulator type of the AggregateFunction.
-
getReturnTypeOfAggregateFunction
public static <T,ACC> org.apache.flink.api.common.typeinfo.TypeInformation<T> getReturnTypeOfAggregateFunction(ImperativeAggregateFunction<T, ACC> aggregateFunction, org.apache.flink.api.common.typeinfo.TypeInformation<T> scalaType) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.- Parameters:
aggregateFunction- The AggregateFunction for which the accumulator type is inferred.scalaType- The implicitly inferred type of the accumulator type.- Returns:
- The inferred accumulator type of the AggregateFunction.
-
getAccumulatorTypeOfAggregateFunction
public static <T,ACC> org.apache.flink.api.common.typeinfo.TypeInformation<ACC> getAccumulatorTypeOfAggregateFunction(ImperativeAggregateFunction<T, ACC> aggregateFunction) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.- Parameters:
aggregateFunction- The AggregateFunction for which the accumulator type is inferred.- Returns:
- The inferred accumulator type of the AggregateFunction.
-
getAccumulatorTypeOfAggregateFunction
public static <T,ACC> org.apache.flink.api.common.typeinfo.TypeInformation<ACC> getAccumulatorTypeOfAggregateFunction(ImperativeAggregateFunction<T, ACC> aggregateFunction, org.apache.flink.api.common.typeinfo.TypeInformation<ACC> scalaType) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.- Parameters:
aggregateFunction- The AggregateFunction for which the accumulator type is inferred.scalaType- The implicitly inferred type of the accumulator type.- Returns:
- The inferred accumulator type of the AggregateFunction.
-
getReturnTypeOfTableFunction
public static <T> org.apache.flink.api.common.typeinfo.TypeInformation<T> getReturnTypeOfTableFunction(TableFunction<T> tableFunction) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.- Parameters:
tableFunction- The TableFunction for which the accumulator type is inferred.- Returns:
- The inferred accumulator type of the AggregateFunction.
-
getReturnTypeOfTableFunction
public static <T> org.apache.flink.api.common.typeinfo.TypeInformation<T> getReturnTypeOfTableFunction(TableFunction<T> tableFunction, org.apache.flink.api.common.typeinfo.TypeInformation<T> scalaType) Tries to infer the TypeInformation of an AggregateFunction's accumulator type.- Parameters:
tableFunction- The TableFunction for which the accumulator type is inferred.scalaType- The implicitly inferred type of the accumulator type.- Returns:
- The inferred accumulator type of the AggregateFunction.
-
instantiateFunction
public static UserDefinedFunction instantiateFunction(ClassLoader classLoader, @Nullable org.apache.flink.configuration.ReadableConfig config, String name, CatalogFunction catalogFunction) Instantiates aUserDefinedFunctionfrom aCatalogFunction.Requires access to
ReadableConfigif Python functions should be supported. -
instantiateFunction
Instantiates aUserDefinedFunctionassuming a JVM function with default constructor. -
prepareInstance
public static void prepareInstance(org.apache.flink.configuration.ReadableConfig config, UserDefinedFunction function) Prepares aUserDefinedFunctioninstance for usage in the API. -
isClassNameSerializable
Returns whether aUserDefinedFunctioncan be easily serialized and identified by only a fully qualified class name. It must have a default constructor and no serializable fields.Other properties (such as checks for abstract classes) are validated at the entry points of the API, see
prepareInstance(ReadableConfig, UserDefinedFunction). -
generateInlineFunctionName
Name for anonymous, inline functions. -
validateClass
Validates aUserDefinedFunctionclass for usage in the API.Note: This is an initial validation to indicate common errors early. The concrete signature validation happens in the code generation when the actual
DataTypes for arguments and result are known. -
validateClassForRuntime
public static void validateClassForRuntime(Class<? extends UserDefinedFunction> functionClass, String methodName, Class<?>[] argumentClasses, Class<?> outputClass, String functionName) Validates aUserDefinedFunctionclass for usage in the runtime.Note: This is for the final validation when actual
DataTypes for arguments and result are known. -
createSpecializedFunction
public static UserDefinedFunction createSpecializedFunction(String functionName, FunctionDefinition definition, CallContext callContext, ClassLoader builtInClassLoader, @Nullable org.apache.flink.configuration.ReadableConfig configuration, @Nullable SpecializedFunction.ExpressionEvaluatorFactory evaluatorFactory) Creates the runtime implementation of aFunctionDefinitionas an instance ofUserDefinedFunction.- See Also:
-