Search in sources :

Example 1 with MultiValueStringCardinalityVectorProcessor

use of org.apache.druid.query.aggregation.cardinality.vector.MultiValueStringCardinalityVectorProcessor 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

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