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());
}
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());
}
Aggregations