SUM, AVG, MAX…) are natively converted to the remote database equivalent aggregations.
However, if you write some custom aggregation functions (UDAF) you will also need to define how this aggregation is done in your remote database.
Sum product example
This example is based on a ClickHouse database and SQL but can easily be ported to other databases. For instance let’s consider a simple sum product on scalar values, which in SQL would beSUM(quantity * price).
Here is a simple implementation with Copper:
To build this SQL UDAF you need:
- the Atoti UDAF key
- the number of inputs of the SQL expressions (i.e. the number of SQL columns to read)
- the SQL expression(s) resolving the aggregation function results(s)
- the aggregation function(s) results types
- the re-aggregation function if needed
You must provide as much aggregation results as needed in your registered Copper terminate function.
| DATE | My Sum Product |
|---|---|
| 2022-02-03 | 580.0 |
| 2022-01-31 | 798.0 |
| 2022-02-04 | 258.0 |
| 2022-02-01 | 1030.0 |
| 2022-02-02 | 604.0 |
Re-aggregable UDAF
For some features like aggregate table with user defined function a reaggregable UDAF is a plus.An aggregation function is re-aggregable if a function, capable of merging two aggregation results into one, exists. For instance, the sum product aggregation can be re-aggregated by the
SUM aggregation function in the example above.