最近看了很多文章,包括官方文档,想了解全局窗口在Apache Beam中是如何工作的。我在 Stackoverflow 中阅读过类似的问题,但我无法理解。
根据官方文档:
You can use the single global window if you are working with an unbounded data set (e.g. from a streaming data source) but use caution when applying aggregating transforms such as GroupByKey and Combine. The single global window with a default trigger generally requires the entire data set to be available before processing, which is not possible with continuously updating data.
因此,全局窗口没有结尾,而且它是全局的,因此很有意义。文档建议在进行聚合时使用非默认触发器,因为默认触发器是在窗口关闭时触发 Pane :
Set a non-default trigger. This allows the global window to emit results under other conditions, since the default windowing behavior (waiting for all data to arrive) will never occur.
我对此感到困惑。这里的逻辑是全局窗口将无法将事件触发到管道的下一步,因为它永远不会结束,因此默认触发器永远不会发生。但是,这不是真实场景中发生的情况。如果我从具有全局窗口的无界 PCollection 中读取,事件仍会被推送到下游。
有人可以向我澄清这个问题吗?带有默认触发器的默认全局窗口如何在 Apache Beam 中用于无界 pcollections?我假设它根本不聚合结果,只是在事件到达时一个一个地处理它们。我想确定是否是这种情况。
最佳答案
默认触发器是在水印根据事件时间到达Window
末尾时触发。 GlobalWindow
永远不会发生这种情况,因此如果您使用 GlobalWindow
,则永远不会触发默认触发器。
但是如果你设置了一个非默认触发器,例如在处理了一定数量的元素后触发(使用 AfterCount
触发器),你的元素甚至可以为 全局窗口
。参见 here有关 Beam 触发器的更多信息。
关于google-cloud-platform - Apache Beam 中无限 pcollection 的全局窗口的默认行为是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67539285/