GroupByKey returns Google 云数据流中没有元素

GroupByKey returns no elements in Google Cloud Dataflow

我是 Dataflow 的新手,所以这可能是一个简单的问题。

我想尝试 Sessions 窗口化策略。根据开窗文档,在我们完成 GroupByKey 之前不会应用开窗,所以我正在尝试这样做。

但是,当我在 Google Cloud Platform 中查看我的管道时,我可以看到 MapElements returns 个元素,但 GroupByKey ("Elements Added: -") 没有返回任何元素。按键分组时我做错了什么?

这是代码中最相关的部分:

events = events
  .apply(Window.named("eventsSessionsWindowing")
    .<MyEvent>into(Sessions.withGapDuration(Duration.standardSeconds(3)))
  );

PCollection<KV<String, MyEvent>> eventsKV = events
  .apply(MapElements
    .via((MyEvent e) -> KV.of(ExtractKey(e), e))
    .withOutputType(new TypeDescriptor<KV<String, MyEvent>>() {}));

PCollection<KV<String, Iterable<MyEvent>>> eventsGrouped = eventsKV.apply(GroupByKey.<String, MyEvent>create());

A GroupByKey 根据触发策略触发,该策略确定系统何时认为已收到此 key/window 的所有数据,以及何时将其分组并传递给下游转换。默认策略是:

The default trigger for a PCollection is event time-based, and emits the results of the window when the system's watermark (Dataflow's notion of when it "should" have all the data) passes the end of the window.

详情请见Default Trigger。您看到了几分钟的延迟,这与 PubSub 水印的进度相对应。