pyflink.table.udf.udf#
- udf(f: Optional[Union[Callable, pyflink.table.udf.ScalarFunction, Type]] = None, input_types: Optional[Union[List[pyflink.table.types.DataType], pyflink.table.types.DataType, str, List[str]]] = None, result_type: Optional[Union[pyflink.table.types.DataType, str]] = None, deterministic: Optional[bool] = None, name: Optional[str] = None, func_type: str = 'general') Union[pyflink.table.udf.UserDefinedScalarFunctionWrapper, Callable] [source]#
Helper method for creating a user-defined function.
- Example:
>>> add_one = udf(lambda i: i + 1, DataTypes.BIGINT(), DataTypes.BIGINT()) >>> # The input_types is optional. >>> @udf(result_type=DataTypes.BIGINT()) ... def add(i, j): ... return i + j >>> # Specify result_type via string. >>> @udf(result_type='BIGINT') ... def add(i, j): ... return i + j >>> class SubtractOne(ScalarFunction): ... def eval(self, i): ... return i - 1 >>> subtract_one = udf(SubtractOne(), DataTypes.BIGINT(), DataTypes.BIGINT())
- Parameters
f – lambda function or user-defined function.
input_types – optional, the input data types.
result_type – the result data type.
deterministic – the determinism of the function’s results. True if and only if a call to this function is guaranteed to always return the same result given the same parameters. (default True)
name – the function name.
func_type – the type of the python function, available value: general, pandas, (default: general)
udf_type – the type of the python function, available value: general, pandas, (default: general)
- Returns
UserDefinedScalarFunctionWrapper or function.
New in version 1.10.0.