3

Using the Samza KeyValueStore interface, how do I retrieve all documents with a common key prefix? The keys are Strings, and RocksDb will be the underlying store.

Are there any issues with the approach below using the range method?

KeyValueStore<String,String> store = (KeyValueStore<String, String>) context.getStore("foo")
store.put("aaa.xxx", "foo");
store.put("aaa.yyy", "bar");
store.put("bbb.zzz", "qux");

// get all docs starting with "aaa."
KeyValueIterator<String, String> it = store.range("aaa.", "aaa." + Character.MAX_VALUE)
Mike Buhot
  • 4,790
  • 20
  • 31

1 Answers1

0

This will work, but because the range end value is exclusive, you could also just do store.range("aaa.", "b")

Jakob Homan
  • 2,284
  • 1
  • 13
  • 16
  • For this particular example data that would work, but in general, the safest algorithm is to append Character.MAX_VALUE to the prefix string. – Mike Buhot Dec 07 '15 at 10:42