Search in sources :

Example 21 with VectorValueSelector

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

the class LongMaxAggregationTest method testLongMaxVectorAggregator.

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

Example 22 with VectorValueSelector

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

the class NumericNullColumnSelectorTest method testLongSelectorWithNullsCanResetOffset.

@Test
public void testLongSelectorWithNullsCanResetOffset() {
    for (ImmutableBitmap bitmap : bitmaps) {
        ColumnarLongs longs = new ColumnarLongs() {

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

            @Override
            public long get(int index) {
                return ThreadLocalRandom.current().nextLong();
            }

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

Example 23 with VectorValueSelector

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

the class BaseFilterTest method selectColumnValuesMatchingFilterUsingVectorVirtualColumnCursor.

private List<String> selectColumnValuesMatchingFilterUsingVectorVirtualColumnCursor(final DimFilter filter, final String virtualColumn, final String selectColumn) {
    final Expr parsedIdentifier = Parser.parse(selectColumn, TestExprMacroTable.INSTANCE);
    try (final VectorCursor cursor = makeVectorCursor(makeFilter(filter))) {
        final ExpressionType outputType = parsedIdentifier.getOutputType(cursor.getColumnSelectorFactory());
        final List<String> values = new ArrayList<>();
        if (outputType.is(ExprType.STRING)) {
            final VectorObjectSelector objectSelector = cursor.getColumnSelectorFactory().makeObjectSelector(virtualColumn);
            while (!cursor.isDone()) {
                final Object[] rowVector = objectSelector.getObjectVector();
                for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
                    values.add((String) rowVector[i]);
                }
                cursor.advance();
            }
        } else {
            final VectorValueSelector valueSelector = cursor.getColumnSelectorFactory().makeValueSelector(virtualColumn);
            while (!cursor.isDone()) {
                final boolean[] nulls = valueSelector.getNullVector();
                if (outputType.is(ExprType.DOUBLE)) {
                    final double[] doubles = valueSelector.getDoubleVector();
                    for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
                        if (nulls != null && nulls[i]) {
                            values.add(null);
                        } else {
                            values.add(String.valueOf(doubles[i]));
                        }
                    }
                } else {
                    final long[] longs = valueSelector.getLongVector();
                    for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
                        if (nulls != null && nulls[i]) {
                            values.add(null);
                        } else {
                            values.add(String.valueOf(longs[i]));
                        }
                    }
                }
                cursor.advance();
            }
        }
        return values;
    }
}
Also used : ArrayList(java.util.ArrayList) VectorCursor(org.apache.druid.segment.vector.VectorCursor) Expr(org.apache.druid.math.expr.Expr) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) VectorObjectSelector(org.apache.druid.segment.vector.VectorObjectSelector) ExpressionType(org.apache.druid.math.expr.ExpressionType)

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