XAP.NET Custom Aggregators


With many systems such as pricing systems, risk management, trading and other analytic and business intelligence applications you may need to perform an aggregation activity across data stored within the data grid when generating reports or when running some business process. Such activity can leverage data stored in memory and will be much faster than performing it with a database.

aggreg.jpg

This best practice demonstrate how to calculate Min, Max, Avg and Sum for objects stored within the space. There is no need to retrieve the entire data set from the space to the client side , iterate the result set and perform the aggregation. This would be an expensive activity as it might return a large amount of data into the client application.

Custom Aggregators allows you to perform the entire aggregation activity at the space side avoiding any data retrieval back to the client side. Only the result of each aggregation activity performed with each partition is returned back to the client side where all the results are reduced and returned to the client application. Such aggregation activity utilizes the partitioned nature of the data-grid allowing each partition to execute the aggregation with its local data in parallel, where all the partitions intermediate results are fully aggregated at the client side using the relevant reducer implementation.

Pre-defined Aggregators

The following pre-defined aggregators are available:

Task Description
AverageTask An average operation to be performed on a specific partition in the space.
MaximumTask A maximum aggregation operation to be performed on a specific partition in the space.
MininimumTask A minimum aggregation operation to be performed on a specific partition in the space.
SumSpacePropertyTask A sum performed on a space property in a specific partition in the space.
SumSpaceObjectTask A sum performed on a space object in a specific partition in the space.

The following pre-defined distributed aggregators are available:

Task Description
AverageReducer An average operation to be performed on the space.
MaximumReducer A maximum aggregation operation to be performed on the space.
MinimumReducer A minimum aggregation operation to be performed on the space.
SumSpacePropertyReducer A sum performed on a space property in the space.
SumSpaceObjectReducer A sum performed on a space object in the space.

Example

Below is an example using the AverageReducer to find the average salary of all employees in the space.

ISpaceProxy spaceProxy = ...;
IDistributedSpaceTask<long,long> averageTask = new AverageReducer<Employee, int>(t => t.Salary);
var averageSalary = spaceProxy.Execute(averageTask);
[SpaceClass]
public class Employee {
    [SpaceID(AutoGenerate=false)
    public int Id { get; set; }
    
    public int Salary {get;set; }
}