Class MultiVersionedKeyQuery<K,V>

java.lang.Object
org.apache.kafka.streams.query.MultiVersionedKeyQuery<K,V>
Type Parameters:
K - The type of the key.
V - The type of the result returned by this query.
All Implemented Interfaces:
Query<VersionedRecordIterator<V>>

@Evolving public final class MultiVersionedKeyQuery<K,V> extends Object implements Query<VersionedRecordIterator<V>>
Interactive query for retrieving a set of records with the same specified key and different timestamps within the specified time range. No ordering is guaranteed for the results, but the results can be sorted by timestamp (in ascending or descending order) by calling the corresponding defined methods.
  • Method Details

    • withKey

      public static <K, V> MultiVersionedKeyQuery<K,V> withKey(K key)
      Creates a query that will retrieve the set of records identified by key if any exists (or null otherwise).

      While the query by default returns the all the record versions of the specified key, setting the fromTimestamp (by calling the fromTime(Instant) method), and the toTimestamp (by calling the toTime(Instant) method) makes the query to return the record versions associated to the specified time range.

      Type Parameters:
      K - The type of the key
      V - The type of the value that will be retrieved
      Parameters:
      key - The specified key by the query
      Throws:
      NullPointerException - if key is null
    • fromTime

      public MultiVersionedKeyQuery<K,V> fromTime(Instant fromTime)
      Specifies the starting time point for the key query.

      The key query returns all the records that are still existing in the time range starting from the timestamp fromTime. There can be records which have been inserted before the fromTime and are still valid in the query specified time range (the whole time range or even partially). The key query in fact returns all the records that have NOT become tombstone at or after fromTime.

      Parameters:
      fromTime - The starting time point If fromTime is null, it will be considered as negative infinity, ie, no lower bound
    • toTime

      public MultiVersionedKeyQuery<K,V> toTime(Instant toTime)
      Specifies the ending time point for the key query. The key query returns all the records that have timestamp <= toTime.
      Parameters:
      toTime - The ending time point If @param toTime is null, will be considered as positive infinity, ie, no upper bound
    • withDescendingTimestamps

      public MultiVersionedKeyQuery<K,V> withDescendingTimestamps()
      Specifies the order of the returned records by the query as descending by timestamp.
    • withAscendingTimestamps

      public MultiVersionedKeyQuery<K,V> withAscendingTimestamps()
      Specifies the order of the returned records by the query as ascending by timestamp.
    • key

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

      public Optional<Instant> fromTime()
      The starting time point of the query, if specified
      Returns:
      The specified fromTime of the query.
    • toTime

      public Optional<Instant> toTime()
      The ending time point of the query, if specified
      Returns:
      The specified toTime of the query.
    • resultOrder

      public ResultOrder resultOrder()
      The order of the returned records by timestamp.
      Returns:
      the order of returned records based on timestamp (can be unordered, or in ascending, or in descending order of timestamps).