use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class ReduceByKeyOperator method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
R obj = (R) tuple.getValue(0);
K key = keyExtractor.apply(obj);
T value = valueExtractor.apply(obj);
T newValue;
if (reduceMap.containsKey(key)) {
newValue = reduceFn.apply(reduceMap.get(key), value);
} else {
newValue = value;
}
reduceMap.put(key, newValue);
collector.emit(new Values(new KeyValue<K, T>(key, newValue)));
collector.ack(tuple);
}
use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class SplitOperator method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
R obj = (R) tuple.getValue(0);
for (Map.Entry<String, SerializablePredicate<R>> entry : splitFns.entrySet()) {
if (entry.getValue().test(obj)) {
collector.emit(entry.getKey(), new Values(obj));
}
}
collector.ack(tuple);
}
use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class UnionOperator method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
I obj = (I) tuple.getValue(0);
collector.emit(new Values(obj));
collector.ack(tuple);
}
use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class FlatMapOperator method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
R obj = (R) tuple.getValue(0);
Iterable<? extends T> result = flatMapFn.apply(obj);
for (T o : result) {
collector.emit(new Values(o));
}
collector.ack(tuple);
}
use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class SlidingWindowSumBolt method execute.
@Override
public void execute(TupleWindow inputWindow) {
/*
* The inputWindow gives a view of
* (a) all the events in the window
* (b) events that expired since last activation of the window
* (c) events that newly arrived since last activation of the window
*/
List<Tuple> tuplesInWindow = inputWindow.get();
List<Tuple> newTuples = inputWindow.getNew();
List<Tuple> expiredTuples = inputWindow.getExpired();
LOG.fine("Events in current window: " + tuplesInWindow.size());
/*
* Instead of iterating over all the tuples in the window to compute
* the sum, the values for the new events are added and old events are
* subtracted. Similar optimizations might be possible in other
* windowing computations.
*/
for (Tuple tuple : newTuples) {
sum += (int) tuple.getValue(0);
}
for (Tuple tuple : expiredTuples) {
sum -= (int) tuple.getValue(0);
}
collector.emit(new Values(sum));
}
Aggregations