mjsax commented on code in PR #14477:
URL: https://github.com/apache/kafka/pull/14477#discussion_r1348227721


##########
streams/src/main/java/org/apache/kafka/streams/state/internals/MeteredKeyValueStore.java:
##########
@@ -254,17 +254,37 @@ protected <R> QueryResult<R> runRangeQuery(final Query<R> 
query,
         final QueryResult<R> result;
         final RangeQuery<K, V> typedQuery = (RangeQuery<K, V>) query;
         final RangeQuery<Bytes, byte[]> rawRangeQuery;
+        final boolean isKeyAscending = typedQuery.isKeyAscending();
         if (typedQuery.getLowerBound().isPresent() && 
typedQuery.getUpperBound().isPresent()) {
-            rawRangeQuery = RangeQuery.withRange(
-                keyBytes(typedQuery.getLowerBound().get()),
-                keyBytes(typedQuery.getUpperBound().get())
-            );
+            if (isKeyAscending) {
+                rawRangeQuery = RangeQuery.withRange(
+                        keyBytes(typedQuery.getLowerBound().get()),
+                        keyBytes(typedQuery.getUpperBound().get())
+                );
+            } else {
+                rawRangeQuery = (RangeQuery<Bytes, byte[]>) (RangeQuery<?, ?>) 
RangeQuery.withRange(
+                        keyBytes(typedQuery.getLowerBound().get()),
+                        keyBytes(typedQuery.getUpperBound().get())
+                ).withDescendingKeys();

Review Comment:
   However, it seem code is a little bit redundant here. I think it would make 
sense to lift the `final` for `rawRangeQuery` and do the following:
   
   ```
   rawRangeQuery = RangeQuery.withRange(
       keyBytes(typedQuery.getLowerBound().get()),
       keyBytes(typedQuery.getUpperBound().get())
   );
   if (!isKeyAscending)
       rawRangeQuery = rawRangeQuery.withDescendingKeys();
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to