Search in sources :

Example 1 with IntegerSumCombinerFactory

use of mapreduce.combiner.IntegerSumCombinerFactory in project microservices by pwillhan.

the class MapReduceCountryCityPopulation method main.

public static void main(String[] args) throws Exception {
    Config conf = new Config();
    HazelcastInstance hz = Hazelcast.newHazelcastInstance(conf);
    IMap<CityKey, City> cities = hz.getMap("cities");
    if (cities.isEmpty()) {
        cities.put(new CityKey("London", "GB"), new City("London", "GB", 8416535, 1572));
        cities.put(new CityKey("Southampton", "GB"), new City("Southampton", "GB", 242100, 51));
        cities.put(new CityKey("Chicago", "US"), new City("Chicago", "US", 2718782, 606));
        cities.put(new CityKey("Washington DC", "US"), new City("Washington DC", "US", 658893, 177));
        cities.put(new CityKey("Seattle", "US"), new City("Seattle", "US", 652405, 370));
    }
    JobTracker jobTracker = hz.getJobTracker("default");
    KeyValueSource<CityKey, City> sourceData = KeyValueSource.fromMap(cities);
    Job<CityKey, City> job = jobTracker.newJob(sourceData);
    JobCompletableFuture<Map<String, Integer>> future = job.mapper(new CountryCityPopulationMapper()).combiner(new IntegerSumCombinerFactory()).reducer(new IntegerSumReducerFactory()).submit();
    Map<String, Integer> result = future.get();
    System.err.println(result);
}
Also used : Config(com.hazelcast.config.Config) IntegerSumCombinerFactory(mapreduce.combiner.IntegerSumCombinerFactory) City(data.City) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IntegerSumReducerFactory(mapreduce.reducer.IntegerSumReducerFactory) CountryCityPopulationMapper(mapreduce.mapper.CountryCityPopulationMapper) CityKey(data.CityKey) IMap(com.hazelcast.core.IMap) Map(java.util.Map)

Aggregations

Config (com.hazelcast.config.Config)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 IMap (com.hazelcast.core.IMap)1 City (data.City)1 CityKey (data.CityKey)1 Map (java.util.Map)1 IntegerSumCombinerFactory (mapreduce.combiner.IntegerSumCombinerFactory)1 CountryCityPopulationMapper (mapreduce.mapper.CountryCityPopulationMapper)1 IntegerSumReducerFactory (mapreduce.reducer.IntegerSumReducerFactory)1