检查是否通过水印传递窗口

时间:2016-03-09 13:42:29

标签: google-cloud-dataflow

如果我有这样的窗口:

.apply(Window
    .<String>into(Sessions
        .withGapDuration(Duration.standardSeconds(10)))
    .triggering(AfterWatermark
        .pastEndOfWindow()
        .withEarlyFirings(AfterPane.elementCountAtLeast(1))));

它接收数据:

a -> x (timestamp 0) (received at 20)
a -> y (timestamp 1) (received at 21)
(watermark passes 11) (at 22)

我认为窗口有时会触发:

  • 20秒,因为早期射击
  • 21秒,因为早期射击
  • 22秒,因为水印通过了GapDuration

在我应用于窗口数据的ParDo函数中,有没有办法区分早期触发和通过GapDuration的水印?

根据this stackoverflow question,无法获得水印。如果我能够做到这一点,我可以检查max(timestamp) < watermark。但由于我无法获得水印,有没有其他方法可以找出水印通过它触发窗口。

1 个答案:

答案 0 :(得分:1)

您可以通过调用ProcesContext#pane()PaneInfo之后访问DoFn中的GroupByKey元素,并使用它来确定Timing。这将允许您识别这是否是“准时”射击(由于水印通过窗口的末端)或投机/后期射击。