Search in sources :

Example 1 with KeyedWindow

use of com.twitter.heron.streamlet.KeyedWindow in project incubator-heron by apache.

the class JoinOperatorTest method testOuterRightJoinOperator.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testOuterRightJoinOperator() {
    JoinOperator<String, KeyValue<String, String>, KeyValue<String, String>, String> joinOperator = getJoinOperator(JoinType.OUTER_RIGHT);
    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("null8");
    expectedResultsK2.add("null9");
    expectedResultsK2.add("null10");
    expectedResultsK2.add("null11");
    joinOperator.execute(tupleWindow);
    Assert.assertEquals(10, 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;
            case "key3":
                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());
}
Also used : KeyValue(com.twitter.heron.streamlet.KeyValue) KeyedWindow(com.twitter.heron.streamlet.KeyedWindow) TupleWindow(com.twitter.heron.api.windowing.TupleWindow) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with KeyedWindow

use of com.twitter.heron.streamlet.KeyedWindow in project incubator-heron by apache.

the class JoinOperatorTest method testInnerJoinOperator.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testInnerJoinOperator() {
    JoinOperator<String, KeyValue<String, String>, KeyValue<String, String>, String> joinOperator = getJoinOperator(JoinType.INNER);
    TupleWindow tupleWindow = getTupleWindow();
    Set<String> expectedResults = new HashSet<>();
    expectedResults.add("01");
    expectedResults.add("03");
    expectedResults.add("21");
    expectedResults.add("23");
    expectedResults.add("41");
    expectedResults.add("43");
    joinOperator.execute(tupleWindow);
    Assert.assertEquals(2 * 3, emittedTuples.size());
    for (Object object : emittedTuples) {
        KeyValue<KeyedWindow<String>, String> tuple = (KeyValue<KeyedWindow<String>, String>) object;
        KeyedWindow<String> keyedWindow = tuple.getKey();
        Assert.assertEquals("key1", keyedWindow.getKey());
        Assert.assertEquals(12, keyedWindow.getWindow().getCount());
        Assert.assertEquals(startTime, keyedWindow.getWindow().getStartTime());
        Assert.assertEquals(endTime, keyedWindow.getWindow().getEndTime());
        Assert.assertTrue(expectedResults.contains(tuple.getValue()));
        expectedResults.remove(tuple.getValue());
    }
    Assert.assertEquals(0, expectedResults.size());
}
Also used : KeyValue(com.twitter.heron.streamlet.KeyValue) KeyedWindow(com.twitter.heron.streamlet.KeyedWindow) TupleWindow(com.twitter.heron.api.windowing.TupleWindow) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with KeyedWindow

use of com.twitter.heron.streamlet.KeyedWindow in project incubator-heron by apache.

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);
}
Also used : KeyedWindow(com.twitter.heron.streamlet.KeyedWindow) Window(com.twitter.heron.streamlet.Window) TupleWindow(com.twitter.heron.api.windowing.TupleWindow) KeyedWindow(com.twitter.heron.streamlet.KeyedWindow)

Example 4 with KeyedWindow

use of com.twitter.heron.streamlet.KeyedWindow in project incubator-heron by apache.

the class GeneralReduceByKeyAndWindowOperatorTest method testReduceByWindowOperator.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testReduceByWindowOperator() {
    GeneralReduceByKeyAndWindowOperator<String, KeyValue<String, Integer>, 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());
    }
}
Also used : KeyValue(com.twitter.heron.streamlet.KeyValue) HashMap(java.util.HashMap) KeyedWindow(com.twitter.heron.streamlet.KeyedWindow) TupleWindow(com.twitter.heron.api.windowing.TupleWindow) Test(org.junit.Test)

Example 5 with KeyedWindow

use of com.twitter.heron.streamlet.KeyedWindow in project incubator-heron by apache.

the class ReduceByKeyAndWindowOperatorTest method testReduceByWindowOperator.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testReduceByWindowOperator() {
    ReduceByKeyAndWindowOperator<String, Integer, String> reduceOperator = getReduceByWindowOperator();
    TupleWindow tupleWindow = getTupleWindow(3, 5);
    HashMap<String, Integer> expectedResults = new HashMap<>();
    expectedResults.put("0", 5);
    expectedResults.put("1", 5);
    expectedResults.put("2", 5);
    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());
    }
}
Also used : KeyValue(com.twitter.heron.streamlet.KeyValue) HashMap(java.util.HashMap) KeyedWindow(com.twitter.heron.streamlet.KeyedWindow) TupleWindow(com.twitter.heron.api.windowing.TupleWindow) Test(org.junit.Test)

Aggregations

TupleWindow (com.twitter.heron.api.windowing.TupleWindow)9 KeyedWindow (com.twitter.heron.streamlet.KeyedWindow)9 KeyValue (com.twitter.heron.streamlet.KeyValue)8 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Window (com.twitter.heron.streamlet.Window)3 Tuple (com.twitter.heron.api.tuple.Tuple)2 Values (com.twitter.heron.api.tuple.Values)2