public final class TimeWindows extends Windows<TimeWindow>
The semantics of time-based aggregation windows are: Every T1 (advance) milliseconds, compute the aggregate total for T2 (size) milliseconds.
advance < size
a hopping windows is defined:advance == size
a tumbling window is defined:TimeWindow
s 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
.
SessionWindows
,
UnlimitedWindows
,
JoinWindows
,
KGroupedStream.count(Windows, String)
,
KGroupedStream.count(Windows, org.apache.kafka.streams.processor.StateStoreSupplier)
,
KGroupedStream.reduce(Reducer, Windows, String)
,
KGroupedStream.reduce(Reducer, Windows, org.apache.kafka.streams.processor.StateStoreSupplier)
,
KGroupedStream.aggregate(Initializer, Aggregator, Windows, org.apache.kafka.common.serialization.Serde, String)
,
KGroupedStream.aggregate(Initializer, Aggregator, Windows, org.apache.kafka.streams.processor.StateStoreSupplier)
,
TimestampExtractor
Modifier and Type | Field and Description |
---|---|
long |
advanceMs
The size of the window's advance interval in milliseconds, i.e., by how much a window moves forward relative to
the previous one.
|
long |
sizeMs
The size of the windows in milliseconds.
|
Modifier and Type | Method and Description |
---|---|
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.
|
boolean |
equals(java.lang.Object o) |
int |
hashCode() |
long |
maintainMs()
Return the window maintain duration (retention time) in milliseconds.
|
static TimeWindows |
of(long sizeMs)
Return a window definition with the given window size, and with the advance interval being equal to the window
size.
|
long |
size()
Return the size of the specified windows in milliseconds.
|
TimeWindows |
until(long durationMs)
Set the window maintain duration (retention time) in milliseconds.
|
java.util.Map<java.lang.Long,TimeWindow> |
windowsFor(long timestamp)
Create all windows that contain the provided timestamp, indexed by non-negative window start timestamps.
|
public final long sizeMs
public final long advanceMs
public static TimeWindows of(long sizeMs) throws java.lang.IllegalArgumentException
[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
.
sizeMs
- The size of the window in millisecondsjava.lang.IllegalArgumentException
- if the specified window size is zero or negativepublic TimeWindows advanceBy(long advanceMs)
[N * advance, N * advance + size)
.
This provides the semantics of hopping windows, which are fixed-sized, overlapping windows.
advanceMs
- The advance interval ("hop") in milliseconds of the window, with the requirement that
0 < advanceMs ≤ sizeMs
.java.lang.IllegalArgumentException
- if the advance interval is negative, zero, or larger-or-equal the window sizepublic java.util.Map<java.lang.Long,TimeWindow> windowsFor(long timestamp)
Windows
windowsFor
in class Windows<TimeWindow>
timestamp
- the timestamp window should get created forwindowStartTimestamp -> Window
entriespublic long size()
Windows
public TimeWindows until(long durationMs) throws java.lang.IllegalArgumentException
Windows
public long maintainMs()
For TimeWindows
the maintain duration is at least as small as the window size.
maintainMs
in class Windows<TimeWindow>
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object