use of org.apache.storm.trident.state.ValueUpdater 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) }));
}
}
use of org.apache.storm.trident.state.ValueUpdater in project storm by apache.
the class MapCombinerAggStateUpdater method updateState.
@Override
public void updateState(MapState map, List<TridentTuple> tuples, TridentCollector collector) {
List<List<Object>> groups = new ArrayList<List<Object>>(tuples.size());
List<ValueUpdater> updaters = new ArrayList<ValueUpdater>(tuples.size());
for (TridentTuple t : tuples) {
groups.add(_groupFactory.create(t));
updaters.add(new CombinerValueUpdater(_agg, _inputFactory.create(t).getValue(0)));
}
List<Object> newVals = map.multiUpdate(groups, updaters);
for (int i = 0; i < tuples.size(); i++) {
List<Object> key = groups.get(i);
Object result = newVals.get(i);
collector.emit(_factory.create(new List[] { key, new Values(result) }));
}
}
use of org.apache.storm.trident.state.ValueUpdater in project storm by apache.
the class DebugMemoryMapState method print.
private void print(List<List<Object>> keys, List<ValueUpdater> updaters) {
for (int i = 0; i < keys.size(); i++) {
ValueUpdater valueUpdater = updaters.get(i);
Object arg = ((CombinerValueUpdater) valueUpdater).getArg();
LOG.info("updateCount = {}, keys = {} => updaterArgs = {}", updateCount, keys.get(i), arg);
}
}
Aggregations