Apache Beam 会话窗口化和跨 PCollections 加入

Apache Beam Session Windowing and joining across PCollections

我们有两个具有相同键 (userId) 的事件流 S1 和 S2。是否可以在两个集合中应用会话 Window,以便任一流中出现的密钥 X 都会对会话有所贡献?这会在 PC 集合中创建 Windows 让我们之后加入这些集合吗?

对于上下文:

非常感谢!

这是正确的 - 您可以这样做,因为 windows 在您执行分组操作时发挥作用。这意味着您可以像这样简单地做一些事情:

p = beam.Pipeline(...)

# Assume that timestamp information is already in the streams
first_stream = p | ReadMyFirstStream() | beam.WindowInto(window.Sessions(...))
second_stream = p | ReadMySecondStream() | beam.WindowInto(window.Sessions(...))

joined_streams = (
    {'first': first_stream,
     'second': second_stream}
    | beam.CoGroupByKey())

加入的流 PCollection 将生成 windows,其中来自两个流的元素组合在一起。


这也适用于 Java。为了简单起见,我使用 Python 回答。如果您更喜欢 Java 代码,请告诉我。