Creating an aggregation
This article shows an example of creating a function to calculate the harmonic mean of a sequence in INTELIE Pipes.
The aggregation
To create the aggregation, the interface SimpleAggregation
should be implemented.
The implementation contains the state and the intermediate representation of the aggregation.
The method marked with @Export
is exposed as a Pipes function. Its body updates the state of the aggregation.
The eval()
method provides the result of the calculation from its state.
The merge()
method allows combining many states into one. This is used mainly by aggregation windows, to combine partial results produced inside it, but it can also be used to run Pipes' aggregations in a distributed system. Note that this means the aggregation should ideally be an associative operation.
The unmerge
method, defined by the SimpleAggregation.Full
class, can be implemented as an optimization for sliding windows intermediate representation calculation, if the aggregation function is invertible. Otherwise, Pipes uses a unoptimized 2-stack-based algorithm to calculate sliding windows, which may use more resources.
Testing
Pipes provides some tools that help unit testing. An easy way is to validate the results after some state flips.
Last updated