Search in sources :

Example 1 with SingleValueStringCardinalityVectorProcessor

use of org.apache.druid.query.aggregation.cardinality.vector.SingleValueStringCardinalityVectorProcessor in project druid by druid-io.

the class CardinalityVectorAggregatorTest method testAggregateSingleValueString.

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

        @Override
        public int[] 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) SingleValueStringCardinalityVectorProcessor(org.apache.druid.query.aggregation.cardinality.vector.SingleValueStringCardinalityVectorProcessor) SingleValueDimensionVectorSelector(org.apache.druid.segment.vector.SingleValueDimensionVectorSelector) Nullable(javax.annotation.Nullable) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

Nullable (javax.annotation.Nullable)1 SingleValueStringCardinalityVectorProcessor (org.apache.druid.query.aggregation.cardinality.vector.SingleValueStringCardinalityVectorProcessor)1 IdLookup (org.apache.druid.segment.IdLookup)1 SingleValueDimensionVectorSelector (org.apache.druid.segment.vector.SingleValueDimensionVectorSelector)1 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)1 Test (org.junit.Test)1