The CREATE AGGREGATE
command can be used to create user-defined aggregate functions (UDAFs). Currently, UDAFs are only supported in Python and JavaScript as embedded UDFs.
IF NOT EXISTS
.Parameter or clause | Description |
---|---|
function_name | The name of the aggregate function that you want to declare in RisingWave. |
argument_type | The data type of the input parameter(s) that the function expects to receive. |
RETURNS return_type | The data type of the return value from the aggregate function. |
LANGUAGE | The programming language used to implement the UDAF. Currently, Python and JavaScript are supported. |
AS function_body | The source code of the UDAF. |
create_state() -> state
: Create a new state.accumulate(state, *args) -> state
: Accumulate a new value into the state, returning the updated state.finish(state) -> value
: Get the result of the aggregate function. If not defined, the state is returned as the result.retract(state, *args) -> state
: Retract a value from the state, returning the updated state. If not defined, the state can not be updated incrementally in materialized views and performance may be affected.weighted_avg
to calculate the weighted average.
weighted_avg
to calculate the weighted average.