Search in sources :

Example 1 with VectorColumnSelectorFactory

use of org.apache.druid.segment.vector.VectorColumnSelectorFactory in project druid by druid-io.

the class LongMinAggregationTest method setup.

@Before
public void setup() {
    NullHandling.initializeForTests();
    selector = new TestLongColumnSelector(values);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(selector);
    EasyMock.expect(colSelectorFactory.getColumnCapabilities("nilly")).andReturn(null);
    EasyMock.replay(colSelectorFactory);
    VectorValueSelector vectorValueSelector = EasyMock.createMock(VectorValueSelector.class);
    EasyMock.expect(vectorValueSelector.getLongVector()).andReturn(longValues1).anyTimes();
    EasyMock.expect(vectorValueSelector.getNullVector()).andReturn(null).anyTimes();
    EasyMock.replay(vectorValueSelector);
    vectorColumnSelectorFactory = EasyMock.createMock(VectorColumnSelectorFactory.class);
    EasyMock.expect(vectorColumnSelectorFactory.getColumnCapabilities("lngFld")).andReturn(new ColumnCapabilitiesImpl().setType(ColumnType.LONG).setDictionaryEncoded(true)).anyTimes();
    EasyMock.expect(vectorColumnSelectorFactory.makeValueSelector("lngFld")).andReturn(vectorValueSelector).anyTimes();
    EasyMock.replay(vectorColumnSelectorFactory);
}
Also used : ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Before(org.junit.Before)

Example 2 with VectorColumnSelectorFactory

use of org.apache.druid.segment.vector.VectorColumnSelectorFactory in project druid by druid-io.

the class FloatMaxAggregationTest method setup.

@Before
public void setup() {
    NullHandling.initializeForTests();
    VectorValueSelector vectorValueSelector = EasyMock.createMock(VectorValueSelector.class);
    EasyMock.expect(vectorValueSelector.getFloatVector()).andReturn(floatValues1).anyTimes();
    EasyMock.expect(vectorValueSelector.getNullVector()).andReturn(null).anyTimes();
    EasyMock.replay(vectorValueSelector);
    vectorColumnSelectorFactory = EasyMock.createMock(VectorColumnSelectorFactory.class);
    EasyMock.expect(vectorColumnSelectorFactory.getColumnCapabilities("fltFld")).andReturn(new ColumnCapabilitiesImpl().setType(ColumnType.FLOAT).setDictionaryEncoded(true)).anyTimes();
    EasyMock.expect(vectorColumnSelectorFactory.makeValueSelector("fltFld")).andReturn(vectorValueSelector).anyTimes();
    EasyMock.replay(vectorColumnSelectorFactory);
}
Also used : VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Before(org.junit.Before)

Example 3 with VectorColumnSelectorFactory

use of org.apache.druid.segment.vector.VectorColumnSelectorFactory in project druid by druid-io.

the class TimeseriesQueryEngine method processVectorized.

