public class SlidingWindows extends NonMergingWindowFn<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 |
|---|---|
Collection<IntervalWindow> |
assignWindows(WindowFn.AssignContext c)
Given a timestamp and element, returns the set of windows into which it
should be placed.
|
SlidingWindows |
every(org.joda.time.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. |
org.joda.time.Duration |
getOffset() |
org.joda.time.Instant |
getOutputTime(org.joda.time.Instant inputTimestamp,
IntervalWindow window)
Ensure that later sliding windows have an output time that is past the end of earlier windows.
|
org.joda.time.Duration |
getPeriod() |
IntervalWindow |
getSideInputWindow(BoundedWindow window)
Return the earliest window that contains the end of the main-input window.
|
org.joda.time.Duration |
getSize() |
boolean |
isCompatible(WindowFn<?,?> other)
Returns whether this performs the same merging as the given
WindowFn. |
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.
|
Coder<IntervalWindow> |
windowCoder()
Returns the
Coder 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).
|
isNonMerging, mergeWindowsassignsToSingleWindowpublic static SlidingWindows of(org.joda.time.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(org.joda.time.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(org.joda.time.Duration offset)
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<Object,IntervalWindow>public Collection<IntervalWindow> assignWindows(WindowFn.AssignContext c)
WindowFnassignWindows in class WindowFn<Object,IntervalWindow>public IntervalWindow getSideInputWindow(BoundedWindow window)
getSideInputWindow in class WindowFn<Object,IntervalWindow>public boolean isCompatible(WindowFn<?,?> other)
WindowFnWindowFn.isCompatible in class WindowFn<Object,IntervalWindow>public org.joda.time.Duration getPeriod()
public org.joda.time.Duration getSize()
public org.joda.time.Duration getOffset()
public org.joda.time.Instant getOutputTime(org.joda.time.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<Object,IntervalWindow>