我如何让GroupByKey触发早期结果,而不是等待所有数据到达(在我的情况下是相当长的时间)。我试图通过早期触发将输入的PCollection拆分为多个窗口,但实际上并没有。工作。在给出结果之前,它仍然等待所有数据到达。
PCollection<List<String>> input = ...
PCollection<KV<Integer,List<String>>> keyedInput = input.apply(ParDo.of(new AddArbitraryKey()))
keyedInput.apply(Window<KV<Integer,List<String>>>into(
FixedWindows.of(Duration.standardSeconds(1)))
.triggering(Repeatedly.forever(AfterWatermark.pastEndOfWindow()))
.withAllowedLateness(Duration.ZERO).discardingFiredPanes())
.apply(GroupByKey.<Integer,List<String>>create())
.apply(ParDo.of(new RemoveArbitraryKey()))
.apply(ParDo.of(new FurtherProcessing())
我这样做是为了防止fusing。 AddArbitraryKey转换使用时间戳输出其元素。但是,GroupByKey保留所有内容,直到所有数据到达(对于所有窗口)为止。有人可以告诉我如何使它尽早触发。谢谢 。
最佳答案
您可以安装类似的触发器
Repeatedly
.forever(AfterProcessingTime
.pastFirstElementInPane()
.plusDuration(Duration.standardMinutes(1))
.orFinally(AfterWatermark.pastEndOfWindow())
.discardingFiredPanes()
要么
AfterWatermark.pastEndOfWindow()
.withEarlyFirings(
AfterProcessingTime
.pastFirstElementInPane()
.plusDuration(Duration.standardMinutes(1))