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(@Nullable 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() |
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, mergeWindows
getWindowTypeDescriptor
public 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()
WindowFn
Coder
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)
WindowFn
assignWindows
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)
WindowFn
WindowFn
.isCompatible
in class WindowFn<java.lang.Object,IntervalWindow>
public boolean assignsToOneWindow()
WindowFn
WindowFn
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
WindowFn
IncompatibleWindowException
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)
WindowFn
populateDisplayData(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 HasDisplayData
populateDisplayData
in class WindowFn<java.lang.Object,IntervalWindow>
builder
- The builder to populate with display data.HasDisplayData
public Duration getPeriod()
public Duration getSize()
public Duration getOffset()
public boolean equals(@Nullable java.lang.Object object)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object