設置在事件時間的定時器和接收回調的一般能力確實是一個重要的特徵請求日提交的作爲BEAM-27,這是正在積極開發。
但是實際上,您使用僅僅使用Dataflow Java SDK 1.x的功能來加入FixedWindows.of(Duration.standardDays(1))
的方法似乎可以實現您的目標。您可以通過添加觸發器AfterPane.elementCountAtLeast(1)
來維持「流水線」行爲,而不是分叉管道。它會產生GroupByKey
的成本,但不會重複任何操作。
完整的管道可能是這樣的:
pipeline
// Read your data from Cloud Pubsub and parse to MyValue
.apply(PubsubIO.Read.topic(...).withCoder(MyValueCoder.of())
// You'll need some keys
.apply(WithKeys.<MyKey, MyValue>of(...))
// Window into daily windows, but still output as fast as possible
.apply(Window.into(FixedWindows.of(Duration.standardDays(1)))
.triggering(AfterPane.elementCountAtLeast(1)))
// GroupByKey adds the necessary EARLY/ON_TIME/LATE labeling
.apply(GroupByKey.<MyKey, MyValue>create())
// Convert KV<MyKey, Iterable<MyValue>>
// to KV<ByteString, Iterable<Mutation>>
// where the iterable of mutations has the "end of day" marker if
// it was ON_TIME
.apply(MapElements.via(new MessageToMutationWithEndOfWindow())
// Write it!
.apply(BigTableIO.Write.to(...);
請做我的答案評論,如果我錯過了你的使用情況的一些細節。