繁体   English   中英

Apache 光束窗口:考虑晚期数据但只发出一个窗格

[英]Apache beam windowing: consider late data but emit only one pane

当水印到达窗口末尾 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时发出单个窗格。

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

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

我首先要做的是将Window.ClosingBehavior设置为FIRE_ALWAYS 这样,当窗口永久关闭时,它将发送一个最终窗格(即使自上一个窗格以来没有延迟记录)并将PaneInfo.isLast设置为true

然后,我将继续第二个选项:

我可以在窗口末尾发出窗格,然后在收到延迟数据时再次发出窗格,但是在这种情况下,我不会发出单个窗格。

但是在下游丢弃不是最终的窗格,例如:

public void processElement(ProcessContext c) {
    if (c.pane().isLast) {
        c.output(c.element());
    }
}

暂无
暂无

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

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