【问题标题】:How to use sliding window with Kafka Streams DSL?如何在 Kafka Streams DSL 中使用滑动窗口?
【发布时间】:2021-07-23 19:20:36
【问题描述】:

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

图片中我的情况:

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

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

【问题讨论】:

    标签: java apache-kafka apache-kafka-streams


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-10
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-30
      相关资源
      最近更新 更多