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;
}
}
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());
}
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));
}
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());
}
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());
}
Aggregations