com.hazelcast.mapreduce.aggregation
Interface Aggregation<Key,Supplied,Result>

Type Parameters:
Key - the input key type
Supplied - the value type returned from the Supplier
Result - the value type returned from the aggregation

@Beta
public interface Aggregation<Key,Supplied,Result>

The Aggregation interface combines multiple map-reduce operations steps to a single operation definition. It is a predefined set of Mapper, Combiner, Reducer and probably a Collator to execute an aggregation over a supplied set of data.

As you'll see in the following example the Aggregations API is fully type-safe. Do to the lack of full type inference support on Java 6 and Java 7 it seems more verbose than it actually is.

 IMap<String, Employee> map = hazelcastInstance.getMap("employees");
 Supplier<String, Employee, Integer> supplier = Supplier.all((employee) -> employee.getSalaryPerMonth());
 Aggregation<String, Integer, Integer> aggregation = Aggregations.integerAvg();
 int avgSalary = map.aggregate(supplier, aggregation);
 
With Java 8 it is possible to write that all in just one line so that the API becomes very straight forward.
 IMap<String, Employee> map = hazelcastInstance.getMap("employees");
 int avgSalary = map.aggregate(Supplier.all((employee) -> employee.getSalaryPerMonth(), Aggregations.integerAvg());
 

Since:
3.3

Method Summary
 Collator<Map.Entry,Result> getCollator()
          Returns a Collator implementation used in this aggregation
 CombinerFactory getCombinerFactory()
          Returns the CombinerFactory for this aggregation to pre-reduce values on mapping nodes.
 Mapper getMapper(Supplier<Key,?,Supplied> supplier)
          Returns the Mapper for this aggregation.
 ReducerFactory getReducerFactory()
          Returns the ReducerFactory for this aggregation.
 

Method Detail

getCollator

Collator<Map.Entry,Result> getCollator()
Returns a Collator implementation used in this aggregation

Returns:
the aggregation defined Collator

getMapper

Mapper getMapper(Supplier<Key,?,Supplied> supplier)
Returns the Mapper for this aggregation. The Mapper implementation has to handle the Supplier to filter / transform values before emitting them to the further aggregation steps.

Parameters:
supplier - the Supplier to filter or / and transform values
Returns:
the aggregation defined Mapper

getCombinerFactory

CombinerFactory getCombinerFactory()
Returns the CombinerFactory for this aggregation to pre-reduce values on mapping nodes. Returning a CombinerFactory preserves traffic costs but implementing a Combiner is not always possible.

Returns:
the aggregation defined CombinerFactory or null

getReducerFactory

ReducerFactory getReducerFactory()
Returns the ReducerFactory for this aggregation. If a CombinerFactory is defined the implemented Reducer has to handle values of the returned type of the Combiner.

Returns:
the aggregation defined ReducerFactory


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.