Creating a UDAF written in R

This section uses examples to illustrate how to create, on a Db2® system, a user-defined aggregate function (UDAF) written in R.

In an R UDAF, the following functions must be defined in the input source file:
  • nz.init
  • nz.accum
  • nz.merge
  • nz.final
These functions are called at runtime in subsequent steps. They should use the same API function as functions and table functions to access the data.[!!! don't understand. "functions and table functions"?]

In R, standard functions can be used to access input, output, and state data. [!!! should we say what they are?] Two additional functions, which can be called only in aggregation mode [!!! by a UDAF?] are getState and getOutputColumn.

The input, output, and state have the following meaning in the defined states: [!!!odd phrasing. what is this trying to say?]
Processing state Input API Output API Description
Initialize None State There is no input. The output API is used to set the initial state values.
Accumulate Input State The input API accesses the input data from the input table, while the output API controls the state variables.
Merge State Merge state For each invocation of this function, another set of state variables is accessible on the input coming from the nodes or data slices that process data, while the output API controls the merge state variables.
Finalize Merge state Output The merge state variables are accessible from the input API. The output API controls the UDA output, which is then reported as the result of the SQL query.