OceanBase Database supports user-defined aggregate functions for processing complex data.
OceanBase Database supports predefined aggregate functions, such as MAX, MIN, and SUM, for performing operations on multiple rows. You can use these predefined aggregate functions only to process scalar data rather than complex data, such as multimedia data, data of the opaque type, and ``LOBs. To solve this problem, you can define aggregate functions as needed.
Just like built-in aggregate functions, user-defined aggregate functions can be used in SQL DML statements. The functions can also be used with scalar data.
User-defined aggregate functions are an extended feature. You can use a set of ODCIAggregate interface routines to create a user-defined aggregate function.
Each user-defined aggregate function uses up to four ODCIAggregate routines or steps, respectively for initialization, iteration, merging, and termination.
The
ODCIAggregateInitialize()routine implements initialization. OceanBase Database calls this routine to initialize user-defined aggregate computation and returns the initialized aggregation context as an object type instance.The
ODCIAggregateIterate()routine performs iteration. This routine can be repeatedly called. Each time the routine is called, a new value or a set of new values and the current aggregation context are passed in. The routine then processes the passed-in new values and returns the updated aggregation context.NULLvalues are ignored during aggregation and will not be passed to the routine.The
ODCIAggregateMerge()routine performs merging. This routine can be called to merge two aggregation contexts. It takes the two contexts as inputs, merges them, and returns the resulting single aggregation context.The
ODCIAggregateTerminate()routine terminates the aggregation. This routine takes the aggregation context as input and returns the aggregation result.