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.
TODO: Describe how to properly create WindowFns.
| 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.
|
abstract org.joda.time.Instant |
getOutputTime(org.joda.time.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.
|
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.
public abstract org.joda.time.Instant getOutputTime(org.joda.time.Instant inputTimestamp,
W window)
inputTimestamp
in the specified window.
The result must be between inputTimestamp and window.maxTimestamp()
(inclusive on both sides). If this WindowFn doesn't produce overlapping windows,
this can (and typically should) just return inputTimestamp. If this does produce
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.
Each KV<K, Iterable<V>> produced from a GroupByKey will be output at a
timestamp that is the minimum of getOutputTime applied to the timestamp of all of
the non-late KV<K, V> that were used as input to the GroupByKey. The watermark
is also prevented from advancing past this minimum timestamp until after the
KV<K, Iterable<V>> has been output.
This function should be monotonic across input timestamps. Specifically, if A < B,
then getOutputTime(A, window) <= getOutputTime(B, window).
public boolean isNonMerging()
WindowFn never needs to merge any windows.public boolean assignsToSingleWindow()
WindowFn assigns each element to a single window.