Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This page is meant as a template for writing a KIP. To create a KIP choose Tools->Copy on this page and modify with your content and replace the heading with the next KIP number and a description of your issue. Replace anything in italics with your own description.

Status

Current state: Under Discussion

...

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation


In the current IQv2 code, there are noticeable differences when interfacing with plain-kv-store and ts-kv-store. Notably, the return type V acts as a simple value for plain-kv-store but evolves into ValueAndTimestamp<V> for ts-kv-store, which presents type safety issues in the API.

...

Why introduce TimestampKeyQuery and TimestampRangeQuery? The primary motivation behind this is to ensure type safety and foster a clear distinction in our API. They bridge the difference between simple key-value stores and those integrated with timestamps, offering a more robust and intuitive querying mechanism.

Proposed Changes

Within the current IQv2 codebase, there have been distinct interactions between plain-kv-store and ts-kv-store. These differences, especially in return types, have raised concerns over type safety within the API.

...

This restructuring ensures a more intuitive, type-safe, and consistent querying mechanism for users across different types of key-value stores in the IQv2.

Compatibility, Deprecation, and Migration Plan

  • Utilizing the existing RangeQuery and KeyQuery class, we can make some modifications to realize the concepts of TimestampKeyQuery  and TimestampRangeQuery. 
  • Since nothing is deprecated in this KIP, users have no need to migrate unless they want to.

Test Plan

To ensure the robustness and accuracy of our new query types, TimestampKeyQuery and TimestampRangeQuery, it's essential to have thorough test coverage. With that in mind, we propose the creation of two specific test methods:

...

Code Block
languagejava
titleshouldHandleTimestampRangeQuery
public <V> void shouldHandleTimestampRangeQuery(
            final Optional<Integer> lower,
            final Optional<Integer> upper,
            final Function<ValueAndTimestamp<V>, Integer> valueExtactor,
            final Set<Integer> expectedValue) {

        final TimestampRangeQuery<Integer, V> query;

        query = TimestampRangeQuery.withRange(lower.orElse(null), upper.orElse(null));

        final StateQueryRequest<KeyValueIterator<Integer, ValueAndTimestamp<V>>> request =
                inStore(STORE_NAME)
                        .withQuery(query)
                        .withPartitions(mkSet(0, 1))
                        .withPositionBound(PositionBound.at(INPUT_POSITION));
        final StateQueryResult<KeyValueIterator<Integer, ValueAndTimestamp<V>>> result =
                IntegrationTestUtils.iqv2WaitForResult(kafkaStreams, request);
            ...
            final Map<Integer, QueryResult<KeyValueIterator<Integer, ValueAndTimestamp<V>>>> queryResult = result.getPartitionResults();
       
             ...

                try (final KeyValueIterator<Integer, ValueAndTimestamp<V>> iterator = queryResult.get(partition).getResult()) {
                    while (iterator.hasNext()) {
                        actualValue.add(valueExtactor.apply(iterator.next().value));
                    }
                }
               ...
        }
    }


Rejected Alternatives

Initially, our approach was to directly use TimestampKeyQuery and TimestampRangeQuery within each store. This implied that every store would return a ValueAndTimestamp<byte[]>. However, this method introduced complexities due to type transformations.

...