Search in sources :

Example 1 with PairValueMapper

use of org.apache.storm.streams.operations.mappers.PairValueMapper in project storm by apache.

the class JoinExample method main.

public static void main(String[] args) throws Exception {
    StreamBuilder builder = new StreamBuilder();
    // a stream of (number, square) pairs
    PairStream<Integer, Integer> squares = builder.newStream(new NumberSpout(x -> x * x), new PairValueMapper<>(0, 1));
    // a stream of (number, cube) pairs
    PairStream<Integer, Integer> cubes = builder.newStream(new NumberSpout(x -> x * x * x), new PairValueMapper<>(0, 1));
    // create a windowed stream of five seconds duration
    squares.window(TumblingWindows.of(Duration.seconds(5))).join(cubes).print();
    Config config = new Config();
    String topoName = JoinExample.class.getName();
    if (args.length > 0) {
        topoName = args[0];
    }
    config.setNumWorkers(1);
    StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
Also used : StormSubmitter(org.apache.storm.StormSubmitter) OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) Duration(org.apache.storm.topology.base.BaseWindowedBolt.Duration) BaseRichSpout(org.apache.storm.topology.base.BaseRichSpout) PairValueMapper(org.apache.storm.streams.operations.mappers.PairValueMapper) PairStream(org.apache.storm.streams.PairStream) StreamBuilder(org.apache.storm.streams.StreamBuilder) TopologyContext(org.apache.storm.task.TopologyContext) Fields(org.apache.storm.tuple.Fields) Utils(org.apache.storm.utils.Utils) Function(org.apache.storm.streams.operations.Function) Values(org.apache.storm.tuple.Values) TumblingWindows(org.apache.storm.streams.windowing.TumblingWindows) Map(java.util.Map) Config(org.apache.storm.Config) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) Config(org.apache.storm.Config) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 2 with PairValueMapper

use of org.apache.storm.streams.operations.mappers.PairValueMapper in project storm by apache.

the class GroupByKeyAndWindowExample method main.

public static void main(String[] args) throws Exception {
    StreamBuilder builder = new StreamBuilder();
    // a stream of stock quotes
    builder.newStream(new StockQuotes(), new PairValueMapper<String, Double>(0, 1)).groupByKeyAndWindow(SlidingWindows.of(Count.of(6), Count.of(3))).print();
    // a stream of stock quotes
    builder.newStream(new StockQuotes(), new PairValueMapper<String, Double>(0, 1)).reduceByKeyAndWindow((x, y) -> x > y ? x : y, SlidingWindows.of(Count.of(6), Count.of(3))).print();
    Config config = new Config();
    String topoName = GroupByKeyAndWindowExample.class.getName();
    if (args.length > 0) {
        topoName = args[0];
    }
    config.setNumWorkers(1);
    StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
Also used : StormSubmitter(org.apache.storm.StormSubmitter) OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) BaseRichSpout(org.apache.storm.topology.base.BaseRichSpout) Arrays(java.util.Arrays) PairValueMapper(org.apache.storm.streams.operations.mappers.PairValueMapper) PairStream(org.apache.storm.streams.PairStream) StreamBuilder(org.apache.storm.streams.StreamBuilder) TopologyContext(org.apache.storm.task.TopologyContext) Fields(org.apache.storm.tuple.Fields) Utils(org.apache.storm.utils.Utils) Reducer(org.apache.storm.streams.operations.Reducer) List(java.util.List) Values(org.apache.storm.tuple.Values) SlidingWindows(org.apache.storm.streams.windowing.SlidingWindows) Window(org.apache.storm.streams.windowing.Window) Map(java.util.Map) Count(org.apache.storm.topology.base.BaseWindowedBolt.Count) Config(org.apache.storm.Config) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) Config(org.apache.storm.Config) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Aggregations

Map (java.util.Map)2 Config (org.apache.storm.Config)2 StormSubmitter (org.apache.storm.StormSubmitter)2 SpoutOutputCollector (org.apache.storm.spout.SpoutOutputCollector)2 PairStream (org.apache.storm.streams.PairStream)2 StreamBuilder (org.apache.storm.streams.StreamBuilder)2 PairValueMapper (org.apache.storm.streams.operations.mappers.PairValueMapper)2 TopologyContext (org.apache.storm.task.TopologyContext)2 OutputFieldsDeclarer (org.apache.storm.topology.OutputFieldsDeclarer)2 BaseRichSpout (org.apache.storm.topology.base.BaseRichSpout)2 Fields (org.apache.storm.tuple.Fields)2 Values (org.apache.storm.tuple.Values)2 Utils (org.apache.storm.utils.Utils)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Function (org.apache.storm.streams.operations.Function)1 Reducer (org.apache.storm.streams.operations.Reducer)1 SlidingWindows (org.apache.storm.streams.windowing.SlidingWindows)1 TumblingWindows (org.apache.storm.streams.windowing.TumblingWindows)1 Window (org.apache.storm.streams.windowing.Window)1