Package com.hazelcast.jet.core
Class SlidingWindowPolicy
java.lang.Object
com.hazelcast.jet.core.SlidingWindowPolicy
- All Implemented Interfaces:
Serializable
Contains parameters that define a sliding/tumbling window over which Jet
will apply an aggregate function. Internally, Jet computes the window
by maintaining frames of size equal to the sliding step. It
treats the frame as a "unit range" of timestamps which cannot be further
divided and immediately applies the accumulating function to the items
belonging to the same frame. This allows Jet to let go of the individual
items' data, saving memory. The user-visible consequences of this are
that the configured window length must be an integer multiple of the
sliding step and that the memory requirements scale with the ratio
between window size and the sliding step.
A frame is labelled with its timestamp, which is the first timestamp value beyond the range covered by the frame. That timestamp denotes the exact moment on the event timeline where the frame was closed.
- Since:
- Jet 3.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionlong
floorFrameTs
(long timestamp) Returns the highest frame timestamp less than or equal to the given timestamp.long
Returns the frame offset.long
Returns the length of the frame (equal to the sliding step).long
higherFrameTs
(long timestamp) Returns the lowest frame timestamp greater than the given timestamp.boolean
Tells whether this definition describes a tumbling window.static SlidingWindowPolicy
slidingWinPolicy
(long windowSize, long slideBy) Returns the definition of a sliding window of lengthwindowSize
that slides byslideBy
.Converts this definition to one defining a tumbling window of the same length as this definition's frame.static SlidingWindowPolicy
tumblingWinPolicy
(long windowSize) Returns the definition of a tumbling window of lengthwindowSize
.long
Returns the length of the window (the size of the timestamp range it covers).withOffset
(long offset) Returns a new window definition where all the frames are shifted by the given offset.
-
Method Details
-
frameSize
public long frameSize()Returns the length of the frame (equal to the sliding step). -
frameOffset
public long frameOffset()Returns the frame offset. For example, withframeLength = 10
andframeOffset = 5
the frames will start at 5, 15, 25... -
windowSize
public long windowSize()Returns the length of the window (the size of the timestamp range it covers). It is an integer multiple offrameSize()
. -
isTumbling
public boolean isTumbling()Tells whether this definition describes a tumbling window. Tumbling window is a special case of sliding window whose sliding step is equal to its size. -
floorFrameTs
public long floorFrameTs(long timestamp) Returns the highest frame timestamp less than or equal to the given timestamp. If there is no suchlong
value, returnsLong.MIN_VALUE
. -
higherFrameTs
public long higherFrameTs(long timestamp) Returns the lowest frame timestamp greater than the given timestamp. If there is no suchlong
value, returnsLong.MAX_VALUE
. -
withOffset
Returns a new window definition where all the frames are shifted by the given offset. More formally, it specifies the value of the lowest non-negative frame timestamp.Given a tumbling window of
windowLength = 4
, with no offset the windows would cover the timestamps..., [-4, 0), [0..4), ...
Withoffset = 2
they will cover..., [-2, 2), [2..6), ...
-
toTumblingByFrame
Converts this definition to one defining a tumbling window of the same length as this definition's frame. -
slidingWinPolicy
Returns the definition of a sliding window of lengthwindowSize
that slides byslideBy
. GivenwindowSize = 4
andslideBy = 2
, the generated windows would cover timestamps..., [-2, 2), [0..4), [2..6), [4..8), [6..10), ...
Since the window will be computed internally by maintaining
frames
of size equal to the sliding step, the configured window length must be an integer multiple of the sliding step.- Parameters:
windowSize
- the length of the window, must be a multiple ofslideBy
slideBy
- the amount to slide the window by
-
tumblingWinPolicy
Returns the definition of a tumbling window of lengthwindowSize
. The tumbling window is a special case of the sliding window withslideBy = windowSize
. GivenwindowSize = 4
, the generated windows would cover timestamps..., [-4, 0), [0..4), [4..8), ...
-