简体   繁体   中英

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). 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. 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()))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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