User-defined aggregate functions are implemented by a set of ODCIAggregate routines. These routines can be methods of an object type and can be created using the CREATE FUNCTION statement.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only MySQL-compatible mode.
The following ODCIAggregate routines are supported in the current version of OceanBase Database:
ODCIAggregateInitialize()ODCIAggregateIterate()ODCIAggregateMerge()ODCIAggregateTerminate()
ODCIAggregateInitialize()
ODCIAggregateInitialize() is used to initialize the aggregate context and the instance of the object type, and returns it as an OUT parameter. It is a static method.
Syntax
STATIC FUNCTION ODCIAggregateInitialize(
actx IN OUT <impltype>)
RETURN NUMBER
Parameters
| Parameter | In/Out | Description |
|---|---|---|
| actx | IN OUT | For regular aggregation, this value is NULL. In window aggregation, actx is the context of the previous window. This object instance is passed as a parameter to the next aggregation routine. |
Return value
ODCIConst.Success if the operation is successful, ODCIConst.Error otherwise.
ODCIAggregateIterate()
ODCIAggregateIterate() is used to iterate through the input rows to process the input values and update, and then return the aggregate context. It is a mandatory routine and is implemented as a member method.
Syntax
MEMBER FUNCTION ODCIAggregateIterate(
self IN OUT <impltype>,
val <inputdatatype>)
RETURN NUMBER
Parameters
| Parameter | In/Out | Description |
|---|---|---|
| self | IN OUT | When used as input, it is the value of the current aggregate context; when used as output, it is the updated value. |
| val | IN | The input value being aggregated. |
Return value
ODCIConst.Success if the operation is successful, ODCIConst.Error otherwise.
ODCIAggregateMerge()
During serial or parallel computation of user-defined aggregation, ODCIAggregateMerge() is used to merge two aggregate contexts into a single object instance. It is a mandatory routine and is implemented as a member method.
Syntax
MEMBER FUNCTION ODCIAggregateMerge(
self IN OUT <impltype>,
ctx2 IN <impltype>)
RETURN NUMBER
Parameters
| Parameter | In/Out | Description |
|---|---|---|
| self | IN OUT | When used as input, it is the value of the first aggregate context; when used as output, it is the result value of the two merged aggregate contexts. |
| ctx2 | IN | The value of the second aggregate context. |
Return value
ODCIConst.Success if the operation is successful, ODCIConst.Error otherwise.
ODCIAggregateTerminate()
ODCIAggregateTerminate() is used to calculate the aggregate result and perform necessary cleanup, such as memory release. It is a mandatory routine and is implemented as a member method.
Syntax
MEMBER FUNCTION ODCIAggregateTerminate(
self IN <impltype>,
ReturnValue OUT <return_type>,
flags IN number)
RETURN NUMBER
Parameters
| Parameter | In/Out | Description |
|---|---|---|
| self | IN | The value of the aggregate context. |
| ctx2 | OUT | The value of the aggregate result. |
| flags | IN | A bit vector indicating various options. If ODCI_AGGREGATE_REUSE_CTX is set, it indicates that the context will be reused and no external context should be released. |
Return value
ODCIConst.Success if the operation is successful, ODCIConst.Error otherwise.