use of org.apache.heron.streamlet.KeyedWindow in project heron by twitter.
the class JoinOperatorTest method testOuterLeftJoinOperator.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testOuterLeftJoinOperator() {
JoinOperator<String, KeyValue<String, String>, KeyValue<String, String>, String> joinOperator = getJoinOperator(JoinType.OUTER_LEFT);
TupleWindow tupleWindow = getTupleWindow();
Set<String> expectedResultsK1 = new HashSet<>();
expectedResultsK1.add("01");
expectedResultsK1.add("03");
expectedResultsK1.add("21");
expectedResultsK1.add("23");
expectedResultsK1.add("41");
expectedResultsK1.add("43");
Set<String> expectedResultsK2 = new HashSet<>();
expectedResultsK2.add("5null");
expectedResultsK2.add("6null");
expectedResultsK2.add("7null");
joinOperator.execute(tupleWindow);
Assert.assertEquals(9, emittedTuples.size());
for (Object object : emittedTuples) {
KeyValue<KeyedWindow<String>, String> tuple = (KeyValue<KeyedWindow<String>, String>) object;
KeyedWindow<String> keyedWindow = tuple.getKey();
switch(keyedWindow.getKey()) {
case "key1":
Assert.assertTrue(expectedResultsK1.contains(tuple.getValue()));
expectedResultsK1.remove(tuple.getValue());
break;
case "key2":
Assert.assertTrue(expectedResultsK2.contains(tuple.getValue()));
expectedResultsK2.remove(tuple.getValue());
break;
default:
Assert.fail();
}
Assert.assertEquals(12, keyedWindow.getWindow().getCount());
Assert.assertEquals(startTime, keyedWindow.getWindow().getStartTime());
Assert.assertEquals(endTime, keyedWindow.getWindow().getEndTime());
}
Assert.assertEquals(0, expectedResultsK1.size());
Assert.assertEquals(0, expectedResultsK2.size());
}
use of org.apache.heron.streamlet.KeyedWindow in project heron by twitter.
the class GeneralReduceByKeyAndWindowOperator 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.streamlet.KeyedWindow in project heron by twitter.
the class JoinOperator method getKeyedWindow.
private KeyedWindow<K> getKeyedWindow(K key, TupleWindow tupleWindow) {
long startWindow;
long endWindow;
if (tupleWindow.getStartTimestamp() == null) {
startWindow = 0;
} else {
startWindow = tupleWindow.getStartTimestamp();
}
if (tupleWindow.getEndTimestamp() == null) {
endWindow = 0;
} else {
endWindow = tupleWindow.getEndTimestamp();
}
Window window = new Window(startWindow, endWindow, tupleWindow.get().size());
return new KeyedWindow<>(key, window);
}
use of org.apache.heron.streamlet.KeyedWindow 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.streamlet.KeyedWindow in project heron by twitter.
the class GeneralReduceByKeyAndWindowOperatorTest method testReduceByWindowOperator.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testReduceByWindowOperator() {
GeneralReduceByKeyAndWindowOperator<KeyValue<String, Integer>, String, Integer> reduceOperator = getReduceByWindowOperator(12);
TupleWindow tupleWindow = getTupleWindow(3, 5);
HashMap<String, Integer> expectedResults = new HashMap<>();
expectedResults.put("0", 22);
expectedResults.put("1", 22);
expectedResults.put("2", 22);
reduceOperator.execute(tupleWindow);
Assert.assertEquals(3, emittedTuples.size());
for (Object object : emittedTuples) {
KeyValue<KeyedWindow<String>, Integer> tuple = (KeyValue<KeyedWindow<String>, Integer>) object;
KeyedWindow<String> window = tuple.getKey();
String key = window.getKey();
Assert.assertEquals(5, window.getWindow().getCount());
Assert.assertEquals(startTime, window.getWindow().getStartTime());
Assert.assertEquals(endTime, window.getWindow().getEndTime());
Assert.assertEquals(expectedResults.get(key), tuple.getValue());
}
}
Aggregations