Package org.apache.flink.table.functions
Class UserDefinedFunctionHelper
- java.lang.Object
-
- org.apache.flink.table.functions.UserDefinedFunctionHelper
-
@Internal public final class UserDefinedFunctionHelper extends Object
Utility for dealing with subclasses ofUserDefinedFunction
. 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 Modifier and Type Field Description static String
AGGREGATE_ACCUMULATE
static String
AGGREGATE_MERGE
static String
AGGREGATE_RETRACT
static String
ASYNC_SCALAR_EVAL
static String
ASYNC_TABLE_EVAL
static String
SCALAR_EVAL
static String
TABLE_AGGREGATE_ACCUMULATE
static String
TABLE_AGGREGATE_EMIT
static String
TABLE_AGGREGATE_EMIT_RETRACT
static String
TABLE_AGGREGATE_MERGE
static String
TABLE_AGGREGATE_RETRACT
static String
TABLE_EVAL
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static UserDefinedFunction
createSpecializedFunction(String functionName, FunctionDefinition definition, CallContext callContext, ClassLoader builtInClassLoader, ReadableConfig configuration, SpecializedFunction.ExpressionEvaluatorFactory evaluatorFactory)
Creates the runtime implementation of aFunctionDefinition
as an instance ofUserDefinedFunction
.static String
generateInlineFunctionName(UserDefinedFunction function)
Name for anonymous, inline functions.static <T,ACC>
TypeInformation<ACC>getAccumulatorTypeOfAggregateFunction(ImperativeAggregateFunction<T,ACC> aggregateFunction)
Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static <T,ACC>
TypeInformation<ACC>getAccumulatorTypeOfAggregateFunction(ImperativeAggregateFunction<T,ACC> aggregateFunction, TypeInformation<ACC> scalaType)
Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static <T,ACC>
TypeInformation<T>getReturnTypeOfAggregateFunction(ImperativeAggregateFunction<T,ACC> aggregateFunction)
Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static <T,ACC>
TypeInformation<T>getReturnTypeOfAggregateFunction(ImperativeAggregateFunction<T,ACC> aggregateFunction, TypeInformation<T> scalaType)
Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static <T> TypeInformation<T>
getReturnTypeOfTableFunction(TableFunction<T> tableFunction)
Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static <T> TypeInformation<T>
getReturnTypeOfTableFunction(TableFunction<T> tableFunction, TypeInformation<T> scalaType)
Tries to infer the TypeInformation of an AggregateFunction's accumulator type.static UserDefinedFunction
instantiateFunction(Class<?> functionClass)
Instantiates aUserDefinedFunction
assuming a JVM function with default constructor.static UserDefinedFunction
instantiateFunction(ClassLoader classLoader, ReadableConfig config, String name, CatalogFunction catalogFunction)
Instantiates aUserDefinedFunction
from aCatalogFunction
.static boolean
isClassNameSerializable(UserDefinedFunction function)
Returns whether aUserDefinedFunction
can be easily serialized and identified by only a fully qualified class name.static void
prepareInstance(ReadableConfig config, UserDefinedFunction function)
Prepares aUserDefinedFunction
instance for usage in the API.static void
validateClass(Class<? extends UserDefinedFunction> functionClass)
Validates aUserDefinedFunction
class for usage in the API.static void
validateClassForRuntime(Class<? extends UserDefinedFunction> functionClass, String methodName, Class<?>[] argumentClasses, Class<?> outputClass, String functionName)
Validates aUserDefinedFunction
class for usage in the runtime.
-
-
-
Field Detail
-
SCALAR_EVAL
public static final String SCALAR_EVAL
- See Also:
- Constant Field Values
-
ASYNC_SCALAR_EVAL
public static final String ASYNC_SCALAR_EVAL
- See Also:
- Constant Field Values
-
TABLE_EVAL
public static final String TABLE_EVAL
- See Also:
- Constant Field Values
-
AGGREGATE_ACCUMULATE
public static final String AGGREGATE_ACCUMULATE
- See Also:
- Constant Field Values
-
AGGREGATE_RETRACT
public static final String AGGREGATE_RETRACT
- See Also:
- Constant Field Values
-
AGGREGATE_MERGE
public static final String AGGREGATE_MERGE
- See Also:
- Constant Field Values
-
TABLE_AGGREGATE_ACCUMULATE
public static final String TABLE_AGGREGATE_ACCUMULATE
- See Also:
- Constant Field Values
-
TABLE_AGGREGATE_RETRACT
public static final String TABLE_AGGREGATE_RETRACT
- See Also:
- Constant Field Values
-
TABLE_AGGREGATE_MERGE
public static final String TABLE_AGGREGATE_MERGE
- See Also:
- Constant Field Values
-
TABLE_AGGREGATE_EMIT
public static final String TABLE_AGGREGATE_EMIT
- See Also:
- Constant Field Values
-
TABLE_AGGREGATE_EMIT_RETRACT
public static final String TABLE_AGGREGATE_EMIT_RETRACT
- See Also:
- Constant Field Values
-
ASYNC_TABLE_EVAL
public static final String ASYNC_TABLE_EVAL
- See Also:
- Constant Field Values
-
-
Method Detail
-
getReturnTypeOfAggregateFunction
public static <T,ACC> 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> TypeInformation<T> getReturnTypeOfAggregateFunction(ImperativeAggregateFunction<T,ACC> aggregateFunction, 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> 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> TypeInformation<ACC> getAccumulatorTypeOfAggregateFunction(ImperativeAggregateFunction<T,ACC> aggregateFunction, 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> 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> TypeInformation<T> getReturnTypeOfTableFunction(TableFunction<T> tableFunction, 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 ReadableConfig config, String name, CatalogFunction catalogFunction)
Instantiates aUserDefinedFunction
from aCatalogFunction
.Requires access to
ReadableConfig
if Python functions should be supported.
-
instantiateFunction
public static UserDefinedFunction instantiateFunction(Class<?> functionClass)
Instantiates aUserDefinedFunction
assuming a JVM function with default constructor.
-
prepareInstance
public static void prepareInstance(ReadableConfig config, UserDefinedFunction function)
Prepares aUserDefinedFunction
instance for usage in the API.
-
isClassNameSerializable
public static boolean isClassNameSerializable(UserDefinedFunction function)
Returns whether aUserDefinedFunction
can 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
public static String generateInlineFunctionName(UserDefinedFunction function)
Name for anonymous, inline functions.
-
validateClass
public static void validateClass(Class<? extends UserDefinedFunction> functionClass)
Validates aUserDefinedFunction
class 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
DataType
s for arguments and result are known.
-
validateClassForRuntime
public static void validateClassForRuntime(Class<? extends UserDefinedFunction> functionClass, String methodName, Class<?>[] argumentClasses, Class<?> outputClass, String functionName)
Validates aUserDefinedFunction
class for usage in the runtime.Note: This is for the final validation when actual
DataType
s for arguments and result are known.
-
createSpecializedFunction
public static UserDefinedFunction createSpecializedFunction(String functionName, FunctionDefinition definition, CallContext callContext, ClassLoader builtInClassLoader, @Nullable ReadableConfig configuration, @Nullable SpecializedFunction.ExpressionEvaluatorFactory evaluatorFactory)
Creates the runtime implementation of aFunctionDefinition
as an instance ofUserDefinedFunction
.- See Also:
SpecializedFunction
-
-