Search in sources :

Example 1 with Values

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

the class CustomSpout method nextTuple.

@Override
public void nextTuple() {
    CustomObject obj = inputObjects[(emitted++) % inputObjects.length];
    collector.emit(new Values(obj));
}
Also used : Values(com.twitter.heron.api.tuple.Values)

Example 2 with Values

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

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 3 with Values

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

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)

Example 4 with Values

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

the class JoinOperatorTest method getTupleWindow.

private TupleWindow getTupleWindow() {
    TopologyAPI.StreamId leftComponentStreamId = TopologyAPI.StreamId.newBuilder().setComponentName("leftComponent").setId("s1").build();
    TopologyAPI.StreamId rightComponentStreamId = TopologyAPI.StreamId.newBuilder().setComponentName("rightComponent").setId("s1").build();
    List<Tuple> tuples = new LinkedList<>();
    for (int i = 0; i < 5; i++) {
        Tuple tuple;
        if (i % 2 == 0) {
            tuple = getTuple(leftComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key1", String.valueOf(i))));
        } else {
            tuple = getTuple(rightComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key1", String.valueOf(i))));
        }
        tuples.add(tuple);
    }
    for (int i = 5; i < 8; i++) {
        Tuple tuple = getTuple(leftComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key2", String.valueOf(i))));
        tuples.add(tuple);
    }
    for (int i = 8; i < 12; i++) {
        Tuple tuple = getTuple(rightComponentStreamId, new Fields("a"), new Values(new KeyValue<String, String>("key3", String.valueOf(i))));
        tuples.add(tuple);
    }
    TupleWindow tupleWindow = new TupleWindowImpl(tuples, new LinkedList<>(), new LinkedList<>(), startTime, endTime);
    return tupleWindow;
}
Also used : KeyValue(com.twitter.heron.streamlet.KeyValue) Values(com.twitter.heron.api.tuple.Values) TupleWindow(com.twitter.heron.api.windowing.TupleWindow) LinkedList(java.util.LinkedList) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Fields(com.twitter.heron.api.tuple.Fields) TupleWindowImpl(com.twitter.heron.api.windowing.TupleWindowImpl) Tuple(com.twitter.heron.api.tuple.Tuple)

Example 5 with Values

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

the class FilterOperator method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(Tuple tuple) {
    R obj = (R) tuple.getValue(0);
    if (filterFn.test(obj)) {
        collector.emit(new Values(obj));
    }
    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