Search in sources :

Example 31 with Cursor

use of io.druid.segment.Cursor in project druid by druid-io.

the class GroupByQueryEngine method process.

public Sequence<Row> process(final GroupByQuery query, final StorageAdapter storageAdapter) {
    if (storageAdapter == null) {
        throw new ISE("Null storage adapter found. Probably trying to issue a query against a segment being memory unmapped.");
    }
    final List<Interval> intervals = query.getQuerySegmentSpec().getIntervals();
    if (intervals.size() != 1) {
        throw new IAE("Should only have one interval, got[%s]", intervals);
    }
    Filter filter = Filters.convertToCNFFromQueryContext(query, Filters.toFilter(query.getDimFilter()));
    final Sequence<Cursor> cursors = storageAdapter.makeCursors(filter, intervals.get(0), query.getVirtualColumns(), query.getGranularity(), false);
    final ResourceHolder<ByteBuffer> bufferHolder = intermediateResultsBufferPool.take();
    return Sequences.concat(Sequences.withBaggage(Sequences.map(cursors, new Function<Cursor, Sequence<Row>>() {

        @Override
        public Sequence<Row> apply(final Cursor cursor) {
            return new BaseSequence<>(new BaseSequence.IteratorMaker<Row, RowIterator>() {

                @Override
                public RowIterator make() {
                    return new RowIterator(query, cursor, bufferHolder.get(), config.get());
                }

                @Override
                public void cleanup(RowIterator iterFromMake) {
                    CloseQuietly.close(iterFromMake);
                }
            });
        }
    }), new Closeable() {

        @Override
        public void close() throws IOException {
            CloseQuietly.close(bufferHolder);
        }
    }));
}
Also used : Closeable(java.io.Closeable) BaseSequence(io.druid.java.util.common.guava.BaseSequence) Sequence(io.druid.java.util.common.guava.Sequence) IAE(io.druid.java.util.common.IAE) Cursor(io.druid.segment.Cursor) ByteBuffer(java.nio.ByteBuffer) Filter(io.druid.query.filter.Filter) ISE(io.druid.java.util.common.ISE) Interval(org.joda.time.Interval)

Aggregations

Cursor (io.druid.segment.Cursor)31 ArrayList (java.util.ArrayList)17 StorageAdapter (io.druid.segment.StorageAdapter)16 List (java.util.List)16 Benchmark (org.openjdk.jmh.annotations.Benchmark)15 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)15 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)15 QueryableIndexStorageAdapter (io.druid.segment.QueryableIndexStorageAdapter)14 DimFilter (io.druid.query.filter.DimFilter)11 Filter (io.druid.query.filter.Filter)11 BoundDimFilter (io.druid.query.filter.BoundDimFilter)9 OrDimFilter (io.druid.query.filter.OrDimFilter)9 DimensionSelector (io.druid.segment.DimensionSelector)9 Interval (org.joda.time.Interval)9 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)8 AndDimFilter (io.druid.query.filter.AndDimFilter)8 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)7 IndexedInts (io.druid.segment.data.IndexedInts)6 SelectorFilter (io.druid.segment.filter.SelectorFilter)6 AndFilter (io.druid.segment.filter.AndFilter)5