Interface for user-defined aggregate functions

2023-07-28 02:53:17  Updated

User-defined aggregate functions are implemented through a set of ODCIAggregate routines. You can use these routines as methods in an object type and use the CREATE FUNCTION statement to create an aggregate function.

Applicability

This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only MySQL mode.

The current version of OceanBase Database supports the following ODCIAggregate routines:

  • ODCIAggregateInitialize()

  • ODCIAggregateIterate()

  • ODCIAggregateMerge()

  • ODCIAggregateTerminate()

ODCIAggregateInitialize()

ODCIAggregateInitialize() initializes the aggregation context and instance of the implementation object type, and returns the result 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 and OUT For regular aggregation cases, this value is NULL. In window aggregation, actx is the context of the previous window. This object instance is passed in to the next aggregation routine as a parameter.

Return values

ODCIConst.Success is returned upon a success, and ODCIConst.Error is returned upon an error.

ODCIAggregateIterate()

ODCIAggregateIterate() traverses input rows to process and update the input values, and then returns the aggregation 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 and OUT The value of the current aggregation context in an input scenario, or the updated value in an output scenario.
val IN The input value being aggregated.

Return values

ODCIConst.Success is returned upon a success, and ODCIConst.Error is returned upon an error.

ODCIAggregateMerge()

For serial or parallel user-defined aggregate computation, ODCIAggregateMerge() merges two aggregation 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 and OUT The value of the first aggregation context in an input scenario, and the resulting value of the two merged aggregation contexts in an output scenario.
ctx2 IN The value of the second aggregation context.

Return values

ODCIConst.Success is returned upon a success, and ODCIConst.Error is returned upon an error.

ODCIAggregateTerminate()

ODCIAggregateTerminate() performs the aggregate computation and necessary cleanup work, such as releasing the 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 aggregation context.
ctx2 OUT The aggregation result.
flags IN A bit vector that represents various options. The setting of ODCI_AGGREGATE_REUSE_CTX indicates that the context will be reused and no external context should be released.

Return values

ODCIConst.Success is returned upon a success, and ODCIConst.Error is returned upon an error.

Contact Us