itschrispeck commented on code in PR #11739:
URL: https://github.com/apache/pinot/pull/11739#discussion_r1364691424


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/json/ImmutableJsonIndexReader.java:
##########
@@ -300,6 +305,92 @@ private int getDocId(int flattenedDocId) {
     return _docIdMapping.getInt((long) flattenedDocId << 2);
   }
 
+  /**
+   * ImmutableJsonIndexReaderContext holds a cache that is used to accelerate 
following reads. The cache is specific
+   * to a key, and therefore should NOT be reused for other keys. For each 
key, ImmutableJsonIndexReader.createContext()
+   * should be invoked to create a fresh context.
+   */
+  public static class ImmutableJsonIndexReaderContext implements 
JsonIndexReaderContext {
+    private final Int2ObjectOpenHashMap<RoaringBitmap> _cache;
+
+    public ImmutableJsonIndexReaderContext() {
+      _cache = new Int2ObjectOpenHashMap<>();
+    }
+
+    public Int2ObjectOpenHashMap<RoaringBitmap> getCache() {
+      return _cache;
+    }
+  }
+
+  @Override
+  public ImmutableJsonIndexReaderContext createContext() {
+    return new ImmutableJsonIndexReaderContext();
+  }
+
+  @Override
+  public String[] getValuesForKeyAndDocs(String key, int[] docIds, 
JsonIndexReaderContext context) {

Review Comment:
   I went w/ a context class since the 'cache' is a different type for the 
mutable/immutable segment implementation. 
   
   I think having a version of the method for immutable/mutable impls, `public 
List<RoaringBitmap> getMatchingDocsMap(String key)` and `public Map<String, 
RoaringBitmap> getMatchingDocsMap(String key)` would move the handling of this 
behavior outside the IndexReader. This would have downsides of requiring that 
the caller of JsonIndexReader have more insight into the implementation of 
JsonIndexReader, and expose the cache object to the caller. Let me know if I'm 
missing something. 



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to