Search in sources :

Example 1 with Fields

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

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

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

the class WindowedBoltExecutorTest method testExecuteWithTs.

@Test
public void testExecuteWithTs() throws Exception {
    long[] timestamps = { 603, 605, 607, 618, 626, 636 };
    for (long ts : timestamps) {
        executor.execute(getTuple("s1", new Fields("ts"), new Values(ts)));
    }
    // Thread.sleep(120);
    executor.waterMarkEventGenerator.run();
    // System.out.println(testWindowedBolt.tupleWindows);
    assertEquals(3, testWindowedBolt.tupleWindows.size());
    TupleWindow first = testWindowedBolt.tupleWindows.get(0);
    assertArrayEquals(new long[] { 603, 605, 607 }, new long[] { (long) first.get().get(0).getValue(0), (long) first.get().get(1).getValue(0), (long) first.get().get(2).getValue(0) });
    TupleWindow second = testWindowedBolt.tupleWindows.get(1);
    assertArrayEquals(new long[] { 603, 605, 607, 618 }, new long[] { (long) second.get().get(0).getValue(0), (long) second.get().get(1).getValue(0), (long) second.get().get(2).getValue(0), (long) second.get().get(3).getValue(0) });
    TupleWindow third = testWindowedBolt.tupleWindows.get(2);
    assertArrayEquals(new long[] { 618, 626 }, new long[] { (long) third.get().get(0).getValue(0), (long) third.get().get(1).getValue(0) });
}
Also used : Fields(org.apache.heron.api.tuple.Fields) Values(org.apache.heron.api.tuple.Values) TupleWindow(org.apache.heron.api.windowing.TupleWindow) Test(org.junit.Test)

Example 4 with Fields

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

the class AllGrouping method buildTopology.

@Override
protected TestTopologyBuilder buildTopology(TestTopologyBuilder builder) {
    builder.setSpout("ab-spout", new ABSpout(), 1);
    builder.setBolt("identity-bolt", new IdentityBolt(new Fields("word")), 2).allGrouping("ab-spout");
    return builder;
}
Also used : IdentityBolt(org.apache.heron.integration_test.common.bolt.IdentityBolt) Fields(org.apache.heron.api.tuple.Fields) ABSpout(org.apache.heron.integration_test.common.spout.ABSpout)

Example 5 with Fields

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

the class BoltDoubleEmitTuples method buildTopology.

@Override
protected TestTopologyBuilder buildTopology(TestTopologyBuilder builder) {
    builder.setSpout("ab-spout", new ABSpout(), 1);
    builder.setBolt("double-tuples-bolt", new DoubleTuplesBolt(new Fields("word")), 1).shuffleGrouping("ab-spout");
    return builder;
}
Also used : Fields(org.apache.heron.api.tuple.Fields) DoubleTuplesBolt(org.apache.heron.integration_test.common.bolt.DoubleTuplesBolt) ABSpout(org.apache.heron.integration_test.common.spout.ABSpout)

Aggregations

Fields (org.apache.heron.api.tuple.Fields)34 ABSpout (org.apache.heron.integration_test.common.spout.ABSpout)15 IdentityBolt (org.apache.heron.integration_test.common.bolt.IdentityBolt)13 Config (org.apache.heron.api.Config)6 TopologyBuilder (org.apache.heron.api.topology.TopologyBuilder)6 Tuple (org.apache.heron.api.tuple.Tuple)6 Values (org.apache.heron.api.tuple.Values)5 HashMap (java.util.HashMap)4 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)4 TupleWindow (org.apache.heron.api.windowing.TupleWindow)4 LinkedList (java.util.LinkedList)3 TopologyContext (org.apache.heron.api.topology.TopologyContext)3 TupleWindowImpl (org.apache.heron.api.windowing.TupleWindowImpl)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 BaseBasicBolt (org.apache.heron.api.bolt.BaseBasicBolt)2 BasicOutputCollector (org.apache.heron.api.bolt.BasicOutputCollector)2 BaseRichSpout (org.apache.heron.api.spout.BaseRichSpout)2 SpoutOutputCollector (org.apache.heron.api.spout.SpoutOutputCollector)2 BoltDeclarer (org.apache.heron.api.topology.BoltDeclarer)2