Search in sources :

Example 31 with Values

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

the class GeneralReduceByKeyAndWindowOperator method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(TupleWindow inputWindow) {
    Map<K, VR> reduceMap = new HashMap<>();
    Map<K, Integer> windowCountMap = new HashMap<>();
    for (Tuple tuple : inputWindow.get()) {
        V tup = (V) 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 32 with Values

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

the class HdfsStringSpout method nextTuple.

@Override
public void nextTuple() {
    if (br == null) {
        return;
    }
    try {
        String line = "";
        if ((line = br.readLine()) != null) {
            collector.emit(new Values(line));
        } else {
            br.close();
            br = null;
        }
    } catch (IOException e) {
        // Clean stuff if any exceptions
        try {
            // Close the outmost is enough
            br.close();
        } catch (IOException e1) {
            throw new RuntimeException("Unable to close stream reader", e1);
        }
        throw new RuntimeException("Unable to emit tuples normally", e);
    }
}
Also used : Values(com.twitter.heron.api.tuple.Values) IOException(java.io.IOException)

Example 33 with Values

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

the class ABSpout method nextTuple.

@Override
public void nextTuple() {
    String word = TO_SEND[emitted % TO_SEND.length];
    if (appendSequenceId) {
        word = word + "_" + emitted;
    }
    collector.emit(new Values(word));
    emitted++;
}
Also used : Values(com.twitter.heron.api.tuple.Values)

Example 34 with Values

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

the class LocalFileSpout method nextTuple.

// We do not explicitly close the buffered reader, even on EoF. This is in case more content is
// added to file, we will read that content as well
@Override
public void nextTuple() {
    if (br == null) {
        return;
    }
    try {
        String currentLine;
        if ((currentLine = br.readLine()) != null) {
            collector.emit(new Values(currentLine));
        } else {
            br.close();
            br = null;
        }
    } catch (IOException e) {
        // Clean stuff if any exceptions
        try {
            // Close the outmost is enough
            if (br != null) {
                br.close();
            }
        } catch (IOException e1) {
            throw new RuntimeException("Unable to close stream reader", e1);
        }
        throw new RuntimeException("Unable to emit tuples normally", e);
    }
}
Also used : Values(com.twitter.heron.api.tuple.Values) IOException(java.io.IOException)

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