Class TimestampedWindowRangeWithHeadersQuery<K,V>
- Type Parameters:
K- Type of keysV- Type of values
- All Implemented Interfaces:
Query<ReadOnlyRecordIterator<Windowed<K>, V>>
TimestampedWindowStoreWithHeaders or a
SessionStoreWithHeaders.
This is the headers-aware parallel of WindowRangeQuery: it returns a
ReadOnlyRecordIterator of ReadOnlyRecord elements, each carrying the windowed key,
value, timestamp, and headers, whereas WindowRangeQuery returns a plain
KeyValueIterator of values (no headers). Like
WindowRangeQuery, this query has two mutually exclusive forms:
withWindowStartRange(Instant, Instant)is handled by window stores: it retrieves every key whose window start falls within the closed range[timeFrom, timeTo]. Each element's key is aWindoweddescribing the record's window, andReadOnlyRecord.timestamp()is the stored record's event-time. A stored event-time is contractually non-negative; if the backing store does not persist timestamps -- for example aWithHeadersstore built over a plain window-store supplier that surfaces entries withNO_TIMESTAMP(-1) -- that entry cannot be represented, so advancing the returnedReadOnlyRecordIteratorthrowsStreamsExceptionat that entry. Because iteration can therefore throw mid-stream, always close the returned iterator (for example with try-with-resources), even when a call tonext()throws; otherwise the underlying store iterator leaks and thenum-open-iteratorsmetric stays incremented.withKey(Object)is handled by session stores: it retrieves every session for the given key. Each element's key is aWindowedwhose window is the session's window. Session aggregations carry no per-record event-time of their own, soReadOnlyRecord.timestamp()is filled from the session window's (inclusive) end timestamp. That value is validated non-negative when the window is constructed, so -- unlike the window-store form above -- this form can never throw while iterating: a session whose stored value deserializes to null is still returned, withReadOnlyRecord.value()null(the window-store form instead throws for such an entry, as it has no event-time to surface).
Submitting the withWindowStartRange form to a session store, or the withKey form
to a window store, fails with FailureReason.UNKNOWN_QUERY_TYPE.
Headers are persisted and returned only when the store is backed by a native headers store,
i.e. built with a KIP-1271 WithHeaders byte-store supplier (e.g.
Stores.persistentTimestampedWindowStoreWithHeaders or
Stores.persistentSessionStoreWithHeaders). A WithHeaders store built over a legacy
(non-headers) supplier cannot persist headers, so the store-served reads come back with empty
headers().
Against a plain store not built with the WithHeaders builder at all, this query type is
unsupported and fails with FailureReason.UNKNOWN_QUERY_TYPE.
-
Method Summary
Modifier and TypeMethodDescriptionkey()The key that was specified for this query, if this is awithKey(Object)query.timeFrom()The inclusive lower bound of the window-start range, if this is awithWindowStartRange(Instant, Instant)query.timeTo()The inclusive upper bound of the window-start range, if this is awithWindowStartRange(Instant, Instant)query.toString()static <K,V> TimestampedWindowRangeWithHeadersQuery <K, V> withKey(K key) Creates a query that will retrieve the sessions (aggregation, timestamp, and headers) for the givenkey.static <K,V> TimestampedWindowRangeWithHeadersQuery <K, V> withWindowStartRange(Instant timeFrom, Instant timeTo) Creates a query that will retrieve the records (value, timestamp, and headers) of every key whose window start falls within the closed range[timeFrom, timeTo].
-
Method Details
-
withWindowStartRange
public static <K,V> TimestampedWindowRangeWithHeadersQuery<K,V> withWindowStartRange(Instant timeFrom, Instant timeTo) Creates a query that will retrieve the records (value, timestamp, and headers) of every key whose window start falls within the closed range[timeFrom, timeTo]. Handled by window stores.- Type Parameters:
K- The type of the keyV- The type of the value that will be retrieved- Parameters:
timeFrom- The inclusive lower bound of the window-start rangetimeTo- The inclusive upper bound of the window-start range
-
withKey
Creates a query that will retrieve the sessions (aggregation, timestamp, and headers) for the givenkey. Handled by session stores.- Type Parameters:
K- The type of the keyV- The type of the value that will be retrieved- Parameters:
key- The key to retrieve
-
key
The key that was specified for this query, if this is awithKey(Object)query. -
timeFrom
The inclusive lower bound of the window-start range, if this is awithWindowStartRange(Instant, Instant)query. -
timeTo
The inclusive upper bound of the window-start range, if this is awithWindowStartRange(Instant, Instant)query. -
toString
-