Google Cloud Dataflow窗口化数据和分组

时间:2019-05-21 08:03:05

标签: google-cloud-dataflow apache-beam dataflow apache-beam-io

我有一个管道,该管道从PubSub获取事件流,应用一个1h窗口,然后将其写入Google Cloud Storage上的文件中。最近,我意识到有时在1h窗口中发生太多事件,因此我还添加了一个触发器,如果​​窗格中有超过100k事件,则触发该事件。现在的问题是,仅当窗口内的单个组超过了该数目而不是整个管道时才触发100k限制。

管道的相关部分如下所示:

PCollection<String> rawEvents = pipeline
   .apply("Read PubSub Events",
       PubsubIO.readStrings()
               .fromSubscription(options.getInputSubscription()));

rawEvents
   .apply("1h Window",
       Window.<String>into(FixedWindows.of(Duration.standardHours(1))
          .triggering(
              Repeatedly
                 .forever(
                    AfterFirst.of(
                       AfterPane.elementCountAtLeast(100000),
                       AfterWatermark.pastEndOfWindow())))
                 .discardingFiredPanes()
                 .withAllowedLateness(Duration.standardDays(7), 
              Window.ClosingBehavior.FIRE_IF_NON_EMPTY)
          .withOnTimeBehavior(Window.OnTimeBehavior.FIRE_IF_NON_EMPTY))
   .apply("Write File(s)", new WriteFiles(options, new EventPartitioner()));

WriteFiles组件是一个PTransform,它会扩展为FileIO.Write,并通过一个键对元素进行分组。

我该如何做,以便在管道中总共有100k个事件而不是特定组的100k个事件触发窗口?预先感谢!

0 个答案:

没有答案