如何获取当前滑动窗口的最大时间戳

use*_*240 0 google-cloud-dataflow

我正在使用 X 大小和 Y 周期的滑动时间窗口。为了标记每个窗口的输出,我想获取PCollection当前窗口的时间戳。

    PCollection<T> windowedInput = input
      .apply(Window<T>into(
          SlidingWindows.of(Duration.standardMinutes(10))
                        .every(Duration.standardMinutes(1))));

   // Extract key from each input and run a function per group.
   //
   // Q: ExtractKey() depends on the window triggered time.
   //    How can I pass the timestamp of windowedInputs to ExtractKey()?
   PCollection<KV<K, Iterable<T>>> groupedInputs = windowedInputs
     .apply(ParDo.of(new ExtractKey()))
     .apply(GroupByKey.<K, Ts>create());

   // Run Story clustering and write outputs.
   //
   // Q: Also I'd like to add a window timestamp suffix to the output.
   //    How can I pass (or get) the timestamp to SomeDoFn()?
   PCollection<String> results = groupedInputs.apply(ParDo.of(new SomeDoFn()));
Run Code Online (Sandbox Code Playgroud)

jkf*_*kff 5

DoFn允许A通过方法BoundedWindow上的可选参数访问当前元素的窗口@ProcessElement

class SomeDoFn extends DoFn<KV<K, Iterable<T>>, String> {
  @ProcessElement
  public void process(ProcessContext c, BoundedWindow window) {
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)