A user-defined aggregate function is implemented by a set of ODCIAggregate routines. These routines can be methods of an object type and can be created by using the CREATE FUNCTION statement.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
The following ODCIAggregate routines are supported in the current version of OceanBase Database:
ODCIAggregateInitialize()ODCIAggregateIterate()ODCIAggregateMerge()ODCIAggregateTerminate()
ODCIAggregateInitialize()
The ODCIAggregateInitialize() routine initializes the aggregate context and the instance of the object type, and returns the instance 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. The object instance is passed as a parameter to the next aggregate routine. |
Return value
ODCIConst.Success if the routine succeeds, or ODCIConst.Error if an error occurs.
ODCIAggregateIterate()
The ODCIAggregateIterate() routine traverses the input rows to process the input values and update the aggregate context, and returns 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 | As an input, it is the value of the current aggregate context; as an output, it is the updated value. |
| val | IN | The input value to be aggregated. |
Return value
ODCIConst.Success if the routine succeeds, or ODCIConst.Error if an error occurs.
ODCIAggregateMerge()
During serial or parallel computation of a user-defined aggregate, the ODCIAggregateMerge() routine merges 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 | As an input, it is the value of the first aggregate context; as an output, it is the result of merging the two aggregate contexts. |
| ctx2 | IN | The value of the second aggregate context. |
Return value
ODCIConst.Success if the routine succeeds, or ODCIConst.Error if an error occurs.
ODCIAggregateTerminate()
The ODCIAggregateTerminate() routine calculates the aggregate result and performs necessary cleanup, such as releasing memory. 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 that indicates 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 routine succeeds, or ODCIConst.Error if an error occurs.