private Sequence<Result<TimeseriesResultValue>> processVectorized(final TimeseriesQuery query, final StorageAdapter adapter, @Nullable final Filter filter, final Interval queryInterval, final Granularity gran, final boolean descending) {
    final boolean skipEmptyBuckets = query.isSkipEmptyBuckets();
    final List<AggregatorFactory> aggregatorSpecs = query.getAggregatorSpecs();
    final VectorCursor cursor = adapter.makeVectorCursor(filter, queryInterval, query.getVirtualColumns(), descending, QueryContexts.getVectorSize(query), null);
    if (cursor == null) {
        return Sequences.empty();
    }
    final Closer closer = Closer.create();
    closer.register(cursor);
    try {
        final VectorCursorGranularizer granularizer = VectorCursorGranularizer.create(adapter, cursor, gran, queryInterval);
        if (granularizer == null) {
            return Sequences.empty();
        }
        final VectorColumnSelectorFactory columnSelectorFactory = cursor.getColumnSelectorFactory();
        final AggregatorAdapters aggregators = closer.register(AggregatorAdapters.factorizeVector(columnSelectorFactory, query.getAggregatorSpecs()));
        final ResourceHolder<ByteBuffer> bufferHolder = closer.register(bufferPool.take());
        final ByteBuffer buffer = bufferHolder.get();
        if (aggregators.spaceNeeded() > buffer.remaining()) {
            throw new ISE("Not enough space for aggregators, needed [%,d] bytes but have only [%,d].", aggregators.spaceNeeded(), buffer.remaining());
        }
        return Sequences.withBaggage(Sequences.simple(granularizer.getBucketIterable()).map(bucketInterval -> {
            // Whether or not the current bucket is empty
            boolean emptyBucket = true;
            while (!cursor.isDone()) {
                granularizer.setCurrentOffsets(bucketInterval);
                if (granularizer.getEndOffset() > granularizer.getStartOffset()) {
                    if (emptyBucket) {
                        aggregators.init(buffer, 0);
                    }
                    aggregators.aggregateVector(buffer, 0, granularizer.getStartOffset(), granularizer.getEndOffset());
                    emptyBucket = false;
                }
                if (!granularizer.advanceCursorWithinBucket()) {
                    break;
                }
            }
            if (emptyBucket && skipEmptyBuckets) {
                // Return null, will get filtered out later by the Objects::nonNull filter.
                return null;
            }
            final TimeseriesResultBuilder bob = new TimeseriesResultBuilder(gran.toDateTime(bucketInterval.getStartMillis()));
            if (emptyBucket) {
                aggregators.init(buffer, 0);
            }
            for (int i = 0; i < aggregatorSpecs.size(); i++) {
                bob.addMetric(aggregatorSpecs.get(i).getName(), aggregators.get(buffer, 0, i));
            }
            return bob.build();
        }).filter(Objects::nonNull), closer);
    } catch (Throwable t1) {
        try {
            closer.close();
        } catch (Throwable t2) {
            t1.addSuppressed(t2);
        }
        throw t1;
    }
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer) AggregatorAdapters(org.apache.druid.query.aggregation.AggregatorAdapters) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) VectorCursor(org.apache.druid.segment.vector.VectorCursor) ByteBuffer(java.nio.ByteBuffer) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) VectorCursorGranularizer(org.apache.druid.query.vector.VectorCursorGranularizer) ISE(org.apache.druid.java.util.common.ISE)

Example 4 with VectorColumnSelectorFactory

use of org.apache.druid.segment.vector.VectorColumnSelectorFactory in project druid by druid-io.

the class QueryableIndexCursorSequenceBuilder method buildVectorized.

public VectorCursor buildVectorized(final int vectorSize) {
    // Sanity check - matches QueryableIndexStorageAdapter.canVectorize
    Preconditions.checkState(!descending, "!descending");
    final Map<String, BaseColumn> columnCache = new HashMap<>();
    final Closer closer = Closer.create();
    NumericColumn timestamps = null;
    final int startOffset;
    final int endOffset;
    if (interval.getStartMillis() > minDataTimestamp) {
        timestamps = (NumericColumn) index.getColumnHolder(ColumnHolder.TIME_COLUMN_NAME).getColumn();
        closer.register(timestamps);
        startOffset = timeSearch(timestamps, interval.getStartMillis(), 0, index.getNumRows());
    } else {
        startOffset = 0;
    }
    if (interval.getEndMillis() <= maxDataTimestamp) {
        if (timestamps == null) {
            timestamps = (NumericColumn) index.getColumnHolder(ColumnHolder.TIME_COLUMN_NAME).getColumn();
            closer.register(timestamps);
        }
        endOffset = timeSearch(timestamps, interval.getEndMillis(), startOffset, index.getNumRows());
    } else {
        endOffset = index.getNumRows();
    }
    final VectorOffset baseOffset = filterBitmap == null ? new NoFilterVectorOffset(vectorSize, startOffset, endOffset) : new BitmapVectorOffset(vectorSize, filterBitmap, startOffset, endOffset);
    // baseColumnSelectorFactory using baseOffset is the column selector for filtering.
    final VectorColumnSelectorFactory baseColumnSelectorFactory = makeVectorColumnSelectorFactoryForOffset(columnCache, baseOffset, closer);
    if (postFilter == null) {
        return new QueryableIndexVectorCursor(baseColumnSelectorFactory, baseOffset, vectorSize, closer);
    } else {
        final VectorOffset filteredOffset = FilteredVectorOffset.create(baseOffset, baseColumnSelectorFactory, postFilter);
        // Now create the cursor and column selector that will be returned to the caller.
        // 
        // There is an inefficiency with how we do things here: this cursor (the one that will be provided to the
        // caller) does share a columnCache with "baseColumnSelectorFactory", but it *doesn't* share vector data. This
        // means that if the caller wants to read from a column that is also used for filtering, the underlying column
        // object will get hit twice for some of the values (anything that matched the filter). This is probably most
        // noticeable if it causes thrashing of decompression buffers due to out-of-order reads. I haven't observed
        // this directly but it seems possible in principle.
        // baseColumnSelectorFactory using baseOffset is the column selector for filtering.
        final VectorColumnSelectorFactory filteredColumnSelectorFactory = makeVectorColumnSelectorFactoryForOffset(columnCache, filteredOffset, closer);
        return new QueryableIndexVectorCursor(filteredColumnSelectorFactory, filteredOffset, vectorSize, closer);
    }
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer) FilteredVectorOffset(org.apache.druid.segment.vector.FilteredVectorOffset) BitmapVectorOffset(org.apache.druid.segment.vector.BitmapVectorOffset) NoFilterVectorOffset(org.apache.druid.segment.vector.NoFilterVectorOffset) VectorOffset(org.apache.druid.segment.vector.VectorOffset) NumericColumn(org.apache.druid.segment.column.NumericColumn) HashMap(java.util.HashMap) BaseColumn(org.apache.druid.segment.column.BaseColumn) NoFilterVectorOffset(org.apache.druid.segment.vector.NoFilterVectorOffset) BitmapVectorOffset(org.apache.druid.segment.vector.BitmapVectorOffset) QueryableIndexVectorColumnSelectorFactory(org.apache.druid.segment.vector.QueryableIndexVectorColumnSelectorFactory) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory)

Example 5 with VectorColumnSelectorFactory

use of org.apache.druid.segment.vector.VectorColumnSelectorFactory in project druid by druid-io.

the class LongMaxAggregationTest method setup.

@Before
public void setup() {
    NullHandling.initializeForTests();
    selector = new TestLongColumnSelector(values);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(selector);
    EasyMock.expect(colSelectorFactory.getColumnCapabilities("nilly")).andReturn(null);
    EasyMock.replay(colSelectorFactory);
    VectorValueSelector vectorValueSelector = EasyMock.createMock(VectorValueSelector.class);
    EasyMock.expect(vectorValueSelector.getLongVector()).andReturn(longValues1).anyTimes();
    EasyMock.expect(vectorValueSelector.getNullVector()).andReturn(null).anyTimes();
    EasyMock.replay(vectorValueSelector);
    vectorColumnSelectorFactory = EasyMock.createMock(VectorColumnSelectorFactory.class);
    EasyMock.expect(vectorColumnSelectorFactory.getColumnCapabilities("lngFld")).andReturn(new ColumnCapabilitiesImpl().setType(ColumnType.LONG).setDictionaryEncoded(true)).anyTimes();
    EasyMock.expect(vectorColumnSelectorFactory.makeValueSelector("lngFld")).andReturn(vectorValueSelector).anyTimes();
    EasyMock.replay(vectorColumnSelectorFactory);
}
Also used : ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Before(org.junit.Before)

Aggregations

VectorColumnSelectorFactory (org.apache.druid.segment.vector.VectorColumnSelectorFactory)12 Before (org.junit.Before)9 ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)8 VectorValueSelector (org.apache.druid.segment.vector.VectorValueSelector)8 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)5 Closer (org.apache.druid.java.util.common.io.Closer)2 ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)2 VectorCursor (org.apache.druid.segment.vector.VectorCursor)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ISE (org.apache.druid.java.util.common.ISE)1 BitmapResultFactory (org.apache.druid.query.BitmapResultFactory)1 AggregatorAdapters (org.apache.druid.query.aggregation.AggregatorAdapters)1 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)1 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)1 BitmapIndexSelector (org.apache.druid.query.filter.BitmapIndexSelector)1 DimFilter (org.apache.druid.query.filter.DimFilter)1 Filter (org.apache.druid.query.filter.Filter)1 VectorCursorGranularizer (org.apache.druid.query.vector.VectorCursorGranularizer)1