[英]Apache Beam Session Windowing and joining across PCollections
我們有兩個具有相同鍵(userId)的事件流 S1 和 S2。 Is it possible to apply a session Window across both collections so that an occurrence of Key X in either stream would contribute to the session? 這會在 PCollections 中創建 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 代碼,請告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.