[英]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.