Using C or Java support functions
About this task
When you use C or Java™ to write routines for the support functions, you must consider the treatment of null values. Unless the HANDLESNULLS modifier is present, rows with null values in the column that is aggregated do not contribute to the aggregate computation. If the iteration function, ITER, uses HANDLESNULLS, all of the support functions must be declared to handle null values. The initialization function, INIT, must always be able to handle null values.
User-defined aggregates are strongly typed. That is, the database server uses the state type information from the support functions to ensure that values are well typed and that their memory is properly managed. With caution, you might be able to use the generic user-defined type pointer to avoid creating a new state type.
To create a user-defined aggregate:
Procedure
- Write the functions that support the aggregate.
- Register the support function with the CREATE FUNCTION statement.
- Register the aggregate with the CREATE AGGREGATE statement.
Results
After you register the aggregate, you can use the aggregate in an SQL statement.
For more information about registering a function, refer to Registering a user-defined routine. For the syntax of the CREATE FUNCTION and CREATE aggregate statements, see the HCL OneDB™ Guide to SQL: Syntax.