Search in sources :

Example 1 with IntegerAvgReducerFactory

use of mapreduce.reducer.IntegerAvgReducerFactory in project microservices by pwillhan.

the class MapReduceCountryCityDensity 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 CountryCityDensityMapper()).reducer(new IntegerAvgReducerFactory()).submit();
    Map<String, Integer> result = future.get();
    System.err.println(result);
}
Also used : Config(com.hazelcast.config.Config) JobTracker(com.hazelcast.mapreduce.JobTracker) IntegerAvgReducerFactory(mapreduce.reducer.IntegerAvgReducerFactory) City(data.City) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CityKey(data.CityKey) IMap(com.hazelcast.core.IMap) Map(java.util.Map) CountryCityDensityMapper(mapreduce.mapper.CountryCityDensityMapper)

Aggregations

Config (com.hazelcast.config.Config)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 IMap (com.hazelcast.core.IMap)1 JobTracker (com.hazelcast.mapreduce.JobTracker)1 City (data.City)1 CityKey (data.CityKey)1 Map (java.util.Map)1 CountryCityDensityMapper (mapreduce.mapper.CountryCityDensityMapper)1 IntegerAvgReducerFactory (mapreduce.reducer.IntegerAvgReducerFactory)1