Class TimestampedKeyWithHeadersQuery<K,V>

java.lang.Object
org.apache.kafka.streams.query.TimestampedKeyWithHeadersQuery<K,V>
Type Parameters:
K - Type of keys
V - Type of values
All Implemented Interfaces:
Query<ReadOnlyRecord<K,V>>

@Evolving @Public public final class TimestampedKeyWithHeadersQuery<K,V> extends Object implements Query<ReadOnlyRecord<K,V>>
Interactive query for retrieving a single record, including its record headers, based on its key from a TimestampedKeyValueStoreWithHeaders.

This is the headers-aware parallel of TimestampedKeyQuery: it returns a ReadOnlyRecord carrying the key, value, timestamp, and headers, whereas TimestampedKeyQuery returns a ValueAndTimestamp (value and timestamp only, no key or headers).

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.persistentTimestampedKeyValueStoreWithHeaders). A WithHeaders store built over a legacy (non-headers) supplier cannot persist headers, so the result depends on who serves the read: with caching enabled, a not-yet-evicted entry is served from the record cache and returns the written value, timestamp, and headers (read-your-writes); once served from the underlying store, the headers are gone. Over a timestamped legacy supplier (e.g. Stores.persistentTimestampedKeyValueStore) the store-served read succeeds with empty headers(); over a plain legacy supplier (e.g. Stores.persistentKeyValueStore), which keeps no timestamp either, the store-served read has no representable timestamp and the query fails with FailureReason.STORE_EXCEPTION.

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 Details

    • withKey

      public static <K,V> TimestampedKeyWithHeadersQuery<K,V> withKey(K key)
      Creates a query that will retrieve the record (value, timestamp, and headers) identified by key if it exists (or null otherwise).
      Type Parameters:
      K - The type of the key
      V - The type of the value that will be retrieved
      Parameters:
      key - The key to retrieve
    • skipCache

      public TimestampedKeyWithHeadersQuery<K,V> skipCache()
      Specifies that the cache should be skipped during query evaluation. This means, that the query will always get forwarded to the underlying store.
    • key

      public K key()
      Return the key that was specified for this query.
      Returns:
      The key that was specified for this query.
    • isSkipCache

      public boolean isSkipCache()
      The flag whether to skip the cache or not during query evaluation.