use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class JoinOperatorTest method getTupleWindow.
private TupleWindow getTupleWindow() {
TopologyAPI.StreamId leftComponentStreamId = TopologyAPI.StreamId.newBuilder().setComponentName("leftComponent").setId("s1").build();
TopologyAPI.StreamId rightComponentStreamId = TopologyAPI.StreamId.newBuilder().setComponentName("rightComponent").setId("s1").build();
List<Tuple> tuples = new LinkedList<>();
for (int i = 0; i < 5; i++) {
Tuple tuple;
if (i % 2 == 0) {
tuple = getTuple(leftComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key1", String.valueOf(i))));
} else {
tuple = getTuple(rightComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key1", String.valueOf(i))));
}
tuples.add(tuple);
}
for (int i = 5; i < 8; i++) {
Tuple tuple = getTuple(leftComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key2", String.valueOf(i))));
tuples.add(tuple);
}
for (int i = 8; i < 12; i++) {
Tuple tuple = getTuple(rightComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key3", String.valueOf(i))));
tuples.add(tuple);
}
TupleWindow tupleWindow = new TupleWindowImpl(tuples, new LinkedList<>(), new LinkedList<>(), startTime, endTime);
return tupleWindow;
}
use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class ReduceByKeyAndWindowOperatorTest method getTupleWindow.
private TupleWindow getTupleWindow(int nkeys, int count) {
TopologyAPI.StreamId componentStreamId = TopologyAPI.StreamId.newBuilder().setComponentName("sourceComponent").setId("default").build();
List<Tuple> tuples = new LinkedList<>();
for (int i = 0; i < nkeys; i++) {
for (int j = 0; j < count; ++j) {
Tuple tuple = getTuple(componentStreamId, new Fields("a"), new Values(String.valueOf(i)));
tuples.add(tuple);
}
}
TupleWindow tupleWindow = new TupleWindowImpl(tuples, new LinkedList<>(), new LinkedList<>(), startTime, endTime);
return tupleWindow;
}
use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class KeyByOperator method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
R obj = (R) tuple.getValue(0);
K key = keyExtractor.apply(obj);
V value = valueExtractor.apply(obj);
collector.emit(new Values(new KeyValue<>(key, value)));
collector.ack(tuple);
}
use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class ReduceByKeyAndWindowOperator method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(TupleWindow inputWindow) {
Map<K, T> reduceMap = new HashMap<>();
Map<K, Integer> windowCountMap = new HashMap<>();
for (Tuple tuple : inputWindow.get()) {
R tup = (R) tuple.getValue(0);
addMap(reduceMap, windowCountMap, tup);
}
long startWindow;
long endWindow;
if (inputWindow.getStartTimestamp() == null) {
startWindow = 0;
} else {
startWindow = inputWindow.getStartTimestamp();
}
if (inputWindow.getEndTimestamp() == null) {
endWindow = 0;
} else {
endWindow = inputWindow.getEndTimestamp();
}
for (K key : reduceMap.keySet()) {
Window window = new Window(startWindow, endWindow, windowCountMap.get(key));
KeyedWindow<K> keyedWindow = new KeyedWindow<>(key, window);
collector.emit(new Values(new KeyValue<>(keyedWindow, reduceMap.get(key))));
}
}
use of org.apache.heron.api.tuple.Values in project heron by twitter.
the class FilterOperator method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
R obj = (R) tuple.getValue(0);
if (filterFn.test(obj)) {
collector.emit(new Values(obj));
}
collector.ack(tuple);
}
Aggregations