Search in sources :

Example 1 with MultiValueDimensionVectorSelector

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

the class VectorValueMatcherColumnProcessorFactoryTest method testMultiValueString.

@Test
public void testMultiValueString() {
    IdLookup lookup = EasyMock.createMock(IdLookup.class);
    MultiValueDimensionVectorSelector selector = EasyMock.createMock(MultiValueDimensionVectorSelector.class);
    EasyMock.expect(selector.getCurrentVectorSize()).andReturn(CURRENT_SIZE).anyTimes();
    EasyMock.expect(selector.getMaxVectorSize()).andReturn(VECTOR_SIZE).anyTimes();
    EasyMock.expect(selector.getValueCardinality()).andReturn(11).anyTimes();
    EasyMock.expect(selector.nameLookupPossibleInAdvance()).andReturn(false).anyTimes();
    EasyMock.expect(selector.idLookup()).andReturn(lookup).anyTimes();
    EasyMock.expect(lookup.lookupId("any value")).andReturn(-1).anyTimes();
    EasyMock.expect(lookup.lookupId(null)).andReturn(0).anyTimes();
    EasyMock.replay(selector, lookup);
    VectorValueMatcherFactory matcherFactory = VectorValueMatcherColumnProcessorFactory.instance().makeMultiValueDimensionProcessor(new ColumnCapabilitiesImpl().setType(ColumnType.STRING).setHasMultipleValues(false).setHasBitmapIndexes(true).setDictionaryValuesUnique(true).setDictionaryValuesSorted(true).setDictionaryEncoded(true), selector);
    Assert.assertTrue(matcherFactory instanceof MultiValueStringVectorValueMatcher);
    VectorValueMatcher valueNotExistMatcher = matcherFactory.makeMatcher("any value");
    Assert.assertTrue(valueNotExistMatcher instanceof BooleanVectorValueMatcher);
    Assert.assertEquals(VECTOR_SIZE, valueNotExistMatcher.getMaxVectorSize());
    Assert.assertEquals(CURRENT_SIZE, valueNotExistMatcher.getCurrentVectorSize());
    VectorValueMatcher valueExistMatcher = matcherFactory.makeMatcher((String) null);
    Assert.assertFalse(valueExistMatcher instanceof BooleanVectorValueMatcher);
    Assert.assertEquals(VECTOR_SIZE, valueExistMatcher.getMaxVectorSize());
    Assert.assertEquals(CURRENT_SIZE, valueExistMatcher.getCurrentVectorSize());
    EasyMock.verify(selector, lookup);
}
Also used : IdLookup(org.apache.druid.segment.IdLookup) MultiValueDimensionVectorSelector(org.apache.druid.segment.vector.MultiValueDimensionVectorSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 2 with MultiValueDimensionVectorSelector

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

the class AlwaysTwoVectorizedVirtualColumn method makeMultiValueVectorDimensionSelector.

@Override
public MultiValueDimensionVectorSelector makeMultiValueVectorDimensionSelector(DimensionSpec dimensionSpec, VectorColumnSelectorFactory factory) {
    Assert.assertEquals(outputName, dimensionSpec.getOutputName());
    final IndexedInts[] rowVector = new IndexedInts[factory.getReadableVectorInspector().getMaxVectorSize()];
    Arrays.fill(rowVector, new ArrayBasedIndexedInts(new int[] { 0, 0 }));
    return new MultiValueDimensionVectorSelector() {

        private final VectorSizeInspector inspector = factory.getReadableVectorInspector();

        @Override
        public IndexedInts[] getRowVector() {
            return rowVector;
        }

        @Override
        public int getValueCardinality() {
            return dictionaryEncoded ? 1 : CARDINALITY_UNKNOWN;
        }

        @Nullable
        @Override
        public String lookupName(int id) {
            return "2";
        }

        @Override
        public boolean nameLookupPossibleInAdvance() {
            return dictionaryEncoded;
        }

        @Nullable
        @Override
        public IdLookup idLookup() {
            return null;
        }

        @Override
        public int getMaxVectorSize() {
            return inspector.getMaxVectorSize();
        }

        @Override
        public int getCurrentVectorSize() {
            return inspector.getCurrentVectorSize();
        }
    };
}
Also used : MultiValueDimensionVectorSelector(org.apache.druid.segment.vector.MultiValueDimensionVectorSelector) ArrayBasedIndexedInts(org.apache.druid.segment.data.ArrayBasedIndexedInts) IndexedInts(org.apache.druid.segment.data.IndexedInts) ArrayBasedIndexedInts(org.apache.druid.segment.data.ArrayBasedIndexedInts) VectorSizeInspector(org.apache.druid.segment.vector.VectorSizeInspector)

Example 3 with MultiValueDimensionVectorSelector

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

the class VirtualColumns method makeMultiValueDimensionVectorSelector.

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

Example 4 with MultiValueDimensionVectorSelector

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

the class CardinalityVectorAggregatorTest method testAggregateMultiValueString.

@Test
public void testAggregateMultiValueString() {
    final IndexedInts[] ids = { new ArrayBasedIndexedInts(new int[] { 1, 2 }), new ArrayBasedIndexedInts(new int[] { 2, 3 }), new ArrayBasedIndexedInts(new int[] { 3, 3 }), new ArrayBasedIndexedInts(new int[] { 0 }) };
    final String[] dict = { null, "abc", "def", "foo" };
    final CardinalityVectorAggregator aggregator = new CardinalityVectorAggregator(Collections.singletonList(new MultiValueStringCardinalityVectorProcessor(new MultiValueDimensionVectorSelector() {

        @Override
        public IndexedInts[] getRowVector() {
            return ids;
        }

        @Override
        public int getValueCardinality() {
            return dict.length;
        }

        @Nullable
        @Override
        public String lookupName(int id) {
            return dict[id];
        }

        @Override
        public boolean nameLookupPossibleInAdvance() {
            return true;
        }

        @Nullable
        @Override
        public IdLookup idLookup() {
            return null;
        }

        @Override
        public int getMaxVectorSize() {
            return ids.length;
        }

        @Override
        public int getCurrentVectorSize() {
            return ids.length;
        }
    })));
    testAggregate(aggregator, ids.length, NullHandling.replaceWithDefault() ? 4 : 3);
}
Also used : IdLookup(org.apache.druid.segment.IdLookup) MultiValueDimensionVectorSelector(org.apache.druid.segment.vector.MultiValueDimensionVectorSelector) ArrayBasedIndexedInts(org.apache.druid.segment.data.ArrayBasedIndexedInts) MultiValueStringCardinalityVectorProcessor(org.apache.druid.query.aggregation.cardinality.vector.MultiValueStringCardinalityVectorProcessor) IndexedInts(org.apache.druid.segment.data.IndexedInts) ArrayBasedIndexedInts(org.apache.druid.segment.data.ArrayBasedIndexedInts) Nullable(javax.annotation.Nullable) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

MultiValueDimensionVectorSelector (org.apache.druid.segment.vector.MultiValueDimensionVectorSelector)4 IdLookup (org.apache.druid.segment.IdLookup)2 ArrayBasedIndexedInts (org.apache.druid.segment.data.ArrayBasedIndexedInts)2 IndexedInts (org.apache.druid.segment.data.IndexedInts)2 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)2 Test (org.junit.Test)2 Nullable (javax.annotation.Nullable)1 MultiValueStringCardinalityVectorProcessor (org.apache.druid.query.aggregation.cardinality.vector.MultiValueStringCardinalityVectorProcessor)1 ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)1 VectorSizeInspector (org.apache.druid.segment.vector.VectorSizeInspector)1