Class WindowStrategy
java.lang.Object
org.apache.flink.datastream.api.extension.window.strategy.WindowStrategy
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
GlobalWindowStrategy,SessionWindowStrategy,SlidingTimeWindowStrategy,TumblingTimeWindowStrategy
This class describes what kind of Windows to use, including strategies for dividing, triggering,
and clearing Windows.
We currently provide three built-in window types: Global Window, Time Window, and Session Window.
- Global Window: All the data is in a single window. There is only one Global Window, and all data is assigned to this single window. Global Window are suitable for bounded stream scenarios and can be used in GlobalStream, KeyedStream, and NonKeyedStream.
- Time Window: Data within a specific time period is assigned to a single window. Time Windows are divided into multiple windows based on time ranges, and data is assigned to the corresponding window based on its timestamp. We support two types of time windows: tumbling windows and sliding windows, and the tumbling windows cannot overlap. The time semantics within the windows can be divided into event time and processing time. Time Window can be used in GlobalStream and KeyedStream.
- Session Window: Consecutive data is assigned to a single window. Session windows are a special type of time window and are divided into multiple windows based on time ranges. When data arrives, it is first assigned to the corresponding window based on its timestamp, and then existing windows are merged as much as possible. Session Window can be used in GlobalStream and KeyedStream.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe types of time used in window operations. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final WindowStrategy.TimeTypestatic final WindowStrategy.TimeType -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic WindowStrategyglobal()Creates a global window strategy.static WindowStrategyCreate a session time window strategy with the event time default time type.static WindowStrategysession(Duration sessionGap, WindowStrategy.TimeType timeType) Create a session time window strategy.static WindowStrategyCreate a sliding time window strategy with the event time default time type.static WindowStrategysliding(Duration windowSize, Duration windowSlideInterval, WindowStrategy.TimeType timeType) Create a sliding time window strategy.static WindowStrategysliding(Duration windowSize, Duration windowSlideInterval, WindowStrategy.TimeType timeType, Duration allowedLateness) Create a sliding time window strategy.static WindowStrategyCreate a tumbling time window strategy with the event time default time type.static WindowStrategytumbling(Duration windowSize, WindowStrategy.TimeType timeType) Create a tumbling time window strategy.static WindowStrategytumbling(Duration windowSize, WindowStrategy.TimeType timeType, Duration allowedLateness) Create a tumbling time window strategy.
-
Field Details
-
PROCESSING_TIME
-
EVENT_TIME
-
-
Constructor Details
-
WindowStrategy
public WindowStrategy()
-
-
Method Details
-
global
Creates a global window strategy. Note that the global window can be used in both GlobalStream, KeyedStream, NonKeyedStream.- Returns:
- A global window strategy.
-
tumbling
Create a tumbling time window strategy with the event time default time type. Note that tumbling time windows can be used in KeyedStream and GlobalStream. If tumbling time window is used in a GlobalStream, it will convert the GlobalStream into a KeyedStream with a Key of zero, and then use the converted KeyedStream to execute the window.- Parameters:
windowSize- the size of Window.- Returns:
- A tumbling time window strategy.
-
tumbling
Create a tumbling time window strategy. Note that tumbling time windows can be used in KeyedStream and GlobalStream. If tumbling time window is used in a GlobalStream, it will convert the GlobalStream into a KeyedStream with a Key of zero, and then use the converted KeyedStream to execute the window.- Parameters:
windowSize- the size of Window.timeType- the time type of Window.- Returns:
- A tumbling time window strategy.
-
tumbling
public static WindowStrategy tumbling(Duration windowSize, WindowStrategy.TimeType timeType, Duration allowedLateness) Create a tumbling time window strategy. Note that tumbling time windows can be used in KeyedStream and GlobalStream. If tumbling time window is used in a GlobalStream, it will convert the GlobalStream into a KeyedStream with a Key of zero, and then use the converted KeyedStream to execute the window.- Parameters:
windowSize- the size of Window.timeType- the time type of Window.allowedLateness- the allowed lateness of Window.- Returns:
- A tumbling time window strategy.
-
sliding
Create a sliding time window strategy with the event time default time type. Note that sliding time windows can be used in KeyedStream and GlobalStream. If sliding time window is used in a GlobalStream, it will convert the GlobalStream into a KeyedStream with a Key of zero, and then use the converted KeyedStream to execute the window.- Parameters:
windowSize- the size of Window.windowSlideInterval- the slide interval of Window.- Returns:
- A sliding time window strategy.
-
sliding
public static WindowStrategy sliding(Duration windowSize, Duration windowSlideInterval, WindowStrategy.TimeType timeType) Create a sliding time window strategy. Note that sliding time windows can be used in KeyedStream and GlobalStream. If sliding time window is used in a GlobalStream, it will convert the GlobalStream into a KeyedStream with a Key of zero, and then use the converted KeyedStream to execute the window.- Parameters:
windowSize- the size of Window.windowSlideInterval- the slide interval of Window.timeType- the time type of Window.- Returns:
- A sliding time window strategy.
-
sliding
public static WindowStrategy sliding(Duration windowSize, Duration windowSlideInterval, WindowStrategy.TimeType timeType, Duration allowedLateness) Create a sliding time window strategy. Note that sliding time windows can be used in KeyedStream and GlobalStream. If sliding time window is used in a GlobalStream, it will convert the GlobalStream into a KeyedStream with a Key of zero, and then use the converted KeyedStream to execute the window.- Parameters:
windowSize- the size of Window.windowSlideInterval- the slide interval of Window.timeType- the time type of Window.allowedLateness- the allowed lateness of Window.- Returns:
- A sliding time window strategy.
-
session
Create a session time window strategy with the event time default time type. Note that session time windows can be used in KeyedStream and GlobalStream. If session time window is used in a GlobalStream, it will convert the GlobalStream into a KeyedStream with a Key of zero, and then use the converted KeyedStream to execute the window.- Parameters:
sessionGap- the timeout of session.- Returns:
- A session window strategy.
-
session
Create a session time window strategy. Note that session time windows can be used in KeyedStream and GlobalStream. If session time window is used in a GlobalStream, it will convert the GlobalStream into a KeyedStream with a Key of zero, and then use the converted KeyedStream to execute the window.- Parameters:
sessionGap- the timeout of session.timeType- the time type of Window.- Returns:
- A session window strategy.
-