Search in sources :

Example 16 with TridentTuple

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);
}
Also used : List(java.util.List) ComboList(storm.trident.tuple.ComboList) Map(java.util.Map) HashMap(java.util.HashMap) TridentTuple(storm.trident.tuple.TridentTuple)

Example 17 with TridentTuple

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);
}
Also used : ProjectionFactory(storm.trident.tuple.TridentTupleView.ProjectionFactory) TridentTuple(storm.trident.tuple.TridentTuple)

Example 18 with TridentTuple

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) }));
    }
}
Also used : CombinerValueUpdater(storm.trident.state.CombinerValueUpdater) ValueUpdater(storm.trident.state.ValueUpdater) ArrayList(java.util.ArrayList) Values(backtype.storm.tuple.Values) CombinerValueUpdater(storm.trident.state.CombinerValueUpdater) ArrayList(java.util.ArrayList) List(java.util.List) ComboList(storm.trident.tuple.ComboList) TridentTuple(storm.trident.tuple.TridentTuple)

Example 19 with TridentTuple

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);
        }
    }
}
Also used : TridentTuple(storm.trident.tuple.TridentTuple)

Example 20 with TridentTuple

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);
}
Also used : ProjectionFactory(storm.trident.tuple.TridentTupleView.ProjectionFactory) TridentTuple(storm.trident.tuple.TridentTuple)

Aggregations

TridentTuple (storm.trident.tuple.TridentTuple)25 ArrayList (java.util.ArrayList)10 List (java.util.List)8 Values (backtype.storm.tuple.Values)6 HashMap (java.util.HashMap)6 ComboList (storm.trident.tuple.ComboList)6 Map (java.util.Map)4 ValueUpdater (storm.trident.state.ValueUpdater)4 FailedException (backtype.storm.topology.FailedException)2 Fields (backtype.storm.tuple.Fields)2 TridentTopology (storm.trident.TridentTopology)2 Consumer (storm.trident.operation.Consumer)2 CombinerValueUpdater (storm.trident.state.CombinerValueUpdater)2 ReducerValueUpdater (storm.trident.state.ReducerValueUpdater)2 FixedBatchSpout (storm.trident.testing.FixedBatchSpout)2 ProjectionFactory (storm.trident.tuple.TridentTupleView.ProjectionFactory)2 HashSet (java.util.HashSet)1 IllegalClassException (org.apache.commons.lang.IllegalClassException)1 Put (org.apache.hadoop.hbase.client.Put)1 ElasticSearchException (org.elasticsearch.ElasticSearchException)1