storm.trident.operation.builtin.FilterNull Java Examples
The following examples show how to use
storm.trident.operation.builtin.FilterNull.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TridentWordCount.java From flink-perf with Apache License 2.0 | 7 votes |
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()).aggregate(new Fields("count"), new Sum(), new Fields("sum")); return topology.build(); }
Example #2
Source File: ESIndexUpdaterTest.java From storm-trident-elasticsearch with Apache License 2.0 | 6 votes |
@Override protected 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); ESIndexState.Factory<Tweet> factory = new ESIndexState.Factory<>(getLocalClient(), Tweet.class); TridentTopology topology = new TridentTopology(); TridentState state = topology.newStream("tweets", spout) .partitionPersist(factory, new Fields("sentence"), new ESIndexUpdater(new MyTridentTupleMapper())); topology.newDRPCStream("search", drpc) .each(new Fields("args"), new ExtractSearchArgs(), new Fields("query", "indices", "types")) .groupBy(new Fields("query", "indices", "types")) .stateQuery(state, new Fields("query", "indices", "types"), new QuerySearchIndexQuery(), new Fields("tweet")) .each(new Fields("tweet"), new FilterNull()) .each(new Fields("tweet"), new CreateJson(), new Fields("json")) .project(new Fields("json")); return topology.build(); }
Example #3
Source File: TridentWordCount.java From jstorm with Apache License 2.0 | 6 votes |
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()) .aggregate(new Fields("count"), new Sum(), new Fields("sum")); return topology.build(); }
Example #4
Source File: TridentMapExample.java From jstorm with Apache License 2.0 | 6 votes |
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) .filter(theFilter).peek(new Consumer() { @Override public void accept(TridentTuple input) { System.out.println(input.getString(0)); } }).groupBy(new Fields("word")) .persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")) .parallelismHint(16); topology.newDRPCStream("words", drpc).flatMap(split).groupBy(new Fields("args")) .stateQuery(wordCounts, new Fields("args"), new MapGet(), new Fields("count")).filter(new FilterNull()) .aggregate(new Fields("count"), new Sum(), new Fields("sum")); return topology.build(); }
Example #5
Source File: IndexMapStateTest.java From storm-trident-elasticsearch with Apache License 2.0 | 5 votes |
@Override public StormTopology buildTopology( ) { ESIndexMapState.Factory<Tweet> state = ESIndexMapState.nonTransactional(getLocalClient(), Tweet.class); 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 staticState = topology.newStaticState(new ESIndexState.Factory<>(getLocalClient(), Tweet.class)); topology.newStream("tweets", spout) .each(new Fields("sentence"), new DocumentBuilder(), new Fields("document")) .each(new Fields("document"), new ExtractDocumentInfo(), new Fields("id", "index", "type")) .groupBy(new Fields("index", "type", "id")) .persistentAggregate(state, new Fields("document"), new TweetBuilder(), new Fields("tweet")) .parallelismHint(1); topology.newDRPCStream("search", drpc) .each(new Fields("args"), new ExtractSearchArgs(), new Fields("query", "indices", "types")) .groupBy(new Fields("query", "indices", "types")) .stateQuery(staticState, new Fields("query", "indices", "types"), new QuerySearchIndexQuery(), new Fields("tweet")) .each(new Fields("tweet"), new FilterNull()) .each(new Fields("tweet"), new CreateJson(), new Fields("json")) .project(new Fields("json")); return topology.build(); }
Example #6
Source File: WordCountTopology.java From storm-cassandra-cql with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static StormTopology buildWordCountAndSourceTopology(LocalDRPC drpc) { LOG.info("Building topology."); TridentTopology topology = new TridentTopology(); String source1 = "spout1"; String source2 = "spout2"; FixedBatchSpout spout1 = new FixedBatchSpout(new Fields("sentence", "source"), 3, new Values("the cow jumped over the moon", source1), new Values("the man went to the store and bought some candy", source1), new Values("four score and four years ago", source2), new Values("how much wood can a wood chuck chuck", source2)); spout1.setCycle(true); TridentState wordCounts = topology.newStream("spout1", spout1) .each(new Fields("sentence"), new Split(), new Fields("word")) .groupBy(new Fields("word", "source")) .persistentAggregate(CassandraCqlMapState.nonTransactional(new WordCountAndSourceMapper()), new IntegerCount(), new Fields("count")) .parallelismHint(6); 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()) .aggregate(new Fields("count"), new Sum(), new Fields("sum")); return topology.build(); }
Example #7
Source File: Part04_BasicStateAndDRPC.java From trident-tutorial with Apache License 2.0 | 4 votes |
private static StormTopology basicStateAndDRPC(LocalDRPC drpc, FeederBatchSpout spout) throws IOException { TridentTopology topology = new TridentTopology(); // persistentAggregate persists the result of aggregation into data stores, // which you can use from other applications. // You can also use it in other topologies by using the TridentState object returned. // // The state is commonly backed by a data store like memcache, cassandra etc. // Here we are simply using a hash map TridentState countState = topology .newStream("spout", spout) .groupBy(new Fields("actor")) .persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")); // There are a few ready-made state libraries that you can use // Below is an example to use memcached // List<InetSocketAddress> memcachedServerLocations = ImmutableList.of(new InetSocketAddress("some.memcached.server",12000)); // TridentState countStateMemcached = // topology // .newStream("spout", spout) // .groupBy(new Fields("actor")) // .persistentAggregate(MemcachedState.transactional(memcachedServerLocations), new Count(), new Fields("count")); // DRPC stands for Distributed Remote Procedure Call // You can issue calls using the DRPC client library // A DRPC call takes two Strings, function name and function arguments // // In order to call the DRPC defined below, you'd use "count_per_actor" as the function name // The function arguments will be available as "args" /* topology .newDRPCStream("ping", drpc) .each(new Fields("args"), new Split(" "), new Fields("reply")) .each(new Fields("reply"), new RegexFilter("ping")) .project(new Fields("reply")); // You can apply usual processing primitives to DRPC streams as well topology .newDRPCStream("count", drpc) .each(new Fields("args"), new Split(" "), new Fields("split")) .each(new Fields("split"), new RegexFilter("a.*")) .groupBy(new Fields("split")) .aggregate(new Count(), new Fields("count")); */ // More usefully, you can query the state you created earlier topology .newDRPCStream("count_per_actor", drpc) .stateQuery(countState, new Fields("args"), new MapGet(), new Fields("count")); // Here is a more complex example topology .newDRPCStream("count_per_actors", drpc) .each(new Fields("args"), new Split(" "), new Fields("actor")) .groupBy(new Fields("actor")) .stateQuery(countState, new Fields("actor"), new MapGet(), new Fields("individual_count")) .each(new Fields("individual_count"), new FilterNull()) .aggregate(new Fields("individual_count"), new Sum(), new Fields("count")); // For how to call DRPC calls, go back to the main method return topology.build(); }