use of org.apache.storm.streams.StreamBuilder in project storm by apache.
the class QueryPlanner method compile.
public AbstractStreamsProcessor compile(Map<String, ISqlStreamsDataSource> sources, String query) throws Exception {
StreamsRel relNode = getPlan(query);
StreamsPlanCreator streamsPlanCreator = new StreamsPlanCreator(sources, new RexBuilder(typeFactory));
relNode.streamsPlan(streamsPlanCreator);
final StreamBuilder streamBuilder = streamsPlanCreator.getStreamBuilder();
final Stream<Values> lastStream = streamsPlanCreator.pop();
final DataContext dc = streamsPlanCreator.getDataContext();
final List<CompilingClassLoader> cls = streamsPlanCreator.getClassLoaders();
return new AbstractStreamsProcessor() {
@Override
public StormTopology build() {
return streamBuilder.build();
}
@Override
public Stream<Values> outputStream() {
return lastStream;
}
@Override
public DataContext getDataContext() {
return dc;
}
@Override
public List<CompilingClassLoader> getClassLoaders() {
return cls;
}
};
}
use of org.apache.storm.streams.StreamBuilder in project storm by apache.
the class WindowedWordCount method main.
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
// A stream of random sentences
builder.newStream(new RandomSentenceSpout(), new ValueMapper<String>(0), 2).window(TumblingWindows.of(Duration.seconds(2))).flatMap(s -> Arrays.asList(s.split(" "))).mapToPair(w -> Pair.of(w, 1)).countByKey().filter(x -> x.getSecond() >= 5).print();
Config config = new Config();
String topoName = "test";
if (args.length > 0) {
topoName = args[0];
}
config.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
use of org.apache.storm.streams.StreamBuilder in project storm by apache.
the class AggregateExample method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
/**
* Computes average of the stream of numbers emitted by the spout. Internally the per-partition
* sum and counts are accumulated and emitted to a downstream task where the partially accumulated
* results are merged and the final result is emitted.
*/
builder.newStream(new RandomIntegerSpout(), new ValueMapper<Integer>(0), 2).window(TumblingWindows.of(BaseWindowedBolt.Duration.seconds(5))).filter(x -> x > 0 && x < 500).aggregate(new Avg()).print();
Config config = new Config();
String topoName = "AGG_EXAMPLE";
if (args.length > 0) {
topoName = args[0];
}
config.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
use of org.apache.storm.streams.StreamBuilder in project storm by apache.
the class BranchExample method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
Stream<Integer>[] evenAndOdd = builder.newStream(new RandomIntegerSpout(), new ValueMapper<Integer>(0)).branch(x -> (x % 2) == 0, x -> (x % 2) == 1);
evenAndOdd[0].forEach(x -> LOG.info("EVEN> " + x));
evenAndOdd[1].forEach(x -> LOG.info("ODD > " + x));
Config config = new Config();
String topoName = "branchExample";
if (args.length > 0) {
topoName = args[0];
}
config.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
use of org.apache.storm.streams.StreamBuilder 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