Search in sources :

Example 16 with CloseableIterator

use of org.apache.druid.java.util.common.parsers.CloseableIterator in project druid by druid-io.

the class HashVectorGrouper method iterator.

@Override
public CloseableIterator<Grouper.Entry<Memory>> iterator() {
    if (!initialized) {
        // a nested groupBy's subquery has an empty result set (see testEmptySubquery() in GroupByQueryRunnerTest)
        return CloseableIterators.withEmptyBaggage(Collections.emptyIterator());
    }
    final IntIterator baseIterator = hashTable.bucketIterator();
    return new CloseableIterator<Grouper.Entry<Memory>>() {

        @Override
        public boolean hasNext() {
            return baseIterator.hasNext();
        }

        @Override
        public Grouper.Entry<Memory> next() {
            final int bucket = baseIterator.nextInt();
            final int bucketPosition = hashTable.bucketMemoryPosition(bucket);
            final Memory keyMemory = hashTable.memory().region(bucketPosition + hashTable.bucketKeyOffset(), hashTable.keySize());
            final Object[] values = new Object[aggregators.size()];
            final int aggregatorsOffset = bucketPosition + hashTable.bucketValueOffset();
            for (int i = 0; i < aggregators.size(); i++) {
                values[i] = aggregators.get(hashTable.memory().getByteBuffer(), aggregatorsOffset, i);
            }
            return new Grouper.Entry<>(keyMemory, values);
        }

        @Override
        public void close() {
        // Do nothing.
        }
    };
}
Also used : CloseableIterator(org.apache.druid.java.util.common.parsers.CloseableIterator) IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory)

Aggregations

CloseableIterator (org.apache.druid.java.util.common.parsers.CloseableIterator)16 IOException (java.io.IOException)9 Map (java.util.Map)6 NoSuchElementException (java.util.NoSuchElementException)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Collections (java.util.Collections)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4 CleanableFile (org.apache.druid.data.input.InputEntity.CleanableFile)4 Closer (org.apache.druid.java.util.common.io.Closer)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Preconditions (com.google.common.base.Preconditions)3 ImmutableList (com.google.common.collect.ImmutableList)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 File (java.io.File)3 Collectors (java.util.stream.Collectors)3 ParseException (org.apache.druid.java.util.common.parsers.ParseException)3 Supplier (com.google.common.base.Supplier)2 ByteBuffer (java.nio.ByteBuffer)2