Search in sources :

Example 1 with CombinerValueUpdater

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

the class CombinerAggStateUpdater method updateState.

@Override
public void updateState(Snapshottable state, List<TridentTuple> tuples, TridentCollector collector) {
    if (tuples.size() != 1) {
        throw new IllegalArgumentException("Combiner state updater should receive a single tuple. Received: " + tuples.toString());
    }
    Object newVal = state.update(new CombinerValueUpdater(_agg, tuples.get(0).getValue(0)));
    collector.emit(new Values(newVal));
}
Also used : Values(org.apache.storm.tuple.Values) CombinerValueUpdater(org.apache.storm.trident.state.CombinerValueUpdater)

Example 2 with CombinerValueUpdater

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

Example 3 with CombinerValueUpdater

use of org.apache.storm.trident.state.CombinerValueUpdater 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);
    }
}
Also used : ValueUpdater(org.apache.storm.trident.state.ValueUpdater) CombinerValueUpdater(org.apache.storm.trident.state.CombinerValueUpdater) CombinerValueUpdater(org.apache.storm.trident.state.CombinerValueUpdater)

Aggregations

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