Class WindowFn<T,W extends BoundedWindow>
- Type Parameters:
T- type of elements being windowedW-BoundedWindowsubclass 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
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.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassInformation available when runningassignWindows(org.apache.beam.sdk.transforms.windowing.WindowFn.AssignContext).classInformation available when runningmergeWindows(org.apache.beam.sdk.transforms.windowing.WindowFn.MergeContext). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if thisWindowFnalways 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 defaultWindowMappingFnto use to map main input windows to side input windows.Returns aTypeDescriptorcapturing what is known statically about the window type of thisWindowFninstance's most-derived class.abstract booleanisCompatible(WindowFn<?, ?> other) Deprecated.please override verifyCompatibility to throw a useful error message; we will remove isCompatible at version 3.0.0booleanReturns true if thisWindowFnnever needs to merge any windows.abstract voidDoes whatever merging of windows is necessary.voidpopulateDisplayData(DisplayData.Builder builder) Register display data for the given transform or component.voidverifyCompatibility(WindowFn<?, ?> other) ThrowIncompatibleWindowExceptionif this WindowFn does not perform the same merging as the given $WindowFn.Returns theCoderused 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
ThrowIncompatibleWindowExceptionif this WindowFn does not perform the same merging as the given $WindowFn.- Throws:
IncompatibleWindowException- if compared WindowFns are not compatible.
-
windowCoder
Returns theCoderused for serializing the windows used by this windowFn. -
getDefaultWindowMappingFn
Returns the defaultWindowMappingFnto use to map main input windows to side input windows. This should accept arbitrary main input windows, and produce aBoundedWindowthat can be produced by thisWindowFn. -
isNonMerging
public boolean isNonMerging()Returns true if thisWindowFnnever needs to merge any windows. -
assignsToOneWindow
public boolean assignsToOneWindow()Returns true if thisWindowFnalways 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 aTypeDescriptorcapturing what is known statically about the window type of thisWindowFninstance's most-derived class.In the normal case of a concrete
WindowFnsubclass 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:
populateDisplayDatain interfaceHasDisplayData- Parameters:
builder- The builder to populate with display data.- See Also:
-