This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'cascalog.playground) (bootstrap) | |
(require '[clojure.set :as set]) | |
(require '[cascalog.vars :as v]) | |
(defn all-syms [form] | |
(if (coll? form) | |
(reduce (fn [curr elem] (set/union curr (all-syms elem))) | |
#{} | |
form) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | |
spout.setCycle(true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TridentTopology topology = new TridentTopology(); | |
TridentState wordCounts = | |
topology.newStream("spout1", spout) | |
.each(new Fields("sentence"), new Split(), new Fields("word")) | |
.groupBy(new Fields("word")) | |
.persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")) | |
.parallelismHint(6); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Split extends BaseFunction { | |
public void execute(TridentTuple tuple, TridentCollector collector) { | |
String sentence = tuple.getString(0); | |
for(String word: sentence.split(" ")) { | |
collector.emit(new Values(word)); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.persistentAggregate(MemcachedState.transactional(serverLocations), new Count(), new Fields("count")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DRPCClient client = new DRPCClient("drpc.server.location", 3772); | |
System.out.println(client.execute("words", "cat dog the man"); | |
// prints the JSON-encoded result, e.g.: "[[5078]]" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
topology.newDRPCStream("words") | |
.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")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TridentState urlToTweeters = | |
topology.newStaticState(getUrlToTweetersState()); | |
TridentState tweetersToFollowers = | |
topology.newStaticState(getTweeterToFollowersState()); | |
topology.newDRPCStream("reach") | |
.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")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class One implements CombinerAggregator<Integer> { | |
public Integer init(TridentTuple tuple) { | |
return 1; | |
} | |
public Integer combine(Integer val1, Integer val2) { | |
return 1; | |
} | |
public Integer zero() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stream.each(new Fields("y"), new MyFilter()) |