Package org.apache.kafka.streams.kstream
Class TimeWindows
- java.lang.Object
-
- org.apache.kafka.streams.kstream.Windows<org.apache.kafka.streams.kstream.internals.TimeWindow>
-
- org.apache.kafka.streams.kstream.TimeWindows
-
public final class TimeWindows extends Windows<org.apache.kafka.streams.kstream.internals.TimeWindow>
The fixed-size time-based window specifications used for aggregations.The semantics of time-based aggregation windows are: Every T1 (advance) milliseconds, compute the aggregate total for T2 (size) milliseconds.
- If
advance < sizea hopping windows is defined:
it discretize a stream into overlapping windows, which implies that a record maybe contained in one and or more "adjacent" windows. - If
advance == sizea tumbling window is defined:
it discretize a stream into non-overlapping windows, which implies that a record is only ever contained in one and only one tumbling window.
TimeWindows are aligned to the epoch. Aligned to the epoch means, that the first window starts at timestamp zero. For example, hopping windows with size of 5000ms and advance of 3000ms, have window boundaries [0;5000),[3000;8000),... and not [1000;6000),[4000;9000),... or even something "random" like [1452;6452),[4452;9452),...For time semantics, see
TimestampExtractor. - If
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TimeWindowsadvanceBy(long advanceMs)Return a window definition with the original size, but advance ("hop") the window by the given interval, which specifies by how much a window moves forward relative to the previous one.booleanequals(java.lang.Object o)inthashCode()longmaintainMs()Return the window maintain duration (retention time) in milliseconds.static TimeWindowsof(long sizeMs)Return a window definition with the given window size, and with the advance interval being equal to the window size.longsize()Return the size of the specified windows in milliseconds.TimeWindowsuntil(long durationMs)Set the window maintain duration (retention time) in milliseconds.java.util.Map<java.lang.Long,org.apache.kafka.streams.kstream.internals.TimeWindow>windowsFor(long timestamp)Create all windows that contain the provided timestamp, indexed by non-negative window start timestamps.
-
-
-
Method Detail
-
of
public static TimeWindows of(long sizeMs) throws java.lang.IllegalArgumentException
Return a window definition with the given window size, and with the advance interval being equal to the window size. The time interval represented by the N-th window is:[N * size, N * size + size).This provides the semantics of tumbling windows, which are fixed-sized, gap-less, non-overlapping windows. Tumbling windows are a special case of hopping windows with
advance == size.- Parameters:
sizeMs- The size of the window in milliseconds- Returns:
- a new window definition with default maintain duration of 1 day
- Throws:
java.lang.IllegalArgumentException- if the specified window size is zero or negative
-
advanceBy
public TimeWindows advanceBy(long advanceMs)
Return a window definition with the original size, but advance ("hop") the window by the given interval, which specifies by how much a window moves forward relative to the previous one. The time interval represented by the N-th window is:[N * advance, N * advance + size).This provides the semantics of hopping windows, which are fixed-sized, overlapping windows.
- Parameters:
advanceMs- The advance interval ("hop") in milliseconds of the window, with the requirement that0 < advanceMs ≤ sizeMs.- Returns:
- a new window definition with default maintain duration of 1 day
- Throws:
java.lang.IllegalArgumentException- if the advance interval is negative, zero, or larger-or-equal the window size
-
windowsFor
public java.util.Map<java.lang.Long,org.apache.kafka.streams.kstream.internals.TimeWindow> windowsFor(long timestamp)
Description copied from class:WindowsCreate all windows that contain the provided timestamp, indexed by non-negative window start timestamps.- Specified by:
windowsForin classWindows<org.apache.kafka.streams.kstream.internals.TimeWindow>- Parameters:
timestamp- the timestamp window should get created for- Returns:
- a map of
windowStartTimestamp -> Windowentries
-
size
public long size()
Description copied from class:WindowsReturn the size of the specified windows in milliseconds.
-
until
public TimeWindows until(long durationMs) throws java.lang.IllegalArgumentException
Description copied from class:WindowsSet the window maintain duration (retention time) in milliseconds. This retention time is a guaranteed lower bound for how long a window will be maintained.
-
maintainMs
public long maintainMs()
Return the window maintain duration (retention time) in milliseconds.For
TimeWindowsthe maintain duration is at least as small as the window size.- Overrides:
maintainMsin classWindows<org.apache.kafka.streams.kstream.internals.TimeWindow>- Returns:
- the window maintain duration
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-