Class SlidingWindowPolicy

java.lang.Object
com.hazelcast.jet.core.SlidingWindowPolicy
All Implemented Interfaces:
Serializable

public class SlidingWindowPolicy extends Object implements 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 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, with frameLength = 10 and frameOffset = 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 of frameSize().
    • 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 such long value, returns Long.MIN_VALUE.
    • higherFrameTs

      public long higherFrameTs(long timestamp)
      Returns the lowest frame timestamp greater than the given timestamp. If there is no such long value, returns Long.MAX_VALUE.
    • withOffset

      public SlidingWindowPolicy withOffset(long offset)
      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), ... With offset = 2 they will cover ..., [-2, 2), [2..6), ...

    • toTumblingByFrame

      public SlidingWindowPolicy toTumblingByFrame()
      Converts this definition to one defining a tumbling window of the same length as this definition's frame.
    • slidingWinPolicy

      public static SlidingWindowPolicy slidingWinPolicy(long windowSize, long slideBy)
      Returns the definition of a sliding window of length windowSize that slides by slideBy. Given windowSize = 4 and slideBy = 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 of slideBy
      slideBy - the amount to slide the window by
    • tumblingWinPolicy

      public static SlidingWindowPolicy tumblingWinPolicy(long windowSize)
      Returns the definition of a tumbling window of length windowSize. The tumbling window is a special case of the sliding window with slideBy = windowSize. Given windowSize = 4, the generated windows would cover timestamps ..., [-4, 0), [0..4), [4..8), ...