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, HasDisplayData
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(org.apache.beam.sdk.transforms.windowing.WindowFn<T, W>.AssignContext). |
class |
WindowFn.MergeContext
Information available when running
mergeWindows(org.apache.beam.sdk.transforms.windowing.WindowFn<T, W>.MergeContext). |
| Constructor and Description |
|---|
WindowFn() |
| Modifier and Type | Method and Description |
|---|---|
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)
Returns the output timestamp to use for data depending on the given
inputTimestamp in the specified window. |
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.
|
void |
populateDisplayData(DisplayData.Builder builder)
Register display data for the given transform or component.
|
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(org.apache.beam.sdk.transforms.windowing.WindowFn<?, org.apache.beam.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.
@Experimental(value=OUTPUT_TIME) public Instant getOutputTime(Instant inputTimestamp, W window)
inputTimestamp in the specified window.
The result of this method must be between inputTimestamp and
window.maxTimestamp() (inclusive on both sides).
This function must be monotonic across input timestamps. Specifically, if A < B,
then getOutputTime(A, window) <= getOutputTime(B, window).
For a WindowFn that doesn't produce overlapping windows, this can (and typically
should) just return inputTimestamp. In the presence of overlapping windows, 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.
public boolean isNonMerging()
WindowFn never needs to merge any windows.public void populateDisplayData(DisplayData.Builder builder)
populateDisplayData(DisplayData.Builder) is invoked by Pipeline runners to collect
display data via DisplayData.from(HasDisplayData). Implementations may call
super.populateDisplayData(builder) in order to register display data in the current
namespace, but should otherwise use subcomponent.populateDisplayData(builder) to use
the namespace of the subcomponent.
By default, does not register any display data. Implementors may override this method to provide their own display data.
populateDisplayData in interface HasDisplayDatabuilder - The builder to populate with display data.HasDisplayData