saurabhd336 commented on code in PR #12532: URL: https://github.com/apache/pinot/pull/12532#discussion_r1533279838
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/realtime/impl/json/MutableJsonIndexImpl.java: ########## @@ -350,58 +354,48 @@ private RoaringBitmap getMatchingFlattenedDocIds(Predicate predicate) { } } - @Override - public Map<String, RoaringBitmap> getMatchingDocsMap(String key) { - Map<String, RoaringBitmap> matchingDocsMap = new HashMap<>(); + @VisibleForTesting + public Map<String, RoaringBitmap> convertFlattenedDocIdsToDocIds(Map<String, RoaringBitmap> valueToFlattenedDocIds) { _readLock.lock(); try { - Pair<String, RoaringBitmap> result = getKeyAndFlattenDocId(key); - key = result.getLeft(); - RoaringBitmap arrayIndexFlattenDocIds = result.getRight(); - if (arrayIndexFlattenDocIds != null && arrayIndexFlattenDocIds.isEmpty()) { - return matchingDocsMap; - } - Map<String, RoaringBitmap> subMap = getMatchingKeysMap(key); - for (Map.Entry<String, RoaringBitmap> entry : subMap.entrySet()) { - RoaringBitmap kvPairFlattenedDocIds = entry.getValue(); - PeekableIntIterator it = arrayIndexFlattenDocIds == null ? kvPairFlattenedDocIds.getIntIterator() - : RoaringBitmap.and(arrayIndexFlattenDocIds, kvPairFlattenedDocIds).getIntIterator(); - if (!it.hasNext()) { - continue; - } - MutableRoaringBitmap postingList = new MutableRoaringBitmap(); - while (it.hasNext()) { - postingList.add(_docIdMapping.getInt(it.next())); - } - String val = entry.getKey().substring(key.length() + 1); - matchingDocsMap.put(val, postingList.toRoaringBitmap()); + Map<String, RoaringBitmap> valueToDocIds = new HashMap<>(); + for (Map.Entry<String, RoaringBitmap> entry : valueToFlattenedDocIds.entrySet()) { + RoaringBitmap docIds = new RoaringBitmap(); + entry.getValue().forEach((IntConsumer) flattenedDocId -> docIds.add(_docIdMapping.getInt(flattenedDocId))); + valueToDocIds.put(entry.getKey(), docIds); } + return valueToDocIds; } finally { _readLock.unlock(); } - return matchingDocsMap; } @Override - public String[] getValuesForKeyAndDocs(int[] docIds, Map<String, RoaringBitmap> matchingDocsMap) { - Int2ObjectOpenHashMap<String> docIdToValues = new Int2ObjectOpenHashMap<>(docIds.length); - RoaringBitmap docIdMask = RoaringBitmap.bitmapOf(docIds); - - for (Map.Entry<String, RoaringBitmap> entry : matchingDocsMap.entrySet()) { - RoaringBitmap intersection = RoaringBitmap.and(entry.getValue(), docIdMask); - if (intersection.isEmpty()) { - continue; + public Map<String, RoaringBitmap> getMatchingFlattenedDocsMap(String jsonPathKey) { + Map<String, RoaringBitmap> valueToMatchingFlattenedDocIdsMap = new HashMap<>(); + _readLock.lock(); + try { + Pair<String, RoaringBitmap> result = getKeyAndFlattenDocId(jsonPathKey); Review Comment: Ack -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org