【发布时间】:2019-12-14 03:15:44
【问题描述】:
我有以下形式的预订元素流:
Booking(id=B1, driverId=D1, time=t1, location=l1)
Booking(id=B2, driverId=D2, time=t2, location=l2)
我需要查找每个位置在过去 15 分钟内进行的预订计数。但是,应针对某个位置的任何新预订来评估该窗口。
大致如下:
Assuming `time` field is set as timestamp of record
bookingStream.keyBy(b=>b.location).window(Any window of 15mins).trigger(triggerFunction)
除了 trigger function should not be evaluated 在 15 分钟结束时,而是 whenever any booking arrives at a location 和 emit the count of booking in last 15min from timestamp of newly arrived booking。
方法:
使用 RichMap 函数,将位置预订的优先级队列维护为托管状态(ValueState),时间戳作为预订的优先级。对于每个到达的元素,首先将其添加到状态,然后从当前到达的元素中删除早于 15 分钟的元素。将优先级队列中剩余元素的计数发送给收集器。
这是正确的方法还是可以通过使用其他一些 flink 构造以更好的方式来实现。
【问题讨论】:
标签: apache-flink flink-streaming