Search in sources :

Example 6 with VectorCursor

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

the class ToObjectVectorColumnProcessorFactoryTest method readColumn.

private List<Object> readColumn(final String column, final int limit) {
    try (final VectorCursor cursor = makeCursor()) {
        final Supplier<Object[]> supplier = ColumnProcessors.makeVectorProcessor(column, ToObjectVectorColumnProcessorFactory.INSTANCE, cursor.getColumnSelectorFactory());
        final List<Object> retVal = new ArrayList<>();
        while (!cursor.isDone()) {
            final Object[] objects = supplier.get();
            for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
                retVal.add(objects[i]);
                if (retVal.size() >= limit) {
                    return retVal;
                }
            }
            cursor.advance();
        }
        return retVal;
    }
}
Also used : ArrayList(java.util.ArrayList) VectorCursor(org.apache.druid.segment.vector.VectorCursor)

Example 7 with VectorCursor

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

the class ExpressionVectorSelectorBenchmark method scan.

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void scan(Blackhole blackhole) {
    final VirtualColumns virtualColumns = VirtualColumns.create(ImmutableList.of(new ExpressionVirtualColumn("v", expression, ExpressionType.toColumnType(outputType), TestExprMacroTable.INSTANCE)));
    if (vectorize) {
        VectorCursor cursor = new QueryableIndexStorageAdapter(index).makeVectorCursor(null, index.getDataInterval(), virtualColumns, false, 512, null);
        if (outputType.isNumeric()) {
            VectorValueSelector selector = cursor.getColumnSelectorFactory().makeValueSelector("v");
            if (outputType.is(ExprType.DOUBLE)) {
                while (!cursor.isDone()) {
                    blackhole.consume(selector.getDoubleVector());
                    blackhole.consume(selector.getNullVector());
                    cursor.advance();
                }
            } else {
                while (!cursor.isDone()) {
                    blackhole.consume(selector.getLongVector());
                    blackhole.consume(selector.getNullVector());
                    cursor.advance();
                }
            }
            closer.register(cursor);
        }
    } else {
        Sequence<Cursor> cursors = new QueryableIndexStorageAdapter(index).makeCursors(null, index.getDataInterval(), virtualColumns, Granularities.ALL, false, null);
        int rowCount = cursors.map(cursor -> {
            final ColumnValueSelector selector = cursor.getColumnSelectorFactory().makeColumnValueSelector("v");
            int rows = 0;
            while (!cursor.isDone()) {
                blackhole.consume(selector.getObject());
                rows++;
                cursor.advance();
            }
            return rows;
        }).accumulate(0, (acc, in) -> acc + in);
        blackhole.consume(rowCount);
    }
}
Also used : BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Measurement(org.openjdk.jmh.annotations.Measurement) SegmentGenerator(org.apache.druid.segment.generator.SegmentGenerator) Blackhole(org.openjdk.jmh.infra.Blackhole) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) Parser(org.apache.druid.math.expr.Parser) Scope(org.openjdk.jmh.annotations.Scope) ExprType(org.apache.druid.math.expr.ExprType) Warmup(org.openjdk.jmh.annotations.Warmup) GeneratorBasicSchemas(org.apache.druid.segment.generator.GeneratorBasicSchemas) VectorCursor(org.apache.druid.segment.vector.VectorCursor) ImmutableList(com.google.common.collect.ImmutableList) ExpressionType(org.apache.druid.math.expr.ExpressionType) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit) Expr(org.apache.druid.math.expr.Expr) TearDown(org.openjdk.jmh.annotations.TearDown) ExpressionVectorSelectorsTest(org.apache.druid.segment.virtual.ExpressionVectorSelectorsTest) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) Nullable(javax.annotation.Nullable) Sequence(org.apache.druid.java.util.common.guava.Sequence) ColumnInspector(org.apache.druid.segment.ColumnInspector) Setup(org.openjdk.jmh.annotations.Setup) QueryableIndexStorageAdapter(org.apache.druid.segment.QueryableIndexStorageAdapter) VirtualColumns(org.apache.druid.segment.VirtualColumns) Mode(org.openjdk.jmh.annotations.Mode) Closer(org.apache.druid.java.util.common.io.Closer) Param(org.openjdk.jmh.annotations.Param) QueryableIndex(org.apache.druid.segment.QueryableIndex) GeneratorSchemaInfo(org.apache.druid.segment.generator.GeneratorSchemaInfo) TestExprMacroTable(org.apache.druid.query.expression.TestExprMacroTable) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) State(org.openjdk.jmh.annotations.State) Benchmark(org.openjdk.jmh.annotations.Benchmark) Granularities(org.apache.druid.java.util.common.granularity.Granularities) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) TimeUnit(java.util.concurrent.TimeUnit) Cursor(org.apache.druid.segment.Cursor) NullHandling(org.apache.druid.common.config.NullHandling) LinearShardSpec(org.apache.druid.timeline.partition.LinearShardSpec) DataSegment(org.apache.druid.timeline.DataSegment) Level(org.openjdk.jmh.annotations.Level) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) Fork(org.openjdk.jmh.annotations.Fork) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) QueryableIndexStorageAdapter(org.apache.druid.segment.QueryableIndexStorageAdapter) VectorCursor(org.apache.druid.segment.vector.VectorCursor) Cursor(org.apache.druid.segment.Cursor) VectorCursor(org.apache.druid.segment.vector.VectorCursor) VirtualColumns(org.apache.druid.segment.VirtualColumns) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 8 with VectorCursor

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

the class BaseFilterTest method selectColumnValuesMatchingFilterUsingVectorizedPostFiltering.

private List<String> selectColumnValuesMatchingFilterUsingVectorizedPostFiltering(final DimFilter filter, final String selectColumn) {
    final Filter theFilter = makeFilter(filter);
    final Filter postFilteringFilter = new Filter() {

        @Override
        public <T> T getBitmapResult(BitmapIndexSelector selector, BitmapResultFactory<T> bitmapResultFactory) {
            throw new UnsupportedOperationException();
        }

        @Override
        public ValueMatcher makeMatcher(ColumnSelectorFactory factory) {
            return theFilter.makeMatcher(factory);
        }

        @Override
        public boolean supportsBitmapIndex(BitmapIndexSelector selector) {
            return false;
        }

        @Override
        public boolean shouldUseBitmapIndex(BitmapIndexSelector selector) {
            return false;
        }

        @Override
        public VectorValueMatcher makeVectorMatcher(VectorColumnSelectorFactory factory) {
            return theFilter.makeVectorMatcher(factory);
        }

        @Override
        public boolean canVectorizeMatcher(ColumnInspector inspector) {
            return theFilter.canVectorizeMatcher(inspector);
        }

        @Override
        public Set<String> getRequiredColumns() {
            return null;
        }

        @Override
        public boolean supportsSelectivityEstimation(ColumnSelector columnSelector, BitmapIndexSelector indexSelector) {
            return false;
        }

        @Override
        public double estimateSelectivity(BitmapIndexSelector indexSelector) {
            return 1.0;
        }
    };
    try (final VectorCursor cursor = makeVectorCursor(postFilteringFilter)) {
        final SingleValueDimensionVectorSelector selector = cursor.getColumnSelectorFactory().makeSingleValueDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
        final List<String> values = new ArrayList<>();
        while (!cursor.isDone()) {
            final int[] rowVector = selector.getRowVector();
            for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
                values.add(selector.lookupName(rowVector[i]));
            }
            cursor.advance();
        }
        return values;
    }
}
Also used : ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) RowBasedColumnSelectorFactory(org.apache.druid.segment.RowBasedColumnSelectorFactory) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) ArrayList(java.util.ArrayList) ColumnInspector(org.apache.druid.segment.ColumnInspector) VectorCursor(org.apache.druid.segment.vector.VectorCursor) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) DimFilter(org.apache.druid.query.filter.DimFilter) Filter(org.apache.druid.query.filter.Filter) ColumnSelector(org.apache.druid.segment.ColumnSelector) BitmapResultFactory(org.apache.druid.query.BitmapResultFactory) BitmapIndexSelector(org.apache.druid.query.filter.BitmapIndexSelector) SingleValueDimensionVectorSelector(org.apache.druid.segment.vector.SingleValueDimensionVectorSelector)

Example 9 with VectorCursor

use of org.apache.druid.segment.vector.VectorCursor 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)

Example 10 with VectorCursor

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

the class BaseFilterTest method selectColumnValuesMatchingFilterUsingVectorCursor.

private List<String> selectColumnValuesMatchingFilterUsingVectorCursor(final DimFilter filter, final String selectColumn) {
    try (final VectorCursor cursor = makeVectorCursor(makeFilter(filter))) {
        final SingleValueDimensionVectorSelector selector = cursor.getColumnSelectorFactory().makeSingleValueDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
        final List<String> values = new ArrayList<>();
        while (!cursor.isDone()) {
            final int[] rowVector = selector.getRowVector();
            for (int i = 0; i < cursor.getCurrentVectorSize(); i++) {
                values.add(selector.lookupName(rowVector[i]));
            }
            cursor.advance();
        }
        return values;
    }
}
Also used : ArrayList(java.util.ArrayList) SingleValueDimensionVectorSelector(org.apache.druid.segment.vector.SingleValueDimensionVectorSelector) VectorCursor(org.apache.druid.segment.vector.VectorCursor) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec)

Aggregations

VectorCursor (org.apache.druid.segment.vector.VectorCursor)10 ArrayList (java.util.ArrayList)5 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)4 ByteBuffer (java.nio.ByteBuffer)3 Closer (org.apache.druid.java.util.common.io.Closer)3 Expr (org.apache.druid.math.expr.Expr)3 ExpressionType (org.apache.druid.math.expr.ExpressionType)3 ColumnInspector (org.apache.druid.segment.ColumnInspector)3 QueryableIndexStorageAdapter (org.apache.druid.segment.QueryableIndexStorageAdapter)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 ISE (org.apache.druid.java.util.common.ISE)2 Granularities (org.apache.druid.java.util.common.granularity.Granularities)2 Sequence (org.apache.druid.java.util.common.guava.Sequence)2 ExprMacroTable (org.apache.druid.math.expr.ExprMacroTable)2 Parser (org.apache.druid.math.expr.Parser)2