首页 > 解决方案 > Apache 光束窗口:考虑延迟数据但只发出一个窗格

问题描述

当水印在窗口结束后达到 x 分钟时,我想发出一个窗格。这让我确保我处理了一些迟到的数据,但仍然只发出一个窗格。我目前在java中工作。

目前我找不到解决这个问题的适当方法。当水印到达窗口末尾时,我可以发出一个窗格,但随后会丢弃任何迟到的数据。我可以在窗口末尾发出窗格,然后在收到迟到的数据时再次发出,但是在这种情况下,我不会发出单个窗格。

我目前有类似这样的代码:

.triggering(
    // This is going to emit the pane, but I don't want emit the pane yet!                                  
    AfterWatermark.pastEndOfWindow()

    // This is going to emit panes each time I receive late data, however 
    // I would like to only emit one pane at the end of the allowedLateness
).withAllowedLateness(allowedLateness).accumulatingFiredPanes())

如果仍然存在混淆,我只想在水印通过allowedLateness.

标签: javaapache-beamdataflowwindowing

解决方案


谢谢 Guillem,最后我用你的答案找到了这个非常有用的链接,里面有很多 apache 梁示例。由此我想出了以下解决方案:

 // We first specify to never emit any panes
 .triggering(Never.ever())

 // We then specify to fire always when closing the window. This will emit a
 // single final pane at the end of allowedLateness
 .withAllowedLateness(allowedLateness, Window.ClosingBehavior.FIRE_ALWAYS)
 .discardingFiredPanes())

推荐阅读