Skip to content

Instantly share code, notes, and snippets.

@enothereska
Created May 3, 2017 07:57
Show Gist options
  • Save enothereska/2edf31c38608be85a9b020256c475071 to your computer and use it in GitHub Desktop.
Save enothereska/2edf31c38608be85a9b020256c475071 to your computer and use it in GitHub Desktop.
Querying a store
// Get the window store named "queryStoreName"
ReadOnlyWindowStore<String, Long> windowStore =
streams.store("queryStoreName", QueryableStoreTypes.windowStore());
// Fetch values for the key "europe" for all of the windows available in this application instance.
// To get *all* available windows we fetch windows from the beginning of time until now.
long timeFrom = 0; // beginning of time = oldest available
long timeTo = System.currentTimeMillis(); // now (in processing-time)
WindowStoreIterator<Long> iterator = windowStore.fetch("europe", timeFrom, timeTo);
while (iterator.hasNext()) {
KeyValue<Long, Long> next = iterator.next();
long windowTimestamp = next.key;
System.out.println("Count of 'europe' @ time " + windowTimestamp + " is " + next.value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment