Writing UDAFs

A UDAF must maintain a state value across subsequent calls in order to accumulate a result across a set of calls, instead of deriving it purely from one set of arguments.

The underlying functions represent a UDAF:
Initialization function
Sets counters to zero, creates empty buffers, and performs any other initial setup for a query.
Update function
Processes the arguments for each row in the result set and accumulates an intermediate result for each node.
Merge function
Combines the intermediate results from different nodes.
Finalize function
Passes through the combined result unchanged, or does one final transformation.