public class Sessions extends WindowFn<Object,IntervalWindow>
WindowFn windowing values into sessions separated by gapDuration-long
periods with no elements.
For example, in order to window data into session with at least 10 minute gaps in between them:
PCollection<Integer> pc = ...;
PCollection<Integer> windowed_pc = pc.apply(
Window.<Integer>into(Sessions.withGapDuration(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.
|
org.joda.time.Duration |
getGapDuration() |
org.joda.time.Instant |
getOutputTime(org.joda.time.Instant inputTimestamp,
IntervalWindow window)
Returns the output timestamp to use for data depending on the given
inputTimestamp
in the specified window. |
IntervalWindow |
getSideInputWindow(BoundedWindow window)
Returns the window of the side input corresponding to the given window of
the main input.
|
boolean |
isCompatible(WindowFn<?,?> other)
Returns whether this performs the same merging as the given
WindowFn. |
void |
mergeWindows(WindowFn.MergeContext c)
Does whatever merging of windows is necessary.
|
Coder<IntervalWindow> |
windowCoder()
Returns the
Coder used for serializing the windows used
by this windowFn. |
static Sessions |
withGapDuration(org.joda.time.Duration gapDuration)
Creates a
Sessions WindowFn with the specified gap duration. |
assignsToSingleWindow, isNonMergingpublic static Sessions withGapDuration(org.joda.time.Duration gapDuration)
Sessions WindowFn with the specified gap duration.public Collection<IntervalWindow> assignWindows(WindowFn.AssignContext c)
WindowFnassignWindows in class WindowFn<Object,IntervalWindow>public void mergeWindows(WindowFn.MergeContext c) throws Exception
WindowFnSee MergeOverlappingIntervalWindows.mergeWindows(com.google.cloud.dataflow.sdk.transforms.windowing.WindowFn<?, com.google.cloud.dataflow.sdk.transforms.windowing.IntervalWindow>.MergeContext) for an
example of how to override this method.
mergeWindows in class WindowFn<Object,IntervalWindow>Exceptionpublic Coder<IntervalWindow> windowCoder()
WindowFnCoder used for serializing the windows used
by this windowFn.windowCoder in class WindowFn<Object,IntervalWindow>public boolean isCompatible(WindowFn<?,?> other)
WindowFnWindowFn.isCompatible in class WindowFn<Object,IntervalWindow>public IntervalWindow getSideInputWindow(BoundedWindow window)
WindowFnAuthors of custom WindowFns should override this.
getSideInputWindow in class WindowFn<Object,IntervalWindow>public org.joda.time.Duration getGapDuration()
public org.joda.time.Instant getOutputTime(org.joda.time.Instant inputTimestamp,
IntervalWindow window)
WindowFninputTimestamp
in the specified window.
The result must be between inputTimestamp and window.maxTimestamp()
(inclusive on both sides). If this WindowFn doesn't produce overlapping windows,
this can (and typically should) just return inputTimestamp. If this does produce
overlapping windows, it is suggested that the result in later overlapping windows is
past the end of earlier windows so that the later windows don't prevent the watermark from
progressing past the end of the earlier window.
Each KV<K, Iterable<V>> produced from a GroupByKey will be output at a
timestamp that is the minimum of getOutputTime applied to the timestamp of all of
the non-late KV<K, V> that were used as input to the GroupByKey. The watermark
is also prevented from advancing past this minimum timestamp until after the
KV<K, Iterable<V>> has been output.
This function should be monotonic across input timestamps. Specifically, if A < B,
then getOutputTime(A, window) <= getOutputTime(B, window).
getOutputTime in class WindowFn<Object,IntervalWindow>