0
我想获得多个字段的总和。我用这个代码来解释我的痛苦:如何在Flink中总结多个字段?
// parse the data, group it, window it, and aggregate the counts
val windowCounts = text
.flatMap { w => w.split("\\s") }
.map { w => WordWithCount(w, 1, 2) }
.keyBy("word")
.timeWindow(Time.seconds(5), Time.seconds(1))
.sum("count")
case class WordWithCount(word: String, count: Long, count2: Long)
我想在我的时间窗口中的两个字段(计数和count2)的总和。 我不能添加多个和这样的:
val windowCounts = text
.flatMap { w => w.split("\\s") }
.map { w => WordWithCount(w, 1, 2) }
.keyBy("word")
.timeWindow(Time.seconds(5), Time.seconds(1))
.sum("count", "count2")
我不知道该怎么做。
你怎么看待使用map函数来创建一个具有任意键的元组流,并在开始时使用两个字段值的总和,然后使用聚合? –
使用@FabianHueske的解决方案它工作正常,我使用reduceFunction与自定义总和。 ''' 流 .MAP(X => transfom(X)) .keyBy( “场”) .timeWindow(Time.milliseconds(10000),Time.milliseconds(1000)) 。降低((X ,y)=> Custom.sum(x,y)) ''' – FlinkNoob