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.
|
boolean |
equals(Object object) |
Duration |
getGapDuration() |
OutputTimeFn<? super IntervalWindow> |
getOutputTimeFn()
Provides a default implementation for
WindowingStrategy.getOutputTimeFn() . |
IntervalWindow |
getSideInputWindow(BoundedWindow window)
Returns the window of the side input corresponding to the given window of
the main input.
|
int |
hashCode() |
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.
|
void |
populateDisplayData(DisplayData.Builder builder)
Register display data for the given transform or component.
|
Coder<IntervalWindow> |
windowCoder()
Returns the
Coder used for serializing the windows used
by this windowFn. |
static Sessions |
withGapDuration(Duration gapDuration)
Creates a
Sessions WindowFn with the specified gap duration. |
assignsToSingleWindow, getOutputTime, isNonMerging
public static Sessions withGapDuration(Duration gapDuration)
Sessions
WindowFn
with the specified gap duration.public Collection<IntervalWindow> assignWindows(WindowFn.AssignContext c)
WindowFn
assignWindows
in class WindowFn<Object,IntervalWindow>
public void mergeWindows(WindowFn.MergeContext c) throws Exception
WindowFn
See 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>
Exception
public Coder<IntervalWindow> windowCoder()
WindowFn
Coder
used for serializing the windows used
by this windowFn.windowCoder
in class WindowFn<Object,IntervalWindow>
public boolean isCompatible(WindowFn<?,?> other)
WindowFn
WindowFn
.isCompatible
in class WindowFn<Object,IntervalWindow>
public IntervalWindow getSideInputWindow(BoundedWindow window)
WindowFn
Authors of custom WindowFn
s should override this.
getSideInputWindow
in class WindowFn<Object,IntervalWindow>
@Experimental(value=OUTPUT_TIME) public OutputTimeFn<? super IntervalWindow> getOutputTimeFn()
WindowFn
WindowingStrategy.getOutputTimeFn()
.
See the full specification there.
If this WindowFn
doesn't produce overlapping windows, this need not (and probably
should not) override any of the default implementations in OutputTimeFn.Defaults
.
If this WindowFn
does produce overlapping windows that can be predicted here, 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.
For example, a timestamp in a sliding window should be moved past the beginning of the next
sliding window. See SlidingWindows.getOutputTimeFn()
.
getOutputTimeFn
in class WindowFn<Object,IntervalWindow>
public Duration getGapDuration()
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<Object,IntervalWindow>
builder
- The builder to populate with display data.HasDisplayData