Search in sources :

Example 6 with Sum

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

the class TransactionalTridentEventCount method buildTopology.

@Override
protected StormTopology buildTopology(EventHubSpout eventHubSpout) {
    TridentTopology topology = new TridentTopology();
    TransactionalTridentEventHubSpout spout = new TransactionalTridentEventHubSpout(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) TridentState(org.apache.storm.trident.TridentState) MemoryMapState(org.apache.storm.trident.testing.MemoryMapState) Sum(org.apache.storm.trident.operation.builtin.Sum) Count(org.apache.storm.trident.operation.builtin.Count) TransactionalTridentEventHubSpout(org.apache.storm.eventhubs.trident.TransactionalTridentEventHubSpout)

Example 7 with Sum

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

the class TridentMapExample method buildTopology.

public static StormTopology buildTopology(LocalDRPC drpc) {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("word"), 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).flatMap(split).map(toUpper, new Fields("uppercased")).filter(theFilter).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            System.out.println(input.getString(0));
        }
    }).groupBy(new Fields("uppercased")).persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")).parallelismHint(16);
    topology.newDRPCStream("words", drpc).flatMap(split, new Fields("word")).groupBy(new Fields("word")).stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count")).filter(new FilterNull()).aggregate(new Fields("count"), new Sum(), new Fields("sum"));
    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) Consumer(org.apache.storm.trident.operation.Consumer) 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) Sum(org.apache.storm.trident.operation.builtin.Sum) Count(org.apache.storm.trident.operation.builtin.Count) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Example 8 with Sum

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

the class TridentReach method buildTopology.

public static StormTopology buildTopology(LocalDRPC drpc) {
    TridentTopology topology = new TridentTopology();
    TridentState urlToTweeters = topology.newStaticState(new StaticSingleKeyMapState.Factory(TWEETERS_DB));
    TridentState tweetersToFollowers = topology.newStaticState(new StaticSingleKeyMapState.Factory(FOLLOWERS_DB));
    topology.newDRPCStream("reach", drpc).stateQuery(urlToTweeters, new Fields("args"), new MapGet(), new Fields("tweeters")).each(new Fields("tweeters"), new ExpandList(), new Fields("tweeter")).shuffle().stateQuery(tweetersToFollowers, new Fields("tweeter"), new MapGet(), new Fields("followers")).each(new Fields("followers"), new ExpandList(), new Fields("follower")).groupBy(new Fields("follower")).aggregate(new One(), new Fields("one")).aggregate(new Fields("one"), new Sum(), new Fields("reach"));
    return topology.build();
}
Also used : Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) TridentState(org.apache.storm.trident.TridentState) MapGet(org.apache.storm.trident.operation.builtin.MapGet) Sum(org.apache.storm.trident.operation.builtin.Sum)

Aggregations

Sum (org.apache.storm.trident.operation.builtin.Sum)8 Fields (org.apache.storm.tuple.Fields)8 TridentState (org.apache.storm.trident.TridentState)7 TridentTopology (org.apache.storm.trident.TridentTopology)7 MapGet (org.apache.storm.trident.operation.builtin.MapGet)5 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)5 Values (org.apache.storm.tuple.Values)5 Count (org.apache.storm.trident.operation.builtin.Count)4 Stream (org.apache.storm.trident.Stream)3 StateFactory (org.apache.storm.trident.state.StateFactory)3 RedisDataTypeDescription (org.apache.storm.redis.common.mapper.RedisDataTypeDescription)2 MemoryMapState (org.apache.storm.trident.testing.MemoryMapState)2 InetSocketAddress (java.net.InetSocketAddress)1 HashSet (java.util.HashSet)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 QueryFilterCreator (org.apache.storm.mongodb.common.QueryFilterCreator)1 SimpleQueryFilterCreator (org.apache.storm.mongodb.common.SimpleQueryFilterCreator)1 MongoMapper (org.apache.storm.mongodb.common.mapper.MongoMapper)1