Search in sources :

Example 1 with Count

use of org.apache.storm.trident.operation.builtin.Count in project storm by apache.

the class TridentWordCount method buildTopology.

public static StormTopology buildTopology(LocalDRPC drpc) {
    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();
    TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).groupBy(new Fields("word")).persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")).parallelismHint(16);
    topology.newDRPCStream("words", drpc).each(new Fields("args"), new Split(), new Fields("word")).groupBy(new Fields("word")).stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count")).each(new Fields("count"), new FilterNull()).project(new Fields("word", "count"));
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) FilterNull(org.apache.storm.trident.operation.builtin.FilterNull) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) MapGet(org.apache.storm.trident.operation.builtin.MapGet) Count(org.apache.storm.trident.operation.builtin.Count)

Example 2 with Count

use of org.apache.storm.trident.operation.builtin.Count in project storm by apache.

the class TridentWordCount method buildTopology.

public static 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"), new Values("to be or not to be the person"));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).groupBy(new Fields("word")).persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")).parallelismHint(16);
    topology.newDRPCStream("words").each(new Fields("args"), new Split(), new Fields("word")).groupBy(new Fields("word")).stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count")).each(new Fields("count"), new FilterNull()).project(new Fields("word", "count"));
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) FilterNull(org.apache.storm.trident.operation.builtin.FilterNull) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) MapGet(org.apache.storm.trident.operation.builtin.MapGet) Count(org.apache.storm.trident.operation.builtin.Count)

Example 3 with Count

use of org.apache.storm.trident.operation.builtin.Count in project storm by apache.

the class TridentTopologySource method getTopology.

public StormTopology getTopology(Config config) {
    this.spout = new FixedBatchSpout(new Fields("sentence"), 20, new Values("one two"), new Values("two three"), new Values("three four"), new Values("four five"), new Values("five six"));
    TridentTopology trident = new TridentTopology();
    trident.newStream("wordcount", spout).name("sentence").parallelismHint(1).shuffle().each(new Fields("sentence"), new Split(), new Fields("word")).parallelismHint(1).groupBy(new Fields("word")).persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")).parallelismHint(1);
    return trident.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) Values(org.apache.storm.tuple.Values) Count(org.apache.storm.trident.operation.builtin.Count)

Example 4 with Count

use of org.apache.storm.trident.operation.builtin.Count 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 5 with Count

use of org.apache.storm.trident.operation.builtin.Count in project storm by apache.

the class OpaqueTridentEventCount method buildTopology.

@Override
protected StormTopology buildTopology(EventHubSpout eventHubSpout) {
    TridentTopology topology = new TridentTopology();
    OpaqueTridentEventHubSpout spout = new OpaqueTridentEventHubSpout(spoutConfig);
    TridentState state = topology.newStream("stream-" + spoutConfig.getTopologyName(), spout).parallelismHint(spoutConfig.getPartitionCount()).aggregate(new Count(), new Fields("partial-count")).persistentAggregate(new MemoryMapState.Factory(), new Fields("partial-count"), new Sum(), new Fields("count"));
    state.newValuesStream().each(new Fields("count"), new LoggingFilter("got count: ", 10000));
    return topology.build();
}
Also used : Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) OpaqueTridentEventHubSpout(org.apache.storm.eventhubs.trident.OpaqueTridentEventHubSpout) TridentState(org.apache.storm.trident.TridentState) MemoryMapState(org.apache.storm.trident.testing.MemoryMapState) LoggingFilter(org.apache.storm.eventhubs.samples.TransactionalTridentEventCount.LoggingFilter) Sum(org.apache.storm.trident.operation.builtin.Sum) Count(org.apache.storm.trident.operation.builtin.Count)

Aggregations

Count (org.apache.storm.trident.operation.builtin.Count)9 Fields (org.apache.storm.tuple.Fields)9 TridentTopology (org.apache.storm.trident.TridentTopology)8 TridentState (org.apache.storm.trident.TridentState)7 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)7 Values (org.apache.storm.tuple.Values)7 Sum (org.apache.storm.trident.operation.builtin.Sum)6 FilterNull (org.apache.storm.trident.operation.builtin.FilterNull)5 MapGet (org.apache.storm.trident.operation.builtin.MapGet)5 Consumer (org.apache.storm.trident.operation.Consumer)2 MemoryMapState (org.apache.storm.trident.testing.MemoryMapState)2 Split (org.apache.storm.trident.testing.Split)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 LoggingFilter (org.apache.storm.eventhubs.samples.TransactionalTridentEventCount.LoggingFilter)1 OpaqueTridentEventHubSpout (org.apache.storm.eventhubs.trident.OpaqueTridentEventHubSpout)1 TransactionalTridentEventHubSpout (org.apache.storm.eventhubs.trident.TransactionalTridentEventHubSpout)1 StringLength (org.apache.storm.trident.testing.StringLength)1