Search in sources :

Example 1 with VectorAggregator

use of org.apache.druid.query.aggregation.VectorAggregator in project druid by druid-io.

the class BaseFilterTest method selectCountUsingVectorizedFilteredAggregator.

private long selectCountUsingVectorizedFilteredAggregator(final DimFilter dimFilter) {
    Preconditions.checkState(makeFilter(dimFilter).canVectorizeMatcher(adapter), "Cannot vectorize filter: %s", dimFilter);
    try (final VectorCursor cursor = makeVectorCursor(null)) {
        final FilteredAggregatorFactory aggregatorFactory = new FilteredAggregatorFactory(new CountAggregatorFactory("count"), maybeOptimize(dimFilter));
        final VectorAggregator aggregator = aggregatorFactory.factorizeVector(cursor.getColumnSelectorFactory());
        final ByteBuffer buf = ByteBuffer.allocate(aggregatorFactory.getMaxIntermediateSizeWithNulls() * 2);
        // Use two slots: one for each form of aggregate.
        aggregator.init(buf, 0);
        aggregator.init(buf, aggregatorFactory.getMaxIntermediateSizeWithNulls());
        for (; !cursor.isDone(); cursor.advance()) {
            aggregator.aggregate(buf, 0, 0, cursor.getCurrentVectorSize());
            final int[] positions = new int[cursor.getCurrentVectorSize()];
            Arrays.fill(positions, aggregatorFactory.getMaxIntermediateSizeWithNulls());
            final int[] allRows = new int[cursor.getCurrentVectorSize()];
            for (int i = 0; i < allRows.length; i++) {
                allRows[i] = i;
            }
            aggregator.aggregate(buf, cursor.getCurrentVectorSize(), positions, allRows, 0);
        }
        final long val1 = (long) aggregator.get(buf, 0);
        final long val2 = (long) aggregator.get(buf, aggregatorFactory.getMaxIntermediateSizeWithNulls());
        if (val1 != val2) {
            throw new ISE("Oh no, val1[%d] != val2[%d]", val1, val2);
        }
        return val1;
    }
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) ISE(org.apache.druid.java.util.common.ISE) VectorCursor(org.apache.druid.segment.vector.VectorCursor) ByteBuffer(java.nio.ByteBuffer)

Example 2 with VectorAggregator

use of org.apache.druid.query.aggregation.VectorAggregator in project druid by druid-io.

the class LongAnyAggregatorFactoryTest method factorizeVectorShouldReturnLongVectorAggregator.

@Test
public void factorizeVectorShouldReturnLongVectorAggregator() {
    VectorAggregator aggregator = target.factorizeVector(selectorFactory);
    Assert.assertNotNull(aggregator);
    Assert.assertEquals(LongAnyVectorAggregator.class, aggregator.getClass());
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 3 with VectorAggregator

use of org.apache.druid.query.aggregation.VectorAggregator in project druid by druid-io.

the class FloatAnyAggregatorFactoryTest method factorizeVectorForStringTypeShouldReturnFloatVectorAggregatorWithNilSelector.

@Test
public void factorizeVectorForStringTypeShouldReturnFloatVectorAggregatorWithNilSelector() {
    Mockito.doReturn(capabilities).when(selectorFactory).getColumnCapabilities(FIELD_NAME);
    Mockito.doReturn(false).when(capabilities).isNumeric();
    VectorAggregator aggregator = target.factorizeVector(selectorFactory);
    Assert.assertNotNull(aggregator);
    Assert.assertEquals(NullHandling.defaultFloatValue(), aggregator.get(BUFFER, POSITION));
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 4 with VectorAggregator

use of org.apache.druid.query.aggregation.VectorAggregator in project druid by druid-io.

the class FloatAnyAggregatorFactoryTest method factorizeVectorForNumericTypeShouldReturnFloatVectorAggregator.

@Test
public void factorizeVectorForNumericTypeShouldReturnFloatVectorAggregator() {
    Mockito.doReturn(capabilities).when(selectorFactory).getColumnCapabilities(FIELD_NAME);
    Mockito.doReturn(true).when(capabilities).isNumeric();
    VectorAggregator aggregator = target.factorizeVector(selectorFactory);
    Assert.assertNotNull(aggregator);
    Assert.assertEquals(FloatAnyVectorAggregator.class, aggregator.getClass());
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 5 with VectorAggregator

use of org.apache.druid.query.aggregation.VectorAggregator in project druid by druid-io.

the class DoubleAnyAggregatorFactoryTest method factorizeVectorForNumericTypeShouldReturnDoubleVectorAggregator.

@Test
public void factorizeVectorForNumericTypeShouldReturnDoubleVectorAggregator() {
    Mockito.doReturn(capabilities).when(selectorFactory).getColumnCapabilities(FIELD_NAME);
    Mockito.doReturn(true).when(capabilities).isNumeric();
    VectorAggregator aggregator = target.factorizeVector(selectorFactory);
    Assert.assertNotNull(aggregator);
    Assert.assertEquals(DoubleAnyVectorAggregator.class, aggregator.getClass());
}
Also used : VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

VectorAggregator (org.apache.druid.query.aggregation.VectorAggregator)21 Test (org.junit.Test)20 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)14 ByteBuffer (java.nio.ByteBuffer)7 ISE (org.apache.druid.java.util.common.ISE)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1 FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)1 VectorCursor (org.apache.druid.segment.vector.VectorCursor)1