Google Cloud Dataflow SDK for Java, version 1.9.1
Class WindowFn<T,W extends BoundedWindow>
- java.lang.Object
-
- com.google.cloud.dataflow.sdk.transforms.windowing.WindowFn<T,W>
-
- Type Parameters:
T
- type of elements being windowedW
-BoundedWindow
subclass used to represent the windows used by thisWindowFn
- All Implemented Interfaces:
- HasDisplayData, Serializable
- Direct Known Subclasses:
- InvalidWindows, NonMergingWindowFn, Sessions
public abstract class WindowFn<T,W extends BoundedWindow> extends Object implements Serializable, HasDisplayData
The argument to theWindow
transform used to assign elements into windows and to determine how windows are merged. SeeWindow
for more information on howWindowFn
s are used and for a library of predefinedWindowFn
s.Users will generally want to use the predefined
WindowFn
s, 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 fromNonMergingWindowFn
instead. If no merging is required and each element is assigned to a single window, inherit fromPartitioningWindowFn
. Inheriting from the most specific subclass will enable more optimizations in the runner.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description class
WindowFn.AssignContext
Information available when runningassignWindows(com.google.cloud.dataflow.sdk.transforms.windowing.WindowFn<T, W>.AssignContext)
.class
WindowFn.MergeContext
Information available when runningmergeWindows(com.google.cloud.dataflow.sdk.transforms.windowing.WindowFn<T, W>.MergeContext)
.
-
Constructor Summary
Constructors Constructor and Description WindowFn()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description boolean
assignsToSingleWindow()
Returns true if thisWindowFn
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.ImplementgetOutputTimeFn()
to return one of the appropriateOutputTimeFns
, or a customOutputTimeFn
extendingOutputTimeFn.Defaults
.OutputTimeFn<? super W>
getOutputTimeFn()
Provides a default implementation forWindowingStrategy.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 givenWindowFn
.boolean
isNonMerging()
Returns true if thisWindowFn
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 theCoder
used for serializing the windows used by this windowFn.
-
-
-
Method Detail
-
assignWindows
public abstract Collection<W> assignWindows(WindowFn.AssignContext c) throws Exception
Given a timestamp and element, returns the set of windows into which it should be placed.- Throws:
Exception
-
mergeWindows
public abstract void mergeWindows(WindowFn.MergeContext c) throws Exception
Does whatever merging of windows is necessary.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.- Throws:
Exception
-
isCompatible
public abstract boolean isCompatible(WindowFn<?,?> other)
Returns whether this performs the same merging as the givenWindowFn
.
-
windowCoder
public abstract Coder<W> windowCoder()
Returns theCoder
used for serializing the windows used by this windowFn.
-
getSideInputWindow
public abstract W getSideInputWindow(BoundedWindow window)
Returns the window of the side input corresponding to the given window of the main input.Authors of custom
WindowFn
s should override this.
-
getOutputTime
@Deprecated @Experimental(value=OUTPUT_TIME) public Instant getOutputTime(Instant inputTimestamp, W window)
Deprecated. ImplementgetOutputTimeFn()
to return one of the appropriateOutputTimeFns
, or a customOutputTimeFn
extendingOutputTimeFn.Defaults
.
-
getOutputTimeFn
@Experimental(value=OUTPUT_TIME) public OutputTimeFn<? super W> getOutputTimeFn()
Provides a default implementation forWindowingStrategy.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 inOutputTimeFn.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()
.
-
isNonMerging
public boolean isNonMerging()
Returns true if thisWindowFn
never needs to merge any windows.
-
assignsToSingleWindow
public boolean assignsToSingleWindow()
Returns true if thisWindowFn
assigns each element to a single window.
-
populateDisplayData
public void populateDisplayData(DisplayData.Builder builder)
Register display data for the given transform or component.populateDisplayData(DisplayData.Builder)
is invoked by Pipeline runners to collect display data viaDisplayData.from(HasDisplayData)
. Implementations may callsuper.populateDisplayData(builder)
in order to register display data in the current namespace, but should otherwise usesubcomponent.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.
- Specified by:
populateDisplayData
in interfaceHasDisplayData
- Parameters:
builder
- The builder to populate with display data.- See Also:
HasDisplayData
-
-