Reputation: 1373
I am pretty new in the world of Streams and I am facing some issues in my first try.
What I would like to do is to find the Top K element in the window: WindowdStream
below.
I tried to implement my own function but not sure how it actually works.
Seems that doesn't print anything
May you have any hint?
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])
Upvotes: 1
Views: 943
Reputation: 43499
When your Flink DataStream job fails to produce any output, the usual suspects are:
env.execute()
)TopLocations.print()
)Without more information it's difficult to guess which of these might be the problem in this case.
Upvotes: 1