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
@Experimental public class WindowStrategy extends Object implements Serializable
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWindowStrategy.TimeTypeThe types of time used in window operations.
-
Field Summary
Fields Modifier and Type Field Description static WindowStrategy.TimeTypeEVENT_TIMEstatic WindowStrategy.TimeTypePROCESSING_TIME
-
Constructor Summary
Constructors Constructor Description WindowStrategy()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static WindowStrategyglobal()Creates a global window strategy.static WindowStrategysession(Duration sessionGap)Create 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 WindowStrategysliding(Duration windowSize, Duration windowSlideInterval)Create 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 WindowStrategytumbling(Duration windowSize)Create 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 Detail
-
PROCESSING_TIME
public static final WindowStrategy.TimeType PROCESSING_TIME
-
EVENT_TIME
public static final WindowStrategy.TimeType EVENT_TIME
-
-
Method Detail
-
global
public static WindowStrategy 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
public static WindowStrategy tumbling(Duration windowSize)
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
public static WindowStrategy tumbling(Duration windowSize, WindowStrategy.TimeType timeType)
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
public static WindowStrategy sliding(Duration windowSize, Duration windowSlideInterval)
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
public static WindowStrategy session(Duration sessionGap)
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
public static WindowStrategy session(Duration sessionGap, WindowStrategy.TimeType timeType)
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.
-
-