Class SlidingWindows
- java.lang.Object
-
- org.apache.beam.sdk.transforms.windowing.WindowFn<T,W>
-
- org.apache.beam.sdk.transforms.windowing.NonMergingWindowFn<java.lang.Object,IntervalWindow>
-
- org.apache.beam.sdk.transforms.windowing.SlidingWindows
-
- All Implemented Interfaces:
java.io.Serializable
,HasDisplayData
public class SlidingWindows extends NonMergingWindowFn<java.lang.Object,IntervalWindow>
AWindowFn
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))));
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.beam.sdk.transforms.windowing.WindowFn
WindowFn.AssignContext, WindowFn.MergeContext
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
assignsToOneWindow()
Returns true if thisWindowFn
always assigns an element to exactly one window.java.util.Collection<IntervalWindow>
assignWindows(WindowFn.AssignContext c)
Given a timestamp and element, returns the set of windows into which it should be placed.java.util.Collection<IntervalWindow>
assignWindows(org.joda.time.Instant timestamp)
boolean
equals(@Nullable java.lang.Object object)
SlidingWindows
every(org.joda.time.Duration period)
Returns a newSlidingWindows
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 aWindowMappingFn
that returns the earliest window that contains the end of the main-input window.org.joda.time.Duration
getOffset()
org.joda.time.Duration
getPeriod()
org.joda.time.Duration
getSize()
int
hashCode()
boolean
isCompatible(WindowFn<?,?> other)
Returns whether this performs the same merging as the givenWindowFn
.static SlidingWindows
of(org.joda.time.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)
ThrowIncompatibleWindowException
if this WindowFn does not perform the same merging as the given $WindowFn
.Coder<IntervalWindow>
windowCoder()
Returns theCoder
used for serializing the windows used by this windowFn.SlidingWindows
withOffset(org.joda.time.Duration offset)
Assigns timestamps into half-open intervals of the form [N * period + offset, N * period + offset + size).-
Methods inherited from class org.apache.beam.sdk.transforms.windowing.NonMergingWindowFn
isNonMerging, mergeWindows
-
Methods inherited from class org.apache.beam.sdk.transforms.windowing.WindowFn
getWindowTypeDescriptor
-
-
-
-
Method Detail
-
of
public static SlidingWindows of(org.joda.time.Duration size)
Assigns timestamps into half-open intervals of the form [N * period, N * period + size), where 0 is the epoch.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.
-
every
public SlidingWindows every(org.joda.time.Duration period)
Returns a newSlidingWindows
with the original size, that assigns timestamps into half-open intervals of the form [N * period, N * period + size), where 0 is the epoch.
-
withOffset
public SlidingWindows withOffset(org.joda.time.Duration offset)
Assigns timestamps into half-open intervals of the form [N * period + offset, N * period + offset + size).- Throws:
java.lang.IllegalArgumentException
- if offset is not in [0, period)
-
windowCoder
public Coder<IntervalWindow> windowCoder()
Description copied from class:WindowFn
Returns theCoder
used for serializing the windows used by this windowFn.- Specified by:
windowCoder
in classWindowFn<java.lang.Object,IntervalWindow>
-
assignWindows
public java.util.Collection<IntervalWindow> assignWindows(WindowFn.AssignContext c)
Description copied from class:WindowFn
Given a timestamp and element, returns the set of windows into which it should be placed.- Specified by:
assignWindows
in classWindowFn<java.lang.Object,IntervalWindow>
-
assignWindows
public java.util.Collection<IntervalWindow> assignWindows(org.joda.time.Instant timestamp)
-
getDefaultWindowMappingFn
public WindowMappingFn<IntervalWindow> getDefaultWindowMappingFn()
Return aWindowMappingFn
that returns the earliest window that contains the end of the main-input window.- Specified by:
getDefaultWindowMappingFn
in classWindowFn<java.lang.Object,IntervalWindow>
-
isCompatible
public boolean isCompatible(WindowFn<?,?> other)
Description copied from class:WindowFn
Returns whether this performs the same merging as the givenWindowFn
.- Specified by:
isCompatible
in classWindowFn<java.lang.Object,IntervalWindow>
-
assignsToOneWindow
public boolean assignsToOneWindow()
Description copied from class:WindowFn
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.
- Overrides:
assignsToOneWindow
in classWindowFn<java.lang.Object,IntervalWindow>
-
verifyCompatibility
public void verifyCompatibility(WindowFn<?,?> other) throws IncompatibleWindowException
Description copied from class:WindowFn
ThrowIncompatibleWindowException
if this WindowFn does not perform the same merging as the given $WindowFn
.- Overrides:
verifyCompatibility
in classWindowFn<java.lang.Object,IntervalWindow>
- Throws:
IncompatibleWindowException
- if compared WindowFns are not compatible.
-
populateDisplayData
public void populateDisplayData(DisplayData.Builder builder)
Description copied from class:WindowFn
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
- Overrides:
populateDisplayData
in classWindowFn<java.lang.Object,IntervalWindow>
- Parameters:
builder
- The builder to populate with display data.- See Also:
HasDisplayData
-
getPeriod
public org.joda.time.Duration getPeriod()
-
getSize
public org.joda.time.Duration getSize()
-
getOffset
public org.joda.time.Duration getOffset()
-
equals
public boolean equals(@Nullable java.lang.Object object)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-