Aggregates

If you created a user-defined aggregate with the Aggregate wizard, BladeSmith generates aggregate methods in the ProjectUDRs.java source code file.

The generated code

BladeSmith only generates templates for aggregate methods.

The generated method declares the method, its return type, and arguments.

Complete the code

To complete the code for aggregate methods, you must:
  • Add your declarations, if necessary.
  • Remove the call to Log(), which raises an error stating that the routine is not implemented.
  • Compute the return value and store it in the Gen_RetVal argument.

For more information about programming aggregate methods, see HCL® J/Foundation Developer's Guide.

The initialization method
If you selected an initialization method, AggregateInit(), you must add code to it to initialize the state type required by the aggregate computation. The AggregateInit() method returns the state type.

The first argument of the AggregateInit() method is a dummy argument whose value is always NULL. The second argument is an optional initialization parameter to customize aggregate computation. The initialization parameter cannot be a lone host variable reference.

The iteration method
You must add code to the iteration method, AggregateIter(), to perform the aggregate computations.
Tip: Although the iteration method is called by the database server multiple times to calculate the aggregation, it is not implemented as an iterator method that returns a set of results.
The combine method
If you selected a combine method, AggregateComb(), you must add code to it to merge one partial result with another and return the updated state type.
The final function
If you selected a final method, AggregateFinl(), you must add code to convert the state type to the result type.

You can also add code to the AggregateFinl() method to release resources acquired by the initialization method. However, the AggregateFinl() method must not free the state type.