Custom Aggregate Operators

Creating custom aggregate operators is a bit more complicated than custom window strategies, but not by much.

Group operators are actually two classes working together com.northconcepts.datapipeline.group.GroupOperation and com.northconcepts.datapipeline.group.GroupOperationField. Think of GroupOperation (sum, min, max, avg) as the factory a for creating instantiates of GroupOperationField for each field in each window.

For example, when you code groupByReader.sum("price").sum("qty");, each open window uses the sum GroupOperation (called GroupSum) to create two instances of GroupOperationField. One for each field the window needs to sum.

From there on, each GroupOperationField receives every record passing through its window while the window is open (GroupOperationField.apply(Record, Field)).

When the window closes, each GroupOperationField emits its summary data when GroupOperationField.getValue() is called.

With that explanation, here's how the sum operator is implemented.

Mobile Analytics