...
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
We aim to enhance the WindowRangeQuery
by supporting a new method: fetch(k
eyFrom, keyT
o, from, to)
. Currently, WindowRangeQuery
utilizes KeyValueIterator<Windowed<K>, V> fetchAll(Instant timeFrom, Instant timeTo)
for retrieving all key-value pairs within a specified time range. However, we propose to use KeyValueIterator<Windowed<K>, V> fetch(K keyFrom, K keyTo, Instant timeFrom, Instant timeTo)
instead. This new method will provide a KeyValueIterator<Windowed<K>, V>
that allows users to iterate over windowed key-value pairs {<Windowed<K>, value>}
, spanning the entire time range.
...
Additionally, this enhancement also allows the WindowRangeQuery
to support WindowKeyQuery
functionality. Users seeking to query window sessions for a specific key can do so by setting keyFrom
and keyTo
to be equal. This dual functionality provides more flexibility and efficiency in querying windowed keys.
Proposed Changes
We need to introduce several additional arguments, upper, key, newTimeFrom, newTimeTo
, in the WindowRangeQuery
class, and subsequently update the methods within this class to accommodate these new parameters.
We also add several new method withAllKey(), fromTime(), toTime(), withKeyRange() to this class.
Code Block | ||||
---|---|---|---|---|
| ||||
public class WindowRangeQuery<K, V> implements Query<KeyValueIterator<Windowed<K>, V>> { ... // newly added public static <K, V> WindowRangeQuery<K, V> withAllKey() { return new WindowRangeQuery<>(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()); } @SuppressWarnings("unchecked") public <K, V> WindowRangeQuery<K, V> fromTime(final Instant timeFrom) { return (WindowRangeQuery<K, V>) new WindowRangeQuery<>(lower, upper, Optional.empty(), Optional.empty(), Optional.empty(), Optional.ofNullable(timeFrom), newTimeTo); } // newly added @SuppressWarnings("unchecked") public <K, V> WindowRangeQuery<K, V> toTime(final Instant timeTo) { return (WindowRangeQuery<K, V>) new WindowRangeQuery<>(lower, upper, Optional.empty(), Optional.empty(), Optional.empty(), newTimeFrom, Optional.ofNullable(timeTo)); } // newly added public static <K, V> WindowRangeQuery<K, V> withKeyRange(final K lower, final K upper) { return new WindowRangeQuery<>(Optional.ofNullable(lower), Optional.ofNullable(upper), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()); } // newly added public Optional<K> lowerKeyBound() { return lower; } // newly added public Optional<K> upperKeyBound() { return upper; } @Deprecated public Optional<Instant> getTimeFrom() { return timeFrom; } @Deprecated public Optional<Instant> getTimeTo() { return timeTo; } // newly added public Optional<Instant> timeFrom() { return timeFrom; } // newly added public Optional<Instant> timeTo() { return timeTo; } // newly added public Optional<Instant> newTimeFrom() { return newTimeFrom; } // newly added public Optional<Instant> newTimeTo() { return newTimeTo; } // newly added public Optional<K> key() { return key; } } |
Compatibility, Deprecation, and Migration Plan
- Utilizing the existing
WindowRangeQuery
class, we can make some modifications to realize the concepts ofKeyValueIterator<Windowed<K>, V> fetch(K keyFrom, K keyTo, Instant timeFrom, Instant timeTo)
. - We want to deprecate
WindowKeyQuery
class
Examples
The following example illustrates the use of the WindowRangeQuery class to query a kv-store or ts kv-store.
...
With the introduction of the new keyTo
argument to the WindowRangeQuery
class, it is necessary to update all associated tests. Since SessionRangeQuery
and WindowKeyQuery
also utilize methods from WindowRangeQuery
, we must ensure that the tests covering SessionRangeQuery
and WindowKeyQuery
are revised accordingly.
Rejected Alternatives
We will introduce a new class, WindowRangeQuery2
, designed to facilitate the KeyValueIterator<Windowed<K>, V> fetch(K keyFrom, K keyTo, Instant timeFrom, Instant timeTo)
method. This addition will be an expansion to the IQv2 codebase, ensuring that no existing code is modified; we are merely supplementing with new code and methods to support this enhanced query type.