Search in sources :

Example 16 with Tuple

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

the class GeneralReduceByKeyAndWindowOperatorTest 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(new KeyValue<>(String.valueOf(i), j)));
            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) KeyValue(org.apache.heron.streamlet.KeyValue) 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 17 with Tuple

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

the class JoinOperatorTest method getJoinOperator.

@SuppressWarnings({ "rawtypes", "unchecked" })
private JoinOperator<String, KeyValue<String, String>, KeyValue<String, String>, String> getJoinOperator(JoinType type) {
    SerializableFunction<KeyValue<String, String>, String> f = x -> x == null ? "null" : x.getKey();
    JoinOperator<String, KeyValue<String, String>, KeyValue<String, String>, String> joinOperator = new JoinOperator(type, "leftComponent", "rightComponent", f, f, (SerializableBiFunction<KeyValue<String, String>, KeyValue<String, String>, String>) (o, o2) -> (o == null ? "null" : o.getValue()) + (o2 == null ? "null" : o2.getValue()));
    joinOperator.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 joinOperator;
}
Also used : TopologyContext(org.apache.heron.api.topology.TopologyContext) OutputCollector(org.apache.heron.api.bolt.OutputCollector) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) JoinType(org.apache.heron.streamlet.JoinType) HashMap(java.util.HashMap) HashSet(java.util.HashSet) SerializableBiFunction(org.apache.heron.streamlet.SerializableBiFunction) Map(java.util.Map) Tuple(org.apache.heron.api.tuple.Tuple) IOutputCollector(org.apache.heron.api.bolt.IOutputCollector) LinkedList(java.util.LinkedList) PowerMockito(org.powermock.api.mockito.PowerMockito) Before(org.junit.Before) KeyValue(org.apache.heron.streamlet.KeyValue) KeyedWindow(org.apache.heron.streamlet.KeyedWindow) Collection(java.util.Collection) Set(java.util.Set) TopologyContextImpl(org.apache.heron.common.utils.topology.TopologyContextImpl) Test(org.junit.Test) TupleImpl(org.apache.heron.common.utils.tuple.TupleImpl) TupleWindowImpl(org.apache.heron.api.windowing.TupleWindowImpl) SerializableFunction(org.apache.heron.streamlet.SerializableFunction) Mockito(org.mockito.Mockito) List(java.util.List) Fields(org.apache.heron.api.tuple.Fields) Config(org.apache.heron.api.Config) Values(org.apache.heron.api.tuple.Values) Assert(org.junit.Assert) TupleWindow(org.apache.heron.api.windowing.TupleWindow) Collections(java.util.Collections) TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) OutputCollector(org.apache.heron.api.bolt.OutputCollector) IOutputCollector(org.apache.heron.api.bolt.IOutputCollector) KeyValue(org.apache.heron.streamlet.KeyValue) Config(org.apache.heron.api.Config) IOutputCollector(org.apache.heron.api.bolt.IOutputCollector) Collection(java.util.Collection) LinkedList(java.util.LinkedList) List(java.util.List) TopologyContext(org.apache.heron.api.topology.TopologyContext) Tuple(org.apache.heron.api.tuple.Tuple)

Example 18 with Tuple

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

the class KeyByOperatorTest method getKeyByOperator.

@SuppressWarnings({ "rawtypes", "unchecked" })
private KeyByOperator<String, String, Integer> getKeyByOperator() {
    KeyByOperator<String, String, Integer> keyByOperator = new KeyByOperator<String, String, Integer>(x -> (Integer.valueOf(x) % 2 == 0) ? "even" : "odd", x -> Integer.valueOf(x));
    keyByOperator.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 keyByOperator;
}
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 19 with Tuple

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

the class WindowedBoltExecutorTest method testExecuteWithLateTupleStream.

@Test
public void testExecuteWithLateTupleStream() throws Exception {
    testWindowedBolt = new TestWindowedBolt();
    testWindowedBolt.withTimestampField("ts");
    executor = new WindowedBoltExecutor(testWindowedBolt);
    TopologyContext context = getTopologyContext();
    Mockito.when(context.getThisStreams()).thenReturn(new HashSet<>(Arrays.asList("default", "$late")));
    OutputCollector outputCollector = Mockito.mock(OutputCollector.class);
    Map<String, Object> conf = new HashMap<>();
    conf.put(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, 100000);
    conf.put(WindowingConfigs.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS, 20L);
    conf.put(WindowingConfigs.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS, 10L);
    conf.put(WindowingConfigs.TOPOLOGY_BOLTS_LATE_TUPLE_STREAM, "$late");
    conf.put(WindowingConfigs.TOPOLOGY_BOLTS_TUPLE_TIMESTAMP_MAX_LAG_MS, 5L);
    // Trigger manually to avoid timing issues
    conf.put(WindowingConfigs.TOPOLOGY_BOLTS_WATERMARK_EVENT_INTERVAL_MS, 1_000_000L);
    executor.prepare(conf, context, outputCollector);
    long[] timestamps = { 603, 605, 607, 618, 626, 636, 600 };
    List<Tuple> tuples = new ArrayList<>(timestamps.length);
    for (long ts : timestamps) {
        Tuple tuple = getTuple("s1", new Fields("ts"), new Values(ts));
        tuples.add(tuple);
        executor.execute(tuple);
        // Update the watermark to this timestamp
        executor.waterMarkEventGenerator.run();
    }
    System.out.println(testWindowedBolt.tupleWindows);
    Tuple tuple = tuples.get(tuples.size() - 1);
    Mockito.verify(outputCollector).emit("$late", Arrays.asList(tuple), new Values(tuple));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Values(org.apache.heron.api.tuple.Values) Fields(org.apache.heron.api.tuple.Fields) TopologyContext(org.apache.heron.api.topology.TopologyContext) Tuple(org.apache.heron.api.tuple.Tuple) Test(org.junit.Test)

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