Search in sources :

Example 1 with Tuple

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

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(org.apache.heron.streamlet.KeyValue) Values(org.apache.heron.api.tuple.Values) TupleWindow(org.apache.heron.api.windowing.TupleWindow) LinkedList(java.util.LinkedList) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) Fields(org.apache.heron.api.tuple.Fields) TupleWindowImpl(org.apache.heron.api.windowing.TupleWindowImpl) Tuple(org.apache.heron.api.tuple.Tuple)

Example 2 with Tuple

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

the class ReduceByKeyAndWindowOperatorTest method getTupleWindow.

private TupleWindow getTupleWindow(int nkeys, int count) {
    TopologyAPI.StreamId componentStreamId = TopologyAPI.StreamId.newBuilder().setComponentName("sourceComponent").setId("default").build();
    List<Tuple> tuples = new LinkedList<>();
    for (int i = 0; i < nkeys; i++) {
        for (int j = 0; j < count; ++j) {
            Tuple tuple = getTuple(componentStreamId, new Fields("a"), new Values(String.valueOf(i)));
            tuples.add(tuple);
        }
    }
    TupleWindow tupleWindow = new TupleWindowImpl(tuples, new LinkedList<>(), new LinkedList<>(), startTime, endTime);
    return tupleWindow;
}
Also used : Fields(org.apache.heron.api.tuple.Fields) TupleWindowImpl(org.apache.heron.api.windowing.TupleWindowImpl) Values(org.apache.heron.api.tuple.Values) TupleWindow(org.apache.heron.api.windowing.TupleWindow) Tuple(org.apache.heron.api.tuple.Tuple) LinkedList(java.util.LinkedList) TopologyAPI(org.apache.heron.api.generated.TopologyAPI)

Example 3 with Tuple

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

the class ReduceByKeyAndWindowOperatorTest method getReduceByWindowOperator.

@SuppressWarnings({ "rawtypes", "unchecked" })
private ReduceByKeyAndWindowOperator<String, String, Integer> getReduceByWindowOperator() {
    ReduceByKeyAndWindowOperator<String, String, Integer> reduceByWindowOperator = new ReduceByKeyAndWindowOperator<>(x -> x, x -> 1, (o, o2) -> o + o2);
    reduceByWindowOperator.prepare(new Config(), PowerMockito.mock(TopologyContext.class), new OutputCollector(new IOutputCollector() {

        @Override
        public void reportError(Throwable error) {
        }

        @Override
        public List<Integer> emit(String streamId, Collection<Tuple> anchors, List<Object> tuple) {
            emittedTuples.addAll(tuple);
            return null;
        }

        @Override
        public void emitDirect(int taskId, String streamId, Collection<Tuple> anchors, List<Object> tuple) {
        }

        @Override
        public void ack(Tuple input) {
        }

        @Override
        public void fail(Tuple input) {
        }
    }));
    return reduceByWindowOperator;
}
Also used : OutputCollector(org.apache.heron.api.bolt.OutputCollector) IOutputCollector(org.apache.heron.api.bolt.IOutputCollector) Config(org.apache.heron.api.Config) IOutputCollector(org.apache.heron.api.bolt.IOutputCollector) Collection(java.util.Collection) List(java.util.List) LinkedList(java.util.LinkedList) TopologyContext(org.apache.heron.api.topology.TopologyContext) Tuple(org.apache.heron.api.tuple.Tuple)

Example 4 with Tuple

use of org.apache.heron.api.tuple.Tuple 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 5 with Tuple

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

the class JoinOperator method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(TupleWindow inputWindow) {
    Map<K, Pair<List<V1>, List<V2>>> joinMap = new HashMap<>();
    for (Tuple tuple : inputWindow.get()) {
        if (tuple.getSourceComponent().equals(leftComponent)) {
            V1 tup = (V1) tuple.getValue(0);
            if (tup != null) {
                addMapLeft(joinMap, tup);
            }
        } else {
            V2 tup = (V2) tuple.getValue(0);
            if (tup != null) {
                addMapRight(joinMap, tup);
            }
        }
    }
    evaluateJoinMap(joinMap, inputWindow);
}
Also used : HashMap(java.util.HashMap) Tuple(org.apache.heron.api.tuple.Tuple) Pair(org.apache.heron.api.Pair)

Aggregations

Tuple (org.apache.heron.api.tuple.Tuple)19 Values (org.apache.heron.api.tuple.Values)9 TopologyContext (org.apache.heron.api.topology.TopologyContext)8 LinkedList (java.util.LinkedList)7 Fields (org.apache.heron.api.tuple.Fields)7 HashMap (java.util.HashMap)6 TupleWindow (org.apache.heron.api.windowing.TupleWindow)6 KeyValue (org.apache.heron.streamlet.KeyValue)6 List (java.util.List)5 Config (org.apache.heron.api.Config)5 Collection (java.util.Collection)4 IOutputCollector (org.apache.heron.api.bolt.IOutputCollector)4 OutputCollector (org.apache.heron.api.bolt.OutputCollector)4 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)4 TopologyBuilder (org.apache.heron.api.topology.TopologyBuilder)4 TupleWindowImpl (org.apache.heron.api.windowing.TupleWindowImpl)4 BaseBasicBolt (org.apache.heron.api.bolt.BaseBasicBolt)3 BasicOutputCollector (org.apache.heron.api.bolt.BasicOutputCollector)3 BaseRichSpout (org.apache.heron.api.spout.BaseRichSpout)3 SpoutOutputCollector (org.apache.heron.api.spout.SpoutOutputCollector)3