繁体   English   中英

如何在 Kafka Streams DSL 中使用滑动窗口?

[英]How to use sliding window with Kafka Streams DSL?

我需要找到固定时间段(例如,过去 7 天)的 MAX 值。 理论上,解决这个任务的最好方法是滑动窗口。

我在图片中的情况: 在此处输入图片说明

我尝试用 SlidingWindows 来做,但我无法编写聚合函数。 我不明白如何访问窗口内的值。

input
   .groupByKey()
   .windowedBy(SlidingWindows.withTimeDifferenceAndGrace(Duration.ofDays(7), Duration.ZERO))
   .reduce(Math::max) // I thinks this is mistake

在我的情况下,我不需要滑动窗口。 我需要一个跳跃窗口:

input
                        .groupByKey()
                        .windowedBy(
                                TimeWindows.of(Duration.ofDays(1)).advanceBy(Duration.ofHours(1)))
                        .reduce(Math::max)
.suppress(Suppressed.untilWindowCloses(Suppressed.BufferConfig.unbounded()))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM