简体   繁体   English

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

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

I need to find the MAX value for a fixed period (for example, the last 7 days).我需要找到固定时间段(例如,过去 7 天)的 MAX 值。 In theory, the best way to resolve this task is the sliding window.理论上,解决这个任务的最好方法是滑动窗口。

My case in the picture:我在图片中的情况: 在此处输入图片说明

I tried to do it with SlidingWindows, but I couldn't write the aggregation function.我尝试用 SlidingWindows 来做,但我无法编写聚合函数。 I don't understand how to get access to values inside the window.我不明白如何访问窗口内的值。

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

I don't need a sliding window in my case.在我的情况下,我不需要滑动窗口。 I need a hopping window:我需要一个跳跃窗口:

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