0

WindowFn入力エントリのタイムスタンプではなく、別のフィールドに基づいて入力要素に Windows を割り当てるような方法で別のものを作成したいと思います。WindowFnGoogle DataFlow SDK の事前定義された は、ウィンドウを割り当てる基準としてタイムスタンプを使用することを知っています。

より具体的には、SlidingWindowsタイムスタンプをウィンドウ割り当て基準と見なす代わりに、別のフィールドをその基準と見なしたいと思います。

カスタマイズした を作成するにはどうすればよいWindowFnですか? 自作するときのポイントはWindowFn

ありがとう。

4

1 に答える 1

2

新しい WindowFn を作成するには、WindowFnまたはサブクラスから継承し、さまざまな抽象メソッドをオーバーライドするだけです。

あなたの場合、ウィンドウのマージは必要ないため、NonMergingWindowFn から継承でき、コードは次のようになります。

public class MyWindowFn extends NonMergingWindowFn<ElementT, IntervalWindow> {
  public Collection<W> assignWindows(AssignContext c) {
    return setOfWindowsElementShouldBeIn(c.element());
  }

  public boolean isCompatible(WindowFn other) {
    return other instanceof MyWindowFn;
  }

  public Coder<IntervalWindow> windowCoder() {
    return IntervalWindow.getCoder();
  }

  public W getSideInputWindow(final BoundedWindow window) {
    // You may not need this if you won't ever be using PCollections windowed 
    // with this as side inputs.  If that's the case, just throw.
    // Otherwise you'll need to figure out how to map the main input windows
    // into the windows generated by this WindowFn.
  }
}
于 2016-06-20T17:52:22.220 に答える