Apache Beam - 如何从所有的窗口中通过键对PCollection<KV<String, Int>&gt进行求和。

问题描述 投票:1回答:2

给定一个 PCollection<KV<String, Int>> 定时窗口的情况下,如何才能将所有的 IntString 钥匙 窗口?

例如


PCollection<KV<String, Int>> pc = ...;  

pc.apply("FixedWindows", Window.<~>into(FixedWindows.of(WindowDuration)) // apply fixed windowing

我怎样才能在 全窗 在这个设置中,每个键都是如此?

我应该使用 Combine.GloballyAsSingletonView<InputT,OutputT> 如果是,我应该如何实现?

google-cloud-platform google-cloud-dataflow apache-beam dataflow apache-beam-pipeline
2个回答
0
投票

Combine总是在你所应用的窗口范围内进行。 如果要对所有元素进行求和,你需要先将窗口返回到GlobalWindows中


0
投票

其中一个选项,万一你没有太多不同的键,而且结果之和小于 Long.MAX_VALUE,您可以使用 光束指标譬如 Counter,为此。

© www.soinside.com 2019 - 2024. All rights reserved.