Class EventTimeSessionWindows
- java.lang.Object
-
- org.apache.flink.streaming.api.windowing.assigners.WindowAssigner<T,W>
-
- org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner<Object,TimeWindow>
-
- org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows
-
- All Implemented Interfaces:
Serializable
@PublicEvolving public class EventTimeSessionWindows extends MergingWindowAssigner<Object,TimeWindow>
AWindowAssignerthat windows elements into sessions based on the timestamp of the elements. Windows cannot overlap.For example, in order to window into windows of 1 minute, every 10 seconds:
DataStream<Tuple2<String, Integer>> in = ...; KeyedStream<String, Tuple2<String, Integer>> keyed = in.keyBy(...); WindowedStream<Tuple2<String, Integer>, String, TimeWindows> windowed = keyed.window(EventTimeSessionWindows.withGap(Duration.ofMinutes(1)));- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner
MergingWindowAssigner.MergeCallback<W>
-
Nested classes/interfaces inherited from class org.apache.flink.streaming.api.windowing.assigners.WindowAssigner
WindowAssigner.WindowAssignerContext
-
-
Field Summary
Fields Modifier and Type Field Description protected longsessionTimeout
-
Constructor Summary
Constructors Modifier Constructor Description protectedEventTimeSessionWindows(long sessionTimeout)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Collection<TimeWindow>assignWindows(Object element, long timestamp, WindowAssigner.WindowAssignerContext context)Returns aCollectionof windows that should be assigned to the element.Trigger<Object,TimeWindow>getDefaultTrigger()Returns the default trigger associated with thisWindowAssigner.Trigger<Object,TimeWindow>getDefaultTrigger(StreamExecutionEnvironment env)Returns the default trigger associated with thisWindowAssigner.org.apache.flink.api.common.typeutils.TypeSerializer<TimeWindow>getWindowSerializer(org.apache.flink.api.common.ExecutionConfig executionConfig)Returns aTypeSerializerfor serializing windows that are assigned by thisWindowAssigner.booleanisEventTime()Returnstrueif elements are assigned to windows based on event time,falseotherwise.voidmergeWindows(Collection<TimeWindow> windows, MergingWindowAssigner.MergeCallback<TimeWindow> c)Merge overlappingTimeWindows.StringtoString()static <T> DynamicEventTimeSessionWindows<T>withDynamicGap(SessionWindowTimeGapExtractor<T> sessionWindowTimeGapExtractor)Creates a newSessionWindowsWindowAssignerthat assigns elements to sessions based on the element timestamp.static EventTimeSessionWindowswithGap(Duration size)Creates a newSessionWindowsWindowAssignerthat assigns elements to sessions based on the element timestamp.static EventTimeSessionWindowswithGap(Time size)Deprecated.
-
-
-
Method Detail
-
assignWindows
public Collection<TimeWindow> assignWindows(Object element, long timestamp, WindowAssigner.WindowAssignerContext context)
Description copied from class:WindowAssignerReturns aCollectionof windows that should be assigned to the element.- Specified by:
assignWindowsin classWindowAssigner<Object,TimeWindow>- Parameters:
element- The element to which windows should be assigned.timestamp- The timestamp of the element.context- TheWindowAssigner.WindowAssignerContextin which the assigner operates.
-
getDefaultTrigger
public Trigger<Object,TimeWindow> getDefaultTrigger(StreamExecutionEnvironment env)
Description copied from class:WindowAssignerReturns the default trigger associated with thisWindowAssigner.- Specified by:
getDefaultTriggerin classWindowAssigner<Object,TimeWindow>- See Also:
- FLIP-343: Remove parameter in WindowAssigner#getDefaultTrigger()
-
getDefaultTrigger
public Trigger<Object,TimeWindow> getDefaultTrigger()
Description copied from class:WindowAssignerReturns the default trigger associated with thisWindowAssigner.1. If you override
getDefaultTrigger(), thegetDefaultTrigger()will be invoked and thegetDefaultTrigger(StreamExecutionEnvironment env)won't be invoked. 2. If you don't overridegetDefaultTrigger(), thegetDefaultTrigger(StreamExecutionEnvironment env)will be invoked in the default implementation of thegetDefaultTrigger().- Overrides:
getDefaultTriggerin classWindowAssigner<Object,TimeWindow>
-
withGap
@Deprecated public static EventTimeSessionWindows withGap(Time size)
Deprecated.Creates a newSessionWindowsWindowAssignerthat assigns elements to sessions based on the element timestamp.- Parameters:
size- The session timeout, i.e. the time gap between sessions- Returns:
- The policy.
-
withGap
public static EventTimeSessionWindows withGap(Duration size)
Creates a newSessionWindowsWindowAssignerthat assigns elements to sessions based on the element timestamp.- Parameters:
size- The session timeout, i.e. the time gap between sessions- Returns:
- The policy.
-
withDynamicGap
@PublicEvolving public static <T> DynamicEventTimeSessionWindows<T> withDynamicGap(SessionWindowTimeGapExtractor<T> sessionWindowTimeGapExtractor)
Creates a newSessionWindowsWindowAssignerthat assigns elements to sessions based on the element timestamp.- Parameters:
sessionWindowTimeGapExtractor- The extractor to use to extract the time gap from the input elements- Returns:
- The policy.
-
getWindowSerializer
public org.apache.flink.api.common.typeutils.TypeSerializer<TimeWindow> getWindowSerializer(org.apache.flink.api.common.ExecutionConfig executionConfig)
Description copied from class:WindowAssignerReturns aTypeSerializerfor serializing windows that are assigned by thisWindowAssigner.- Specified by:
getWindowSerializerin classWindowAssigner<Object,TimeWindow>
-
isEventTime
public boolean isEventTime()
Description copied from class:WindowAssignerReturnstrueif elements are assigned to windows based on event time,falseotherwise.- Specified by:
isEventTimein classWindowAssigner<Object,TimeWindow>
-
mergeWindows
public void mergeWindows(Collection<TimeWindow> windows, MergingWindowAssigner.MergeCallback<TimeWindow> c)
Merge overlappingTimeWindows.- Specified by:
mergeWindowsin classMergingWindowAssigner<Object,TimeWindow>- Parameters:
windows- The window candidates.c- A callback that can be invoked to signal which windows should be merged.
-
-