Search in sources :

Example 1 with Split

use of org.apache.storm.trident.testing.Split in project storm by apache.

the class TridentWindowingInmemoryStoreTopology method buildTopology.

public static StormTopology buildTopology(WindowsStoreFactory windowStore, WindowConfig windowConfig) throws Exception {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"), new Values("to be or not to be the person"));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).window(windowConfig, windowStore, new Fields("word"), new CountAsAggregator(), new Fields("count")).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            LOG.info("Received tuple: [{}]", input);
        }
    });
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) Consumer(org.apache.storm.trident.operation.Consumer) TridentTopology(org.apache.storm.trident.TridentTopology) CountAsAggregator(org.apache.storm.trident.testing.CountAsAggregator) Values(org.apache.storm.tuple.Values) Stream(org.apache.storm.trident.Stream) Split(org.apache.storm.trident.testing.Split) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Example 2 with Split

use of org.apache.storm.trident.testing.Split in project storm by apache.

the class TestTridentTopology method buildTopology.

private StormTopology buildTopology() {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    topology.newStream("spout", spout).each(new Fields("sentence"), new Split(), new Fields("word")).partitionBy(new Fields("word")).name("abc").each(new Fields("word"), new StringLength(), new Fields("length")).partitionBy(new Fields("length")).name("def").aggregate(new Fields("length"), new Count(), new Fields("count")).partitionBy(new Fields("count")).name("ghi").aggregate(new Fields("count"), new Sum(), new Fields("sum"));
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) StringLength(org.apache.storm.trident.testing.StringLength) Fields(org.apache.storm.tuple.Fields) Values(org.apache.storm.tuple.Values) Sum(org.apache.storm.trident.operation.builtin.Sum) Count(org.apache.storm.trident.operation.builtin.Count) Split(org.apache.storm.trident.testing.Split)

Example 3 with Split

use of org.apache.storm.trident.testing.Split in project storm by apache.

the class MapStateTest method wordsTest.

public void wordsTest(StateFactory factory) throws Exception {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"));
    spout.setCycle(false);
    TridentTopology topology = new TridentTopology();
    TridentState wordCounts = topology.newStream("spout1", spout).each(new Fields("sentence"), new Split(), new Fields("word")).groupBy(new Fields("word")).persistentAggregate(factory, new Count(), new Fields("state")).parallelismHint(1);
    LocalCluster cluster = new LocalCluster();
    LocalDRPC client = new LocalDRPC(cluster.getMetricRegistry());
    topology.newDRPCStream("words", client).each(new Fields("args"), new Split(), new Fields("word")).groupBy(new Fields("word")).stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("state")).each(new Fields("state"), new FilterNull()).aggregate(new Fields("state"), new Sum(), new Fields("sum"));
    logger.info("Submitting topology.");
    cluster.submitTopology("test", new HashMap(), topology.build());
    logger.info("Waiting for something to happen.");
    int count;
    do {
        Thread.sleep(2000);
        count = session.execute(QueryBuilder.select().all().from("words_ks", "words_table")).getAvailableWithoutFetching();
        logger.info("Found {} records", count);
    } while (count < 24);
    logger.info("Starting queries.");
    // 5
    assertEquals("[[5]]", client.execute("words", "cat dog the man"));
    // 0
    assertEquals("[[0]]", client.execute("words", "cat"));
    // 0
    assertEquals("[[0]]", client.execute("words", "dog"));
    // 4
    assertEquals("[[4]]", client.execute("words", "the"));
    // 1
    assertEquals("[[1]]", client.execute("words", "man"));
    cluster.shutdown();
}
Also used : LocalCluster(org.apache.storm.LocalCluster) FilterNull(org.apache.storm.trident.operation.builtin.FilterNull) TridentState(org.apache.storm.trident.TridentState) HashMap(java.util.HashMap) Values(org.apache.storm.tuple.Values) MapGet(org.apache.storm.trident.operation.builtin.MapGet) Sum(org.apache.storm.trident.operation.builtin.Sum) Count(org.apache.storm.trident.operation.builtin.Count) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) LocalDRPC(org.apache.storm.LocalDRPC) Split(org.apache.storm.trident.testing.Split)

Example 4 with Split

use of org.apache.storm.trident.testing.Split in project storm by apache.

the class TridentHBaseWindowingStoreTopology method buildTopology.

public static StormTopology buildTopology(WindowsStoreFactory windowsStore) throws Exception {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"), new Values("to be or not to be the person"));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).window(TumblingCountWindow.of(1000), windowsStore, new Fields("word"), new CountAsAggregator(), new Fields("count")).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            LOG.info("Received tuple: [{}]", input);
        }
    });
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) Consumer(org.apache.storm.trident.operation.Consumer) TridentTopology(org.apache.storm.trident.TridentTopology) CountAsAggregator(org.apache.storm.trident.testing.CountAsAggregator) Values(org.apache.storm.tuple.Values) Stream(org.apache.storm.trident.Stream) Split(org.apache.storm.trident.testing.Split) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Aggregations

FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)4 Split (org.apache.storm.trident.testing.Split)4 Fields (org.apache.storm.tuple.Fields)4 Values (org.apache.storm.tuple.Values)4 TridentTopology (org.apache.storm.trident.TridentTopology)3 Stream (org.apache.storm.trident.Stream)2 Consumer (org.apache.storm.trident.operation.Consumer)2 Count (org.apache.storm.trident.operation.builtin.Count)2 Sum (org.apache.storm.trident.operation.builtin.Sum)2 CountAsAggregator (org.apache.storm.trident.testing.CountAsAggregator)2 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)2 HashMap (java.util.HashMap)1 LocalCluster (org.apache.storm.LocalCluster)1 LocalDRPC (org.apache.storm.LocalDRPC)1 TridentState (org.apache.storm.trident.TridentState)1 FilterNull (org.apache.storm.trident.operation.builtin.FilterNull)1 MapGet (org.apache.storm.trident.operation.builtin.MapGet)1 StringLength (org.apache.storm.trident.testing.StringLength)1