public class SlidingWindows extends NonMergingWindowFn<java.lang.Object,IntervalWindow>
WindowFn that windows values into possibly overlapping fixed-size timestamp-based
windows.
For example, in order to window data into 10 minute windows that update every minute:
PCollection<Integer> items = ...;
PCollection<Integer> windowedItems = items.apply(
Window.<Integer>into(SlidingWindows.of(Duration.standardMinutes(10))));
WindowFn.AssignContext, WindowFn.MergeContext| Modifier and Type | Method and Description |
|---|---|
boolean |
assignsToOneWindow()
Returns true if this
WindowFn always assigns an element to exactly one window. |
java.util.Collection<IntervalWindow> |
assignWindows(Instant timestamp) |
java.util.Collection<IntervalWindow> |
assignWindows(WindowFn.AssignContext c)
Given a timestamp and element, returns the set of windows into which it should be placed.
|
boolean |
equals(java.lang.Object object) |
SlidingWindows |
every(Duration period)
Returns a new
SlidingWindows with the original size, that assigns timestamps into
half-open intervals of the form [N * period, N * period + size), where 0 is the epoch. |
WindowMappingFn<IntervalWindow> |
getDefaultWindowMappingFn()
Return a
WindowMappingFn that returns the earliest window that contains the end of the
main-input window. |
Duration |
getOffset() |
Instant |
getOutputTime(Instant inputTimestamp,
IntervalWindow window)
Ensures that later sliding windows have an output time that is past the end of earlier windows.
|
Duration |
getPeriod() |
Duration |
getSize() |
int |
hashCode() |
boolean |
isCompatible(WindowFn<?,?> other)
Returns whether this performs the same merging as the given
WindowFn. |
static SlidingWindows |
of(Duration size)
Assigns timestamps into half-open intervals of the form [N * period, N * period + size), where
0 is the epoch.
|
void |
populateDisplayData(DisplayData.Builder builder)
Register display data for the given transform or component.
|
void |
verifyCompatibility(WindowFn<?,?> other)
Throw
IncompatibleWindowException if this WindowFn does not perform the same merging as
the given $WindowFn. |
Coder<IntervalWindow> |
windowCoder()
Returns the
Coder used for serializing the windows used by this windowFn. |
SlidingWindows |
withOffset(Duration offset)
Assigns timestamps into half-open intervals of the form [N * period + offset, N * period +
offset + size).
|
isNonMerging, mergeWindowsgetWindowTypeDescriptorpublic static SlidingWindows of(Duration size)
If every(org.joda.time.Duration) is not called, the period defaults to the largest time unit
smaller than the given duration. For example, specifying a size of 5 seconds will result in a
default period of 1 second.
public SlidingWindows every(Duration period)
SlidingWindows with the original size, that assigns timestamps into
half-open intervals of the form [N * period, N * period + size), where 0 is the epoch.public SlidingWindows withOffset(Duration offset)
java.lang.IllegalArgumentException - if offset is not in [0, period)public Coder<IntervalWindow> windowCoder()
WindowFnCoder used for serializing the windows used by this windowFn.windowCoder in class WindowFn<java.lang.Object,IntervalWindow>public java.util.Collection<IntervalWindow> assignWindows(WindowFn.AssignContext c)
WindowFnassignWindows in class WindowFn<java.lang.Object,IntervalWindow>public java.util.Collection<IntervalWindow> assignWindows(Instant timestamp)
public WindowMappingFn<IntervalWindow> getDefaultWindowMappingFn()
WindowMappingFn that returns the earliest window that contains the end of the
main-input window.getDefaultWindowMappingFn in class WindowFn<java.lang.Object,IntervalWindow>public boolean isCompatible(WindowFn<?,?> other)
WindowFnWindowFn.isCompatible in class WindowFn<java.lang.Object,IntervalWindow>public boolean assignsToOneWindow()
WindowFnWindowFn always assigns an element to exactly one window.
If this varies per-element, or cannot be determined, conservatively return false.
By default, returns false.
assignsToOneWindow in class WindowFn<java.lang.Object,IntervalWindow>public void verifyCompatibility(WindowFn<?,?> other) throws IncompatibleWindowException
WindowFnIncompatibleWindowException if this WindowFn does not perform the same merging as
the given $WindowFn.verifyCompatibility in class WindowFn<java.lang.Object,IntervalWindow>IncompatibleWindowException - if compared WindowFns are not compatible.public void populateDisplayData(DisplayData.Builder builder)
WindowFnpopulateDisplayData(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 HasDisplayDatapopulateDisplayData in class WindowFn<java.lang.Object,IntervalWindow>builder - The builder to populate with display data.HasDisplayDatapublic Duration getPeriod()
public Duration getSize()
public Duration getOffset()
@Experimental(value=OUTPUT_TIME) public Instant getOutputTime(Instant inputTimestamp, IntervalWindow window)
If this is the earliest sliding window containing inputTimestamp, that's fine.
Otherwise, we pick the earliest time that doesn't overlap with earlier windows.
getOutputTime in class WindowFn<java.lang.Object,IntervalWindow>public boolean equals(java.lang.Object object)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object