Package org.apache.kafka.streams.kstream
Class JoinWindows
- java.lang.Object
-
- org.apache.kafka.streams.kstream.Windows<Window>
-
- org.apache.kafka.streams.kstream.JoinWindows
-
public final class JoinWindows extends Windows<Window>
The window specifications used for joins.A
JoinWindowsinstance defines a maximum time difference for ajoin over two streamson the same key. In SQL-style you would express this join as
There are three different window configuration supported:SELECT * FROM stream1, stream2 WHERE stream1.key = stream2.key AND stream1.ts - before <= stream2.ts AND stream2.ts <= stream1.ts + after- before = after = time-difference
- before = 0 and after = time-difference
- before = time-difference and after = 0
Both values (before and after) must not result in an "inverse" window, i.e., upper-interval bound cannot be smaller than lower-interval bound.
JoinWindowsare sliding windows, thus, they are aligned to the actual record timestamps. This implies, that each input record defines its own window with start and end time being relative to the record's timestamp.For time semantics, see
TimestampExtractor.- See Also:
TimeWindows,UnlimitedWindows,SessionWindows,KStream.join(KStream, ValueJoiner, JoinWindows),KStream.join(KStream, ValueJoiner, JoinWindows, Joined),KStream.leftJoin(KStream, ValueJoiner, JoinWindows),KStream.leftJoin(KStream, ValueJoiner, JoinWindows, Joined),KStream.outerJoin(KStream, ValueJoiner, JoinWindows),KStream.outerJoin(KStream, ValueJoiner, JoinWindows, Joined),TimestampExtractor
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description JoinWindowsafter(long timeDifferenceMs)Changes the end window boundary totimeDifferenceMsbut keep the start window boundary as is.JoinWindowsbefore(long timeDifferenceMs)Changes the start window boundary totimeDifferenceMsbut keep the end window boundary as is.booleanequals(java.lang.Object o)inthashCode()longmaintainMs()Return the window maintain duration (retention time) in milliseconds.static JoinWindowsof(long timeDifferenceMs)Specifies that records of the same key are joinable if their timestamps are withintimeDifferenceMs, i.e., the timestamp of a record from the secondary stream is maxtimeDifferenceMsearlier or later than the timestamp of the record from the primary stream.longsize()Return the size of the specified windows in milliseconds.JoinWindowsuntil(long durationMs)Set the window maintain duration (retention time) in milliseconds.java.util.Map<java.lang.Long,Window>windowsFor(long timestamp)Not supported byJoinWindows.
-
-
-
Method Detail
-
of
public static JoinWindows of(long timeDifferenceMs) throws java.lang.IllegalArgumentException
Specifies that records of the same key are joinable if their timestamps are withintimeDifferenceMs, i.e., the timestamp of a record from the secondary stream is maxtimeDifferenceMsearlier or later than the timestamp of the record from the primary stream.- Parameters:
timeDifferenceMs- join window interval in milliseconds- Throws:
java.lang.IllegalArgumentException- iftimeDifferenceMsis negative
-
before
public JoinWindows before(long timeDifferenceMs) throws java.lang.IllegalArgumentException
Changes the start window boundary totimeDifferenceMsbut keep the end window boundary as is. Thus, records of the same key are joinable if the timestamp of a record from the secondary stream is at mosttimeDifferenceMsearlier than the timestamp of the record from the primary stream.timeDifferenceMscan be negative but it's absolute value must not be larger than current window "after" value (which would result in a negative window size).- Parameters:
timeDifferenceMs- relative window start time in milliseconds- Throws:
java.lang.IllegalArgumentException- if the resulting window size is negative
-
after
public JoinWindows after(long timeDifferenceMs) throws java.lang.IllegalArgumentException
Changes the end window boundary totimeDifferenceMsbut keep the start window boundary as is. Thus, records of the same key are joinable if the timestamp of a record from the secondary stream is at mosttimeDifferenceMslater than the timestamp of the record from the primary stream.timeDifferenceMscan be negative but it's absolute value must not be larger than current window "before" value (which would result in a negative window size).- Parameters:
timeDifferenceMs- relative window end time in milliseconds- Throws:
java.lang.IllegalArgumentException- if the resulting window size is negative
-
windowsFor
public java.util.Map<java.lang.Long,Window> windowsFor(long timestamp)
Not supported byJoinWindows. ThrowsUnsupportedOperationException.- Specified by:
windowsForin classWindows<Window>- Parameters:
timestamp- the timestamp window should get created for- Returns:
- a map of
windowStartTimestamp -> Windowentries - Throws:
java.lang.UnsupportedOperationException- at every invocation
-
size
public long size()
Description copied from class:WindowsReturn the size of the specified windows in milliseconds.
-
until
public JoinWindows 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<Window>- Returns:
- the window maintain duration
-
equals
public final boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-