Search in sources :

Example 26 with Values

use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.

the class ReduceByKeyAndWindowOperator method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(TupleWindow inputWindow) {
    Map<K, V> 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 : KeyedWindow(com.twitter.heron.streamlet.KeyedWindow) Window(com.twitter.heron.streamlet.Window) TupleWindow(com.twitter.heron.api.windowing.TupleWindow) KeyValue(com.twitter.heron.streamlet.KeyValue) HashMap(java.util.HashMap) KeyedWindow(com.twitter.heron.streamlet.KeyedWindow) Values(com.twitter.heron.api.tuple.Values) Tuple(com.twitter.heron.api.tuple.Tuple)

Example 27 with Values

use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.

the class TestSpout method nextTuple.

@Override
public void nextTuple() {
    // It will emit A, B, A, B, A, B, A, B, A, B
    if (emitted < EMIT_COUNT) {
        String word = toSend[emitted % toSend.length];
        emit(outputCollector, new Values(word), MESSAGE_ID, emitted++);
    }
}
Also used : Values(com.twitter.heron.api.tuple.Values)

Example 28 with Values

use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.

the class TestBolt method execute.

@Override
public void execute(Tuple tuple) {
    AtomicInteger ackCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton(Constants.ACK_COUNT);
    AtomicInteger failCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton(Constants.FAIL_COUNT);
    AtomicInteger tupleExecutedCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton(Constants.EXECUTE_COUNT);
    CountDownLatch tupleExecutedLatch = (CountDownLatch) SingletonRegistry.INSTANCE.getSingleton(Constants.EXECUTE_LATCH);
    StringBuilder receivedStrings = (StringBuilder) SingletonRegistry.INSTANCE.getSingleton(Constants.RECEIVED_STRING_LIST);
    if (receivedStrings != null) {
        receivedStrings.append(tuple.getString(0));
    }
    if (tupleExecutedCount != null) {
        tupleExecutedCount.getAndIncrement();
    }
    if ((tupleExecuted & 1) == 0) {
        outputCollector.ack(tuple);
        if (ackCount != null) {
            ackCount.getAndIncrement();
        }
    } else {
        outputCollector.fail(tuple);
        if (failCount != null) {
            failCount.getAndIncrement();
        }
    }
    tupleExecuted++;
    outputCollector.emit(new Values(tuple.getString(0)));
    if (tupleExecutedLatch != null) {
        tupleExecutedLatch.countDown();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Values(com.twitter.heron.api.tuple.Values) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 29 with Values

use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.

the class EmitDirectRoundRobinBolt method execute.

@Override
public void execute(Tuple tuple) {
    String word = toSend[emitted % toSend.length];
    outputCollector.emitDirect(emitted, new Values(word));
}
Also used : Values(com.twitter.heron.api.tuple.Values)

Example 30 with Values

use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.

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);
}
Also used : Values(com.twitter.heron.api.tuple.Values)

Aggregations

Values (com.twitter.heron.api.tuple.Values)34 Tuple (com.twitter.heron.api.tuple.Tuple)7 TupleWindow (com.twitter.heron.api.windowing.TupleWindow)6 IOException (java.io.IOException)6 Fields (com.twitter.heron.api.tuple.Fields)5 KeyValue (com.twitter.heron.streamlet.KeyValue)4 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)3 TupleWindowImpl (com.twitter.heron.api.windowing.TupleWindowImpl)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 KeyedWindow (com.twitter.heron.streamlet.KeyedWindow)2 Window (com.twitter.heron.streamlet.Window)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 TweetsGenerator (com.github.ashvina.common.TweetsGenerator)1 TopologyContext (com.twitter.heron.api.topology.TopologyContext)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RankableObjectWithFields (org.apache.storm.starter.tools.RankableObjectWithFields)1