Write the aggregate support functions

An aggregate support function is a special-purpose user-defined function that implements some task in the aggregate algorithm. You write aggregate support functions to initialize, calculate, and return the aggregate result to the calling code.

An aggregate algorithm can include the following kinds of aggregate support functions.
Aggregate support function Algorithm step
INIT Possible initialization tasks that must be performed before the iterations can begin
ITER An iteration step, which is performed on each aggregate argument and merges this argument into a partial result
COMBINE Merging one partial result with another partial result, thus allowing parallel execution of the user-defined aggregate
FINAL Post-iteration tasks that must be performed after all aggregate arguments were merged into a partial result