Search in sources :

Example 1 with ReducerValueUpdater

use of org.apache.storm.trident.state.ReducerValueUpdater in project storm by apache.

the class MapReducerAggStateUpdater method updateState.

@Override
public void updateState(MapState map, List<TridentTuple> tuples, TridentCollector collector) {
    Map<List<Object>, List<TridentTuple>> grouped = new HashMap<>();
    for (TridentTuple t : tuples) {
        List<Object> group = _groupFactory.create(t);
        List<TridentTuple> groupTuples = grouped.get(group);
        if (groupTuples == null) {
            groupTuples = new ArrayList<>();
            grouped.put(group, groupTuples);
        }
        groupTuples.add(_inputFactory.create(t));
    }
    List<List<Object>> uniqueGroups = new ArrayList<>(grouped.keySet());
    List<ValueUpdater> updaters = new ArrayList<>(uniqueGroups.size());
    for (List<Object> group : uniqueGroups) {
        updaters.add(new ReducerValueUpdater(_agg, grouped.get(group)));
    }
    List<Object> results = map.multiUpdate(uniqueGroups, updaters);
    for (int i = 0; i < uniqueGroups.size(); i++) {
        List<Object> group = uniqueGroups.get(i);
        Object result = results.get(i);
        collector.emit(_factory.create(new List[] { group, new Values(result) }));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) ReducerValueUpdater(org.apache.storm.trident.state.ReducerValueUpdater) ValueUpdater(org.apache.storm.trident.state.ValueUpdater) ReducerValueUpdater(org.apache.storm.trident.state.ReducerValueUpdater) ArrayList(java.util.ArrayList) ComboList(org.apache.storm.trident.tuple.ComboList) List(java.util.List) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Example 2 with ReducerValueUpdater

use of org.apache.storm.trident.state.ReducerValueUpdater in project storm by apache.

the class ReducerAggStateUpdater method updateState.

@Override
public void updateState(Snapshottable state, List<TridentTuple> tuples, TridentCollector collector) {
    Object newVal = state.update(new ReducerValueUpdater(_agg, tuples));
    collector.emit(new Values(newVal));
}
Also used : Values(org.apache.storm.tuple.Values) ReducerValueUpdater(org.apache.storm.trident.state.ReducerValueUpdater)

Aggregations

ReducerValueUpdater (org.apache.storm.trident.state.ReducerValueUpdater)2 Values (org.apache.storm.tuple.Values)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ValueUpdater (org.apache.storm.trident.state.ValueUpdater)1 ComboList (org.apache.storm.trident.tuple.ComboList)1 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)1