apachebeam中基于元组的google云数据流窗口

flvlnr44  于 2021-06-25  发布在  Flink
关注(0)|答案(1)|浏览(442)

如何在apachebeam中创建基于元组的滑动窗口?这在Flink很容易做到:

  1. DataStream.countWindowAll(long size, long slide)

但beam(或dataflow)的文档还不清楚如何做到这一点。是窗口和触发器的组合吗?效率高吗?

kgsdhlau

kgsdhlau1#

滑动窗本身由梁支撑。请参阅slidingwindows类的编程指南和文档。
例如。:

  1. PCollection<Foo> foos = ...;
  2. PCollection<Integer> counts = foos
  3. .apply(Window.into(
  4. SlidingWindows.of(Duration.standardMinutes(5))
  5. .every(Duration.standardMinutes(1))))
  6. // Below is required instead of Count.globally() when you use
  7. // a non-global windowing function.
  8. .apply(Combine.globally(Count.<Foo>combineFn()).withoutDefaults());
  9. PCollection<String> formattedCounts = counts.apply(
  10. ParDo.of(new DoFn<Integer, String>() {
  11. @ProcessElement
  12. public void process(ProcessContext c, BoundedWindow w) {
  13. c.output("Window: " + w + ", count: " + c.element());
  14. }
  15. }));

触发是问题的一个独立维度,它控制特定窗口的数据何时被认为“足够完整”以应用聚合。请参阅编程指南。

展开查看全部

相关问题