Class WindowFn<T,W extends BoundedWindow>
- Type Parameters:
T
- type of elements being windowedW
-BoundedWindow
subclass used to represent the windows used by thisWindowFn
- All Implemented Interfaces:
Serializable
,HasDisplayData
- Direct Known Subclasses:
NonMergingWindowFn
,Sessions
Window
transform used to assign elements into windows and to
determine how windows are merged. See Window
for more information on how
WindowFn
s 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.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Information available when runningassignWindows(org.apache.beam.sdk.transforms.windowing.WindowFn.AssignContext)
.class
Information available when runningmergeWindows(org.apache.beam.sdk.transforms.windowing.WindowFn.MergeContext)
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns true if thisWindowFn
always assigns an element to exactly one window.abstract Collection
<W> Given a timestamp and element, returns the set of windows into which it should be placed.abstract WindowMappingFn
<W> Returns the defaultWindowMappingFn
to use to map main input windows to side input windows.Returns aTypeDescriptor
capturing what is known statically about the window type of thisWindowFn
instance's most-derived class.abstract boolean
isCompatible
(WindowFn<?, ?> other) Deprecated.please override verifyCompatibility to throw a useful error message; we will remove isCompatible at version 3.0.0boolean
Returns true if thisWindowFn
never needs to merge any windows.abstract void
Does whatever merging of windows is necessary.void
populateDisplayData
(DisplayData.Builder builder) Register display data for the given transform or component.void
verifyCompatibility
(WindowFn<?, ?> other) ThrowIncompatibleWindowException
if this WindowFn does not perform the same merging as the given $WindowFn
.Returns theCoder
used for serializing the windows used by this windowFn.
-
Constructor Details
-
WindowFn
public WindowFn()
-
-
Method Details
-
assignWindows
Given a timestamp and element, returns the set of windows into which it should be placed.- Throws:
Exception
-
mergeWindows
Does whatever merging of windows is necessary.See
MergeOverlappingIntervalWindows.mergeWindows(org.apache.beam.sdk.transforms.windowing.WindowFn.MergeContext)
for an example of how to override this method.- Throws:
Exception
-
isCompatible
Deprecated.please override verifyCompatibility to throw a useful error message; we will remove isCompatible at version 3.0.0Returns whether this performs the same merging as the givenWindowFn
. -
verifyCompatibility
ThrowIncompatibleWindowException
if this WindowFn does not perform the same merging as the given $WindowFn
.- Throws:
IncompatibleWindowException
- if compared WindowFns are not compatible.
-
windowCoder
Returns theCoder
used for serializing the windows used by this windowFn. -
getDefaultWindowMappingFn
Returns the defaultWindowMappingFn
to use to map main input windows to side input windows. This should accept arbitrary main input windows, and produce aBoundedWindow
that can be produced by thisWindowFn
. -
isNonMerging
public boolean isNonMerging()Returns true if thisWindowFn
never needs to merge any windows. -
assignsToOneWindow
public boolean assignsToOneWindow()Returns true if thisWindowFn
always assigns an element to exactly one window.If this varies per-element, or cannot be determined, conservatively return false.
By default, returns false.
-
getWindowTypeDescriptor
Returns aTypeDescriptor
capturing what is known statically about the window type of thisWindowFn
instance's most-derived class.In the normal case of a concrete
WindowFn
subclass with no generic type parameters of its own (including anonymous inner classes), this will be a complete non-generic type. -
populateDisplayData
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:
-