Search in sources :

Example 11 with Values

use of org.apache.heron.api.tuple.Values 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))));
    }
}
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 12 with Values

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

the class StatefulRandomIntSpout method nextTuple.

@Override
public void nextTuple() {
    Utils.sleep(2000);
    int randomInt = randomInt();
    System.out.println("Emitting Value: " + randomInt);
    spoutOutputCollector.emit(new Values(randomInt));
}
Also used : Values(org.apache.heron.api.tuple.Values)

Example 13 with Values

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

the class WordSpout method nextTuple.

@Override
public void nextTuple() {
    System.out.println("next tuple");
    int nextInt = rnd.nextInt(ARRAY_LENGTH);
    collector.emit(new Values(words[nextInt]));
}
Also used : Values(org.apache.heron.api.tuple.Values)

Example 14 with Values

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

the class PausedLocalFileSpout method nextTuple.

// each nextTuple will either read the current line as null, and not emit anything
// or emit one line from the text file
// We do not explicitly close buffered reader. This is so the spout will read any new data
// appended to the file. On spout close, buffered reader will close automatically
@Override
public void nextTuple() {
    if (br == null) {
        return;
    }
    try {
        String currentLine;
        // more content, and do not emit anything if data is null
        if ((currentLine = br.readLine()) != null) {
            LOG.info("Emitting tuple from input data file: " + currentLine);
            collector.emit(new Values(currentLine), "MESSAGE_ID");
        }
    } 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(org.apache.heron.api.tuple.Values) IOException(java.io.IOException)

Example 15 with Values

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

the class IntegrationTestBolt method execute.

@Override
public void execute(Tuple tuple) {
    String streamID = tuple.getSourceStreamId();
    LOG.info("Received a tuple: " + tuple + " ; from: " + streamID);
    if (streamID.equals(Constants.INTEGRATION_TEST_CONTROL_STREAM_ID)) {
        terminalsToReceive--;
        if (terminalsToReceive == 0) {
            // invoke the finishBatch() callback if necessary
            if (IBatchBolt.class.isInstance(delegateBolt)) {
                LOG.fine("Invoke bolt to do finishBatch!");
                ((IBatchBolt) delegateBolt).finishBatch();
            }
            LOG.info("Received the last terminal, populating the terminals to downstream");
            collector.emit(Constants.INTEGRATION_TEST_CONTROL_STREAM_ID, tuple, new Values(Constants.INTEGRATION_TEST_TERMINAL));
        } else {
            LOG.info(String.format("Received a terminal, need to receive %s more", terminalsToReceive));
        }
    } else {
        tuplesReceived++;
        currentTupleProcessing = tuple;
        delegateBolt.execute(tuple);
        // We ack only the tuples in user's logic
        if (this.ackAuto) {
            collector.ack(tuple);
        }
    }
}
Also used : 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