Versions Compared

Key

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

...

According to KIP-968, this KIP introduces the public enum ResultOrder to determine whether keys are sorted in ascending or descending  or unordered order. Order is based on the serialized byte[] of the keys, not the 'logical' key order. employs the withDescendingKeys() and withAscendingKeys() methods to specify that the keys should be ordered in descending or ascending or unordered sequence, and the resultOrder() method to retrieve the value of enum value in  ResultOrder. I've incorporated these variables and methods into the RangeQuerythe TimestampedRangeQuery  class and modified some method inputs. As a result, we can now use withDescendingKeys() to obtain results in reverse order and use withAscendingKeys to obtain the result in ascending order. 

Code Block
languagejava
titleTimestampedRangeQuery
@Evolving
public final class TimestampedRangeQuery<K, V> implements Query<KeyValueIterator<K, ValueAndTimestamp<V>>> {

    ...

    /**
     * Interactive range query using a lower and upper bound to filter the keys returned.
     * @param lower The key that specifies the lower bound of the range
     * @param upper The key that specifies the upper bound of the range
     * @param <K> The key type
     * @param <V> The value type
     */
    public static <K, V> TimestampedRangeQuery<K, V> withRange(final K lower, final K upper) 
 

	/**
     * Determines if the serialized byte[] of the keys in ascending or descending or unordered order.
     * Order is based on the serialized byte[] of the keys, not the 'logical' key order.
     * @return return the order of return records base on the serialized byte[] of the keys (can be unordered, or in ascending, or in descending order).
     */
    public ResultOrder resultOrder() {
        return order;
    }

    /**
     * Set the query to return the serialized byte[] of the keys in descending order.
     * Order is based on the serialized byte[] of the keys, not the 'logical' key order.
     * @return a new RangeQuery instance with descending flag set.
     */
    public TimestampedRangeQuery<K, V> withDescendingKeys() {
        return new TimestampedRangeQuery<>(this.lower, this.upper, ResultOrder.DESCENDING);
    }

    /**
     * Set the query to return the serialized byte[] of the keys in Ascending order.
     * Order is based on the serialized byte[] of the keys, not the 'logical' key order.
     * @return a new RangeQuery instance with ascending flag set.
     */
    public TimestampedRangeQuery<K, V> withAscendingKeys() {
        return new TimestampedRangeQuery<>(this.lower, this.upper, ResultOrder.ASCENDING);
    }
   
}

According to KIP-968, we introduce a public enum ResultOrder.

ResultOrder enum
It helps with specifying the order of the returned results by the query.

Code Block
languagejava
titleResultOrder
package org.apache.kafka.streams.query;
  
public enum ResultOrder {
    ANY,
    ASCENDING,
    DESCENDING
}

...