This statement creates a custom function. Executing this command requires the user to have privileges.
If function_name
contains the database name, then the custom function will be created in the corresponding database, otherwise the function will be created in the database where the current session is located. The name and parameters of the new function cannot be the same as the existing functions in the current namespace, otherwise the creation will fail. But only with the same name and different parameters can be created successfully.
grammar:
Parameter Description:
AGGREGATE
: If there is this item, it means that the created function is an aggregate function.ALIAS
: If there is this item, it means that the created function is an alias function.
If the above two items are absent, it means that the created function is a scalar function
function_name
: The name of the function to be created, which can include the name of the database. For example:db1.my_func
.arg_type
: The parameter type of the function, which is the same as the type defined when creating the table. Variable-length parameters can be represented by, ...
. If it is a variable-length type, the type of the variable-length parameter is the same as that of the last non-variable-length parameter.ret_type
: Required for creating new functions. If you are aliasing an existing function, you do not need to fill in this parameter.inter_type
: The data type used to represent the intermediate stage of the aggregation function.param
: used to represent the parameter of the alias function, including at least one.: used to represent the original function corresponding to the alias function.
Create a custom scalar function
"symbol" = "_ZN9doris_udf6AddUdfEPNS_15FunctionContextERKNS_6IntValES4_",
);
Create a custom scalar function with prepare/close functions
Create a custom aggregate function
CREATE AGGREGATE FUNCTION my_count (BIGINT) RETURNS BIGINT PROPERTIES (
"init_fn"="_ZN9doris_udf9CountInitEPNS_15FunctionContextEPNS_9BigIntValE",
"update_fn"="_ZN9doris_udf11CountUpdateEPNS_15FunctionContextERKNS_6IntValEPNS_9BigIntValE",
"merge_fn"="_ZN9doris_udf10CountMergeEPNS_15FunctionContextERKNS_9BigIntValEPS2_",
"finalize_fn"="_ZN9doris_udf13CountFinalizeEPNS_15FunctionContextERKNS_9BigIntValE",
"object_file"="http://host:port/libudasample.so"
);
Create a scalar function with variable length arguments
-
CREATE ALIAS FUNCTION id_masking(INT) WITH PARAMETER(id) AS CONCAT(LEFT(id, 3), '****', RIGHT(id, 4));