Search in sources :

Example 6 with SingleValueDimensionVectorSelector

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

the class VirtualColumns method makeSingleValueDimensionVectorSelector.

/**
 * Create a single value dimension vector (string) selector.
 *
 * @throws IllegalArgumentException if the virtual column does not exist (see {@link #exists(String)}
 */
public SingleValueDimensionVectorSelector makeSingleValueDimensionVectorSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory) {
    final VirtualColumn virtualColumn = getVirtualColumnForSelector(dimensionSpec.getDimension());
    final SingleValueDimensionVectorSelector selector = virtualColumn.makeSingleValueVectorDimensionSelector(dimensionSpec, factory);
    Preconditions.checkNotNull(selector, "selector");
    return selector;
}
Also used : SingleValueDimensionVectorSelector(org.apache.druid.segment.vector.SingleValueDimensionVectorSelector)

Example 7 with SingleValueDimensionVectorSelector

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

the class VectorValueMatcherColumnProcessorFactoryTest method testSingleValueStringOneCardinalityBooleanMatcherIfNullAndNameLookupPossible.

@Test
public void testSingleValueStringOneCardinalityBooleanMatcherIfNullAndNameLookupPossible() {
    // single value string column with cardinality 1 and name lookup possible in advance uses boolean matcher for
    // matches
    SingleValueDimensionVectorSelector selector = EasyMock.createMock(SingleValueDimensionVectorSelector.class);
    EasyMock.expect(selector.getCurrentVectorSize()).andReturn(CURRENT_SIZE).anyTimes();
    EasyMock.expect(selector.getMaxVectorSize()).andReturn(VECTOR_SIZE).anyTimes();
    EasyMock.expect(selector.getValueCardinality()).andReturn(1).anyTimes();
    EasyMock.expect(selector.nameLookupPossibleInAdvance()).andReturn(true).anyTimes();
    EasyMock.expect(selector.lookupName(0)).andReturn(null).anyTimes();
    EasyMock.replay(selector);
    VectorValueMatcherFactory matcherFactory = VectorValueMatcherColumnProcessorFactory.instance().makeSingleValueDimensionProcessor(new ColumnCapabilitiesImpl().setType(ColumnType.STRING).setHasMultipleValues(false).setHasBitmapIndexes(true).setDictionaryValuesUnique(true).setDictionaryValuesSorted(true).setDictionaryEncoded(true), selector);
    Assert.assertTrue(matcherFactory instanceof SingleValueStringVectorValueMatcher);
    // false matcher
    VectorValueMatcher booleanMatcher = matcherFactory.makeMatcher("any value");
    Assert.assertTrue(booleanMatcher instanceof BooleanVectorValueMatcher);
    Assert.assertEquals(VECTOR_SIZE, booleanMatcher.getMaxVectorSize());
    Assert.assertEquals(CURRENT_SIZE, booleanMatcher.getCurrentVectorSize());
    // true matcher
    VectorValueMatcher anotherBooleanMatcher = matcherFactory.makeMatcher((String) null);
    Assert.assertTrue(anotherBooleanMatcher instanceof BooleanVectorValueMatcher);
    Assert.assertEquals(VECTOR_SIZE, anotherBooleanMatcher.getMaxVectorSize());
    Assert.assertEquals(CURRENT_SIZE, anotherBooleanMatcher.getCurrentVectorSize());
    EasyMock.verify(selector);
}
Also used : SingleValueDimensionVectorSelector(org.apache.druid.segment.vector.SingleValueDimensionVectorSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 8 with SingleValueDimensionVectorSelector

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

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

SingleValueDimensionVectorSelector (org.apache.druid.segment.vector.SingleValueDimensionVectorSelector)9 Test (org.junit.Test)6 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)5 ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)4 ArrayList (java.util.ArrayList)3 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)3 IdLookup (org.apache.druid.segment.IdLookup)3 VectorCursor (org.apache.druid.segment.vector.VectorCursor)3 Nullable (javax.annotation.Nullable)2 ColumnInspector (org.apache.druid.segment.ColumnInspector)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.druid.java.util.common.StringUtils)1 Granularities (org.apache.druid.java.util.common.granularity.Granularities)1 Sequence (org.apache.druid.java.util.common.guava.Sequence)1 Closer (org.apache.druid.java.util.common.io.Closer)1 Expr (org.apache.druid.math.expr.Expr)1 ExprMacroTable (org.apache.druid.math.expr.ExprMacroTable)1