我在Streams领域还很陌生,在我的第一次尝试中遇到了一些问题。
我想做的是在下面的window: WindowdStream
中找到Top K元素。
我尝试实现自己的功能,但不确定其实际工作方式。
似乎什么也没打印
你有什么提示吗?
val parsedStream: DataStream[(String, Response)] = stream
.mapWith(_.decodeOption[Response])
.filter(_.isDefined)
.map { record =>
(
s"${record.get.group.group_country}, ${record.get.group.group_city}",
record.get
)
}
val topLocations = parsedStream
.keyBy(_._1)
.timeWindow(Time.days(7))
.process(new SortByCountFunction)
SortByCountFunction
class SortByCountFunction
extends ProcessWindowFunction[(String, Response), MeetUpLocationWindow, String, TimeWindow] {
override def process(key: String,
context: Context,
elements: Iterable[(String, Response)],
out: Collector[MeetUpLocationWindow]): Unit = {
val count: Map[String, Iterable[(String, Response)]] = elements.groupBy(_._1)
val locAndCount: Seq[MeetUpLocation] = count.toList.map(tmp => {
val location: String = tmp._1
val meetUpList: Iterable[(String, Response)] = tmp._2
MeetUpLocation(location, tmp._2.size, meetUpList.map(_._2).toList)
})
val output: List[MeetUpLocation] = locAndCount.sortBy(tup => tup.count).take(20).toList
val windowEnd = context.window.getEnd
out.collect(MeetUpLocationWindow(windowEnd, output))
}
}
case class MeetUpLocationWindow(endTs: Long, locations: List[MeetUpLocation])
case class MeetUpLocation(location: String, count: Int, meetUps: List[Response])
答案 0 :(得分:0)
当您的Flink DataStream作业无法产生任何输出时,通常可疑的是:
env.execute()
)上调用execute()TopLocations.print()
)在没有更多信息的情况下,很难猜测在这种情况下哪些可能是问题。