如何使用 Trident 拓扑找到字数拓扑中计数最多的单词?这是 Trident 字数统计拓扑的链接。 https://github.com/nathanmarz/storm-starter/blob/master/src/jvm/storm/starter/trident/TridentWordCount.java
问问题
38 次
1 回答
0
Trident API 提供max和maxBy操作,它们在 trident 流中的一批元组的每个分区上返回最大值。
因此,在计算每个单词的计数后,如下所示:
Stream wordCountsStream = 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).newValuesStream();
使用maxBy获取具有最大计数的单词:
wordCountsStream.maxBy(new Fields("count"))
于 2019-03-04T11:54:14.620 回答