public final class SlidingWindows extends Object
Sliding Windows are defined based on a record's timestamp, the window size based on the given maximum time difference (inclusive) between records in the same window, and the given window grace period. While the window is sliding over the input data stream, a new window is created each time a record enters the sliding window or a record drops out of the sliding window.
Records that come after set grace period will be ignored, i.e., a window is closed when
stream-time > window-end + grace-period
.
For example, if we have a time difference of 5000ms and the following data arrives:
+--------------------------------------+ | key | value | time | +-----------+-------------+------------+ | A | 1 | 8000 | +-----------+-------------+------------+ | A | 2 | 9200 | +-----------+-------------+------------+ | A | 3 | 12400 | +-----------+-------------+------------+We'd have the following 5 windows:
[3000;8000]
contains [1] (created when first record enters the window)[4200;9200]
contains [1,2] (created when second record enters the window)[7400;12400]
contains [1,2,3] (created when third record enters the window)[8001;13001]
contains [2,3] (created when the first record drops out of the window)[9201;14201]
contains [3] (created when the second record drops out of the window)
Note that while SlidingWindows are of a fixed size, as are TimeWindows
, the start and end points of the window
depend on when events occur in the stream (i.e., event timestamps), similar to SessionWindows
.
For time semantics, see TimestampExtractor
.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
long |
gracePeriodMs() |
int |
hashCode() |
static SlidingWindows |
ofTimeDifferenceAndGrace(Duration timeDifference,
Duration afterWindowEnd)
Return a window definition with the window size based on the given maximum time difference (inclusive) between
records in the same window and given window grace period.
|
static SlidingWindows |
ofTimeDifferenceWithNoGrace(Duration timeDifference)
Return a window definition with the window size based on the given maximum time difference (inclusive) between
records in the same window and given window grace period.
|
long |
timeDifferenceMs() |
String |
toString() |
static SlidingWindows |
withTimeDifferenceAndGrace(Duration timeDifference,
Duration grace)
Deprecated.
since 3.0. Use
ofTimeDifferenceWithNoGrace(Duration) or ofTimeDifferenceAndGrace(Duration, Duration) instead |
public static SlidingWindows ofTimeDifferenceWithNoGrace(Duration timeDifference) throws IllegalArgumentException
grace
.
A window is closed when stream-time > window-end + grace-period
.
CAUTION: Using this method implicitly sets the grace period to zero, which means that any out-of-order records arriving after the window ends are considered late and will be dropped.
timeDifference
- the max time difference (inclusive) between two records in a windowIllegalArgumentException
- if the timeDifference is negative or can't be represented as long milliseconds
public static SlidingWindows ofTimeDifferenceAndGrace(Duration timeDifference, Duration afterWindowEnd) throws IllegalArgumentException
afterWindowEnd
.
A window is closed when stream-time > window-end + grace-period
.timeDifference
- the max time difference (inclusive) between two records in a windowafterWindowEnd
- the grace period to admit out-of-order events to a windowIllegalArgumentException
- if the timeDifference or afterWindowEnd (grace period) is negative or can't be represented as long milliseconds
@Deprecated public static SlidingWindows withTimeDifferenceAndGrace(Duration timeDifference, Duration grace) throws IllegalArgumentException
ofTimeDifferenceWithNoGrace(Duration)
or ofTimeDifferenceAndGrace(Duration, Duration)
insteadgrace
.
A window is closed when stream-time > window-end + grace-period
.timeDifference
- the max time difference (inclusive) between two records in a windowgrace
- the grace period to admit out-of-order events to a windowIllegalArgumentException
- if the specified window size is < 0 or grace < 0, or either can't be represented as long milliseconds
public long timeDifferenceMs()
public long gracePeriodMs()