vamossagar12 commented on a change in pull request #10052:
URL: https://github.com/apache/kafka/pull/10052#discussion_r575662025



##########
File path: 
streams/src/test/java/org/apache/kafka/streams/state/internals/InMemoryKeyValueStoreTest.java
##########
@@ -60,4 +67,22 @@ public void shouldRemoveKeysWithNullValues() {
 
         assertThat(store.get(0), nullValue());
     }
+
+
+    @Test
+    public void shouldReturnKeysWithGivenPrefix(){
+        store = createKeyValueStore(driver.context());
+        final String value = "value";
+        final List<KeyValue<Integer, String>> entries = new ArrayList<>();
+        entries.add(new KeyValue<>(1, value));
+        entries.add(new KeyValue<>(2, value));
+        entries.add(new KeyValue<>(11, value));
+        entries.add(new KeyValue<>(13, value));
+
+        store.putAll(entries);
+        final KeyValueIterator<Integer, String> keysWithPrefix = 
store.prefixScan(1, new IntegerSerializer());

Review comment:
       I spent some more time on this today. What seems to be happening here is 
that in InMemoryKVStore, even though we are creating a NavigableMap as the 
inner map and even though Bytes(Key type for the inner map) does implement 
Comparable, when I insert the following keys:
   
   ```final List<KeyValue<Integer, String>> entries = new ArrayList<>();
           entries.add(new KeyValue<>(1, value));
           entries.add(new KeyValue<>(2, value));
           entries.add(new KeyValue<>(11, value));
           entries.add(new KeyValue<>(13, value));
   store.putAll(entries);
   ```
   so the expectation(atleast for me) was that i should get the keys stored 
lexicographically ie the output of 
   
   ```
   final KeyValueIterator<Integer, String> allKeys = store.all();
           while (allKeys.hasNext()){
               System.out.println(allKeys.next().key);
           }
   ``` 
   should be `1 11 13 2` but what gets returned is `1 2 11 13` i.e the order in 
which we inserted. 
   
   Just to strengthen the point, when I insert keys in the order:
   ```final List<KeyValue<Integer, String>> entries = new ArrayList<>();
           entries.add(new KeyValue<>(1, value));
           entries.add(new KeyValue<>(11, value));
           entries.add(new KeyValue<>(13, value));
           entries.add(new KeyValue<>(2, value));
   
           store.putAll(entries);
   ```
   and when I fetch all keys, what I get back is still `1 2 11 13` i.e the 
natural ordering of the integer keys. And this is precisely the reason why 
prefix scan is returning only 1 key in the test case that I had pointed out. I 
did try to pass in an explicit comparator to the TreeMap but that didn't help 
as well. What are your thoughts on this?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to