T - type of elements being windowedW - BoundedWindow subclass used to represent the
windows used by this WindowFnpublic abstract class WindowFn<T,W extends BoundedWindow> extends Object implements Serializable
Window transform used to assign elements into
windows and to determine how windows are merged. See Window for more
information on how WindowFns are used and for a library of
predefined WindowFns.
Users will generally want to use the predefined
WindowFns, but it is also possible to create new
subclasses.
To create a custom WindowFn, inherit from this class and override all required
methods. If no merging is required, inherit from NonMergingWindowFn
instead. If no merging is required and each element is assigned to a single window, inherit from
PartitioningWindowFn. Inheriting from the most specific subclass will enable more
optimizations in the runner.
| Modifier and Type | Class and Description |
|---|---|
class |
WindowFn.AssignContext
Information available when running
assignWindows(com.google.cloud.dataflow.sdk.transforms.windowing.WindowFn<T, W>.AssignContext). |
class |
WindowFn.MergeContext
Information available when running
mergeWindows(com.google.cloud.dataflow.sdk.transforms.windowing.WindowFn<T, W>.MergeContext). |
| Constructor and Description |
|---|
WindowFn() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
assignsToSingleWindow()
Returns true if this
WindowFn assigns each element to a single window. |
abstract Collection<W> |
assignWindows(WindowFn.AssignContext c)
Given a timestamp and element, returns the set of windows into which it
should be placed.
|
Instant |
getOutputTime(Instant inputTimestamp,
W window)
Deprecated.
Implement
getOutputTimeFn() to return either the appropriate
ElementaryOutputTimeFn or a custom OutputTimeFn extending
OutputTimeFn.Defaults. |
OutputTimeFn<? super W> |
getOutputTimeFn()
Provides a default implementation for
WindowingStrategy.getOutputTimeFn(). |
abstract W |
getSideInputWindow(BoundedWindow window)
Returns the window of the side input corresponding to the given window of
the main input.
|
abstract boolean |
isCompatible(WindowFn<?,?> other)
Returns whether this performs the same merging as the given
WindowFn. |
boolean |
isNonMerging()
Returns true if this
WindowFn never needs to merge any windows. |
abstract void |
mergeWindows(WindowFn.MergeContext c)
Does whatever merging of windows is necessary.
|
abstract Coder<W> |
windowCoder()
Returns the
Coder used for serializing the windows used
by this windowFn. |
public abstract Collection<W> assignWindows(WindowFn.AssignContext c) throws Exception
Exceptionpublic abstract void mergeWindows(WindowFn.MergeContext c) throws Exception
See MergeOverlappingIntervalWindows.mergeWindows(com.google.cloud.dataflow.sdk.transforms.windowing.WindowFn<?, com.google.cloud.dataflow.sdk.transforms.windowing.IntervalWindow>.MergeContext) for an
example of how to override this method.
Exceptionpublic abstract boolean isCompatible(WindowFn<?,?> other)
WindowFn.public abstract Coder<W> windowCoder()
Coder used for serializing the windows used
by this windowFn.public abstract W getSideInputWindow(BoundedWindow window)
Authors of custom WindowFns should override this.
@Deprecated @Experimental(value=OUTPUT_TIME) public Instant getOutputTime(Instant inputTimestamp, W window)
getOutputTimeFn() to return either the appropriate
ElementaryOutputTimeFn or a custom OutputTimeFn extending
OutputTimeFn.Defaults.@Experimental(value=OUTPUT_TIME) public OutputTimeFn<? super W> getOutputTimeFn()
WindowingStrategy.getOutputTimeFn().
See the full specification there.
If this WindowFn doesn't produce overlapping windows, this need not (and probably
should not) override any of the default implementations in OutputTimeFn.Defaults.
If this WindowFn does produce overlapping windows that can be predicted here, it is
suggested that the result in later overlapping windows is past the end of earlier windows so
that the later windows don't prevent the watermark from progressing past the end of the earlier
window.
For example, a timestamp in a sliding window should be moved past the beginning of the next
sliding window. See SlidingWindows.getOutputTimeFn().
public boolean isNonMerging()
WindowFn never needs to merge any windows.public boolean assignsToSingleWindow()
WindowFn assigns each element to a single window.