Create aggregates
An aggregate is a function that returns information about a set of query results. For example, the SUM aggregate adds all the query results together and returns the result. An aggregate is invoked in SQL as a single function but is implemented as one or more support functions. You can use BladeSmith to create user-defined aggregates that implement user-defined routines.
You can define two aggregates that have the same name but operate on different data types. An aggregate acts as a template: the aggregate support functions must have the same names for both aggregates. If you overload an aggregate, you cannot add, remove, or change the names of its support functions. Use your new object prefix to begin the name of your aggregate to avoid accidentally overloading an aggregate in another DataBlade module.
Property | Default value | Description |
---|---|---|
Aggregate name | Aggregate | The name of the aggregate function. If you are
overloading an aggregate, the name can be the name of an existing
aggregate; otherwise, the name must be unique. New aggregate names
must begin with the new object prefix. See Aggregate name for more information. |
Language | C | Which language to use for the aggregate functions:
C or Java™. You must set server compatibility to 9.2 or later to generate code for Java projects. You need J/Foundation to enable Java services. |
Iteration type | None | The data type on which the aggregate function operates. See Iteration type for restrictions. |
Initialization parameter | No | Optional. Used only for aggregates whose behavior
can be changed dynamically. See Initialization parameter for more information. |
Return type | None | The data type of the result of the aggregate function. |
State type | None | The data type of the intermediate aggregation state.
The state type is often POINTER. See State type for more information. |
Initialization function | AggregateInit | The function called before the aggregation begins.
Not required if the state and iteration data types are the same and
there is no initialization parameter. See Initialization function for more information. |
Iteration function | AggregateIter | Called once for every value that is aggregated.
By default, this function accepts null values. See Iteration function for more information. |
Combine function | AggregateComb | Optional. Merges results from parallel iterations. See Combine function for more information. |
Final function | AggregateFinl | Performs computations on the combined state, cleans
up memory, and returns the final value. See Final function for more information. |
For information about how aggregates behave, see the HCL OneDB DataBlade API Programmer's Guide.