Search in sources :

Example 1 with LongIntHashMap

use of com.carrotsearch.hppc.LongIntHashMap in project elasticsearch by elastic.

the class ReverseNestedAggregator method getLeafCollector.

@Override
protected LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
    // In ES if parent is deleted, then also the children are deleted, so the child docs this agg receives
    // must belong to parent docs that is alive. For this reason acceptedDocs can be null here.
    final BitSet parentDocs = parentBitsetProducer.getBitSet(ctx);
    if (parentDocs == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final LongIntHashMap bucketOrdToLastCollectedParentDoc = new LongIntHashMap(32);
    return new LeafBucketCollectorBase(sub, null) {

        @Override
        public void collect(int childDoc, long bucket) throws IOException {
            // fast forward to retrieve the parentDoc this childDoc belongs to
            final int parentDoc = parentDocs.nextSetBit(childDoc);
            assert childDoc <= parentDoc && parentDoc != DocIdSetIterator.NO_MORE_DOCS;
            int keySlot = bucketOrdToLastCollectedParentDoc.indexOf(bucket);
            if (bucketOrdToLastCollectedParentDoc.indexExists(keySlot)) {
                int lastCollectedParentDoc = bucketOrdToLastCollectedParentDoc.indexGet(keySlot);
                if (parentDoc > lastCollectedParentDoc) {
                    collectBucket(sub, parentDoc, bucket);
                    bucketOrdToLastCollectedParentDoc.indexReplace(keySlot, parentDoc);
                }
            } else {
                collectBucket(sub, parentDoc, bucket);
                bucketOrdToLastCollectedParentDoc.indexInsert(keySlot, bucket, parentDoc);
            }
        }
    };
}
Also used : LongIntHashMap(com.carrotsearch.hppc.LongIntHashMap) BitSet(org.apache.lucene.util.BitSet) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase)

Aggregations

LongIntHashMap (com.carrotsearch.hppc.LongIntHashMap)1 BitSet (org.apache.lucene.util.BitSet)1 LeafBucketCollectorBase (org.elasticsearch.search.aggregations.LeafBucketCollectorBase)1