Search in sources :

Example 1 with VectorValueSelector

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

the class NumericNullColumnSelectorTest method testFloatSelectorWithNullsCanResetOffset.

@Test
public void testFloatSelectorWithNullsCanResetOffset() {
    for (ImmutableBitmap bitmap : bitmaps) {
        ColumnarFloats floats = new ColumnarFloats() {

            @Override
            public int size() {
                return numRows;
            }

            @Override
            public float get(int index) {
                return ThreadLocalRandom.current().nextFloat();
            }

            @Override
            public void close() {
            }
        };
        FloatsColumn columnWithNulls = FloatsColumn.create(floats, bitmap);
        ColumnValueSelector<?> selector = columnWithNulls.makeColumnValueSelector(offset);
        assertOffsetCanReset(selector, bitmap, offset);
        VectorValueSelector vectorSelector = columnWithNulls.makeVectorValueSelector(vectorOffset);
        assertVectorOffsetCanReset(vectorSelector, bitmap, vectorOffset);
        VectorValueSelector anotherSelector = columnWithNulls.makeVectorValueSelector(anotherVectorOffset);
        assertVectorChillWhenOffsetsOverlap(anotherSelector, bitmap, anotherVectorOffset);
    }
}
Also used : FloatsColumn(org.apache.druid.segment.column.FloatsColumn) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) Test(org.junit.Test)

Example 2 with VectorValueSelector

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

the class NumericNullColumnSelectorTest method testDoubleSelectorWithNullsCanResetOffset.

@Test
public void testDoubleSelectorWithNullsCanResetOffset() {
    for (ImmutableBitmap bitmap : bitmaps) {
        ColumnarDoubles doubles = new ColumnarDoubles() {

            @Override
            public int size() {
                return numRows;
            }

            @Override
            public double get(int index) {
                return ThreadLocalRandom.current().nextDouble();
            }

            @Override
            public void close() {
            }
        };
        DoublesColumn columnWithNulls = DoublesColumn.create(doubles, bitmap);
        ColumnValueSelector<?> selector = columnWithNulls.makeColumnValueSelector(offset);
        assertOffsetCanReset(selector, bitmap, offset);
        VectorValueSelector vectorSelector = columnWithNulls.makeVectorValueSelector(vectorOffset);
        assertVectorOffsetCanReset(vectorSelector, bitmap, vectorOffset);
    }
}
Also used : ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) DoublesColumn(org.apache.druid.segment.column.DoublesColumn) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) Test(org.junit.Test)

Example 3 with VectorValueSelector

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

the class VectorCursorGranularizer method create.

@Nullable
public static VectorCursorGranularizer create(final StorageAdapter storageAdapter, final VectorCursor cursor, final Granularity granularity, final Interval queryInterval) {
    final DateTime minTime = storageAdapter.getMinTime();
    final DateTime maxTime = storageAdapter.getMaxTime();
    final Interval storageAdapterInterval = new Interval(minTime, granularity.bucketEnd(maxTime));
    final Interval clippedQueryInterval = queryInterval.overlap(storageAdapterInterval);
    if (clippedQueryInterval == null) {
        return null;
    }
    final Iterable<Interval> bucketIterable = granularity.getIterable(clippedQueryInterval);
    final Interval firstBucket = granularity.bucket(clippedQueryInterval.getStart());
    final VectorValueSelector timeSelector;
    if (firstBucket.contains(clippedQueryInterval)) {
        // Only one bucket, no need to read the time column.
        assert Iterables.size(bucketIterable) == 1;
        timeSelector = null;
    } else {
        // Multiple buckets, need to read the time column to know when we move from one to the next.
        timeSelector = cursor.getColumnSelectorFactory().makeValueSelector(ColumnHolder.TIME_COLUMN_NAME);
    }
    return new VectorCursorGranularizer(cursor, bucketIterable, timeSelector);
}
Also used : VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Nullable(javax.annotation.Nullable)

Example 4 with VectorValueSelector

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

the class DoubleMinAggregationTest method testDoubleMinVectorAggregator.

@Test
public void testDoubleMinVectorAggregator() {
    // Some sanity.
    Assert.assertTrue(doubleMinVectorAggFactory.canVectorize(vectorColumnSelectorFactory));
    VectorValueSelector vectorValueSelector = doubleMinVectorAggFactory.vectorSelector(vectorColumnSelectorFactory);
    Assert.assertEquals(doubleValues1, vectorValueSelector.getDoubleVector());
    VectorAggregator vectorAggregator = doubleMinVectorAggFactory.factorizeVector(vectorColumnSelectorFactory);
    final ByteBuffer buf = ByteBuffer.allocate(doubleMinVectorAggFactory.getMaxIntermediateSizeWithNulls() * 3);
    vectorAggregator.init(buf, 0);
    vectorAggregator.aggregate(buf, 0, 0, 3);
    Assert.assertEquals(doubleValues1[1], vectorAggregator.get(buf, 0));
    vectorAggregator.init(buf, 8);
    vectorAggregator.aggregate(buf, 8, 0, 3);
    Assert.assertEquals(doubleValues1[1], vectorAggregator.get(buf, 8));
    vectorAggregator.init(buf, 16);
    vectorAggregator.aggregate(buf, 16, 3, 7);
    Assert.assertEquals(doubleValues1[6], vectorAggregator.get(buf, 16));
    vectorAggregator.init(buf, 0);
    vectorAggregator.aggregate(buf, 0, 0, 10);
    Assert.assertEquals(doubleValues1[7], vectorAggregator.get(buf, 0));
}
Also used : VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with VectorValueSelector

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

the class LongMinAggregationTest method testLongMinVectorAggregator.

@Test
public void testLongMinVectorAggregator() {
    // Some sanity.
    Assert.assertTrue(longMinVectorAggFactory.canVectorize(vectorColumnSelectorFactory));
    VectorValueSelector vectorValueSelector = longMinVectorAggFactory.vectorSelector(vectorColumnSelectorFactory);
    Assert.assertEquals(longValues1, vectorValueSelector.getLongVector());
    VectorAggregator vectorAggregator = longMinVectorAggFactory.factorizeVector(vectorColumnSelectorFactory);
    final ByteBuffer buf = ByteBuffer.allocate(longMinAggFactory.getMaxIntermediateSizeWithNulls() * 2);
    vectorAggregator.init(buf, 0);
    vectorAggregator.aggregate(buf, 0, 0, 3);
    Assert.assertEquals(longValues1[1], (long) vectorAggregator.get(buf, 0));
    vectorAggregator.aggregate(buf, 1, 0, 3);
    Assert.assertEquals(longValues1[1], (long) vectorAggregator.get(buf, 1));
    vectorAggregator.aggregate(buf, 2, 3, 7);
    Assert.assertEquals(longValues1[6], (long) vectorAggregator.get(buf, 2));
    vectorAggregator.aggregate(buf, 0, 0, 10);
    Assert.assertEquals(longValues1[7], (long) vectorAggregator.get(buf, 0));
}
Also used : VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

VectorValueSelector (org.apache.druid.segment.vector.VectorValueSelector)23 Test (org.junit.Test)10 Before (org.junit.Before)9 VectorColumnSelectorFactory (org.apache.druid.segment.vector.VectorColumnSelectorFactory)8 ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)7 ByteBuffer (java.nio.ByteBuffer)6 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)4 ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)4 Nullable (javax.annotation.Nullable)3 ImmutableBitmap (org.apache.druid.collections.bitmap.ImmutableBitmap)3 Expr (org.apache.druid.math.expr.Expr)3 ExpressionType (org.apache.druid.math.expr.ExpressionType)3 VectorCursor (org.apache.druid.segment.vector.VectorCursor)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 Granularities (org.apache.druid.java.util.common.granularity.Granularities)2 Sequence (org.apache.druid.java.util.common.guava.Sequence)2 Closer (org.apache.druid.java.util.common.io.Closer)2 ExprMacroTable (org.apache.druid.math.expr.ExprMacroTable)2 Parser (org.apache.druid.math.expr.Parser)2