Class VersionedKeyQuery<K,V>

java.lang.Object
org.apache.kafka.streams.query.VersionedKeyQuery<K,V>
Type Parameters:
K - The type of the key.
V - The type of the value.
All Implemented Interfaces:
Query<VersionedRecord<V>>

@Evolving public final class VersionedKeyQuery<K,V> extends Object implements Query<VersionedRecord<V>>
Interactive query for retrieving a single record from a versioned state store based on its key and timestamp.
  • Method Details

    • withKey

      public static <K, V> VersionedKeyQuery<K,V> withKey(K key)
      Creates a query that will retrieve the record from a versioned state store identified by key if it exists (or null otherwise).

      While the query by default returns the latest value of the specified key, setting the asOfTimestamp (by calling the asOf(Instant) method), makes the query to return the value associated to the specified asOfTimestamp.

      Type Parameters:
      K - The type of the key
      V - The type of the value that will be retrieved
      Parameters:
      key - The key to retrieve
      Throws:
      NullPointerException - if key is null
    • asOf

      public VersionedKeyQuery<K,V> asOf(Instant asOfTimestamp)
      Specifies the timestamp for the key query. The key query returns the record's version for the specified timestamp. (To be more precise: The key query returns the record with the greatest timestamp <= asOfTimestamp)
      Parameters:
      asOfTimestamp - The timestamp of the query.
      Throws:
      NullPointerException - if asOfTimestamp is null
    • key

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

      public Optional<Instant> asOfTimestamp()
      The timestamp of the query, if specified.
      Returns:
      The specified asOfTimestamp of the query.