Search in sources :

Example 6 with Values

use of org.apache.heron.api.tuple.Values 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))));
    }
}
Also used : Window(org.apache.heron.streamlet.Window) KeyedWindow(org.apache.heron.streamlet.KeyedWindow) TupleWindow(org.apache.heron.api.windowing.TupleWindow) KeyValue(org.apache.heron.streamlet.KeyValue) HashMap(java.util.HashMap) KeyedWindow(org.apache.heron.streamlet.KeyedWindow) Values(org.apache.heron.api.tuple.Values) Tuple(org.apache.heron.api.tuple.Tuple)

Example 7 with Values

use of org.apache.heron.api.tuple.Values in project heron by twitter.

the class MapOperator method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
    R obj = (R) tuple.getValue(0);
    T result = mapFn.apply(obj);
    collector.emit(new Values(result));
    collector.ack(tuple);
}
Also used : Values(org.apache.heron.api.tuple.Values)

Example 8 with Values

use of org.apache.heron.api.tuple.Values in project heron by twitter.

the class WindowedBoltExecutorTest method testExecuteWithTs.

@Test
public void testExecuteWithTs() throws Exception {
    long[] timestamps = { 603, 605, 607, 618, 626, 636 };
    for (long ts : timestamps) {
        executor.execute(getTuple("s1", new Fields("ts"), new Values(ts)));
    }
    // Thread.sleep(120);
    executor.waterMarkEventGenerator.run();
    // System.out.println(testWindowedBolt.tupleWindows);
    assertEquals(3, testWindowedBolt.tupleWindows.size());
    TupleWindow first = testWindowedBolt.tupleWindows.get(0);
    assertArrayEquals(new long[] { 603, 605, 607 }, new long[] { (long) first.get().get(0).getValue(0), (long) first.get().get(1).getValue(0), (long) first.get().get(2).getValue(0) });
    TupleWindow second = testWindowedBolt.tupleWindows.get(1);
    assertArrayEquals(new long[] { 603, 605, 607, 618 }, new long[] { (long) second.get().get(0).getValue(0), (long) second.get().get(1).getValue(0), (long) second.get().get(2).getValue(0), (long) second.get().get(3).getValue(0) });
    TupleWindow third = testWindowedBolt.tupleWindows.get(2);
    assertArrayEquals(new long[] { 618, 626 }, new long[] { (long) third.get().get(0).getValue(0), (long) third.get().get(1).getValue(0) });
}
Also used : Fields(org.apache.heron.api.tuple.Fields) Values(org.apache.heron.api.tuple.Values) TupleWindow(org.apache.heron.api.windowing.TupleWindow) Test(org.junit.Test)

Example 9 with Values

use of org.apache.heron.api.tuple.Values in project heron by twitter.

the class GeneralReduceByKeyOperator method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
    R obj = (R) tuple.getValue(0);
    K key = keyExtractor.apply(obj);
    T oldValue = reduceMap.getOrDefault(key, identity);
    T newValue = reduceFn.apply(oldValue, obj);
    reduceMap.put(key, newValue);
    collector.emit(new Values(new KeyValue<K, T>(key, newValue)));
    collector.ack(tuple);
}
Also used : KeyValue(org.apache.heron.streamlet.KeyValue) Values(org.apache.heron.api.tuple.Values)

Example 10 with Values

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);
}
Also used : KeyValue(org.apache.heron.streamlet.KeyValue) Values(org.apache.heron.api.tuple.Values)

Aggregations

Values (org.apache.heron.api.tuple.Values)37 Tuple (org.apache.heron.api.tuple.Tuple)8 KeyValue (org.apache.heron.streamlet.KeyValue)7 TupleWindow (org.apache.heron.api.windowing.TupleWindow)6 Fields (org.apache.heron.api.tuple.Fields)5 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)3 TupleWindowImpl (org.apache.heron.api.windowing.TupleWindowImpl)3 KeyedWindow (org.apache.heron.streamlet.KeyedWindow)2 Window (org.apache.heron.streamlet.Window)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 TopologyContext (org.apache.heron.api.topology.TopologyContext)1 SerializablePredicate (org.apache.heron.streamlet.SerializablePredicate)1