use of storm.trident.tuple.TridentTuple in project storm by nathanmarz.
the class GroupedAggregator method aggregate.
@Override
public void aggregate(Object[] arr, TridentTuple tuple, TridentCollector collector) {
GroupCollector groupColl = (GroupCollector) arr[0];
Map<List, Object> val = (Map) arr[1];
TridentTuple group = _groupFactory.create((TridentTupleView) tuple);
TridentTuple input = _inputFactory.create((TridentTupleView) tuple);
Object curr;
if (!val.containsKey(group)) {
curr = _agg.init(arr[2], groupColl);
val.put((List) group, curr);
} else {
curr = val.get(group);
}
groupColl.currGroup = group;
_agg.aggregate(curr, input, groupColl);
}
use of storm.trident.tuple.TridentTuple in project storm by nathanmarz.
the class GroupedMultiReducerExecutor method execute.
@Override
public void execute(Map<TridentTuple, Object> state, int streamIndex, TridentTuple full, TridentCollector collector) {
ProjectionFactory groupFactory = _groupFactories.get(streamIndex);
ProjectionFactory inputFactory = _inputFactories.get(streamIndex);
TridentTuple group = groupFactory.create(full);
TridentTuple input = inputFactory.create(full);
Object curr;
if (!state.containsKey(group)) {
curr = _reducer.init(collector, group);
state.put(group, curr);
} else {
curr = state.get(group);
}
_reducer.execute(curr, streamIndex, group, input, collector);
}
use of storm.trident.tuple.TridentTuple in project storm by nathanmarz.
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 storm.trident.tuple.TridentTuple in project jstorm by alibaba.
the class StateQueryProcessor method finishBatch.
@Override
public void finishBatch(ProcessorContext processorContext) {
BatchState state = (BatchState) processorContext.state[_context.getStateIndex()];
if (!state.tuples.isEmpty()) {
List<Object> results = _function.batchRetrieve(_state, Collections.unmodifiableList(state.args));
if (results.size() != state.tuples.size()) {
throw new RuntimeException("Results size is different than argument size: " + results.size() + " vs " + state.tuples.size());
}
for (int i = 0; i < state.tuples.size(); i++) {
TridentTuple tuple = state.tuples.get(i);
Object result = results.get(i);
_collector.setContext(processorContext, tuple);
_function.execute(state.args.get(i), result, _collector);
}
}
}
use of storm.trident.tuple.TridentTuple in project jstorm by alibaba.
the class GroupedMultiReducerExecutor method execute.
@Override
public void execute(Map<TridentTuple, Object> state, int streamIndex, TridentTuple full, TridentCollector collector) {
ProjectionFactory groupFactory = _groupFactories.get(streamIndex);
ProjectionFactory inputFactory = _inputFactories.get(streamIndex);
TridentTuple group = groupFactory.create(full);
TridentTuple input = inputFactory.create(full);
Object curr;
if (!state.containsKey(group)) {
curr = _reducer.init(collector, group);
state.put(group, curr);
} else {
curr = state.get(group);
}
_reducer.execute(curr, streamIndex, group, input, collector);
}
Aggregations