use of org.apache.druid.query.aggregation.AggregatorAndSize in project druid by druid-io.
the class OnheapIncrementalIndex method factorizeAggs.
/**
* Creates aggregators for the given aggregator factories.
*
* @return Total initial size in bytes required by all the aggregators.
* This value is non-zero only when {@link #useMaxMemoryEstimates} is false.
*/
private long factorizeAggs(AggregatorFactory[] metrics, Aggregator[] aggs, ThreadLocal<InputRow> rowContainer, InputRow row) {
long totalInitialSizeBytes = 0L;
rowContainer.set(row);
final long aggReferenceSize = Long.BYTES;
for (int i = 0; i < metrics.length; i++) {
final AggregatorFactory agg = metrics[i];
if (useMaxMemoryEstimates) {
aggs[i] = agg.factorize(selectors.get(agg.getName()));
} else {
AggregatorAndSize aggregatorAndSize = agg.factorizeWithSize(selectors.get(agg.getName()));
aggs[i] = aggregatorAndSize.getAggregator();
totalInitialSizeBytes += aggregatorAndSize.getInitialSizeBytes();
totalInitialSizeBytes += aggReferenceSize;
}
}
rowContainer.set(null);
return totalInitialSizeBytes;
}
use of org.apache.druid.query.aggregation.AggregatorAndSize in project druid by druid-io.
the class DoubleMeanAggregationTest method testAggregateWithSize.
@Test
public void testAggregateWithSize() {
Double[] values = new Double[] { 3.0, 1.0, 2.0 };
TestObjectColumnSelector<Double> columnValueSelector = new TestObjectColumnSelector<>(values);
ColumnSelectorFactory colSelectorFactory = EasyMock.mock(ColumnSelectorFactory.class);
EasyMock.expect(colSelectorFactory.makeColumnValueSelector(EasyMock.anyString())).andReturn(columnValueSelector).anyTimes();
EasyMock.replay(colSelectorFactory);
DoubleMeanAggregatorFactory aggregatorFactory = new DoubleMeanAggregatorFactory("name", "fieldName");
AggregatorAndSize aggregatorAndSize = aggregatorFactory.factorizeWithSize(colSelectorFactory);
Assert.assertEquals(aggregatorFactory.getMaxIntermediateSize(), aggregatorAndSize.getInitialSizeBytes());
Assert.assertTrue(aggregatorAndSize.getAggregator() instanceof DoubleMeanAggregator);
Aggregator aggregator = aggregatorAndSize.getAggregator();
for (int i = 0; i < values.length; ++i) {
long sizeDelta = aggregator.aggregateWithSize();
Assert.assertEquals(0L, sizeDelta);
columnValueSelector.increment();
}
DoubleMeanHolder meanHolder = (DoubleMeanHolder) aggregator.get();
Assert.assertEquals(2.0, meanHolder.mean(), 0.0);
}
use of org.apache.druid.query.aggregation.AggregatorAndSize in project druid by druid-io.
the class SketchAggregatorFactoryTest method testFactorizeSized.
@Test
public void testFactorizeSized() {
ColumnSelectorFactory colSelectorFactory = EasyMock.mock(ColumnSelectorFactory.class);
EasyMock.expect(colSelectorFactory.makeColumnValueSelector(EasyMock.anyString())).andReturn(EasyMock.createMock(ColumnValueSelector.class)).anyTimes();
EasyMock.replay(colSelectorFactory);
AggregatorAndSize aggregatorAndSize = AGGREGATOR_16384.factorizeWithSize(colSelectorFactory);
Assert.assertEquals(48, aggregatorAndSize.getInitialSizeBytes());
aggregatorAndSize = AGGREGATOR_32768.factorizeWithSize(colSelectorFactory);
Assert.assertEquals(48, aggregatorAndSize.getInitialSizeBytes());
}
use of org.apache.druid.query.aggregation.AggregatorAndSize in project druid by druid-io.
the class SketchAggregatorFactory method factorizeWithSize.
@Override
public AggregatorAndSize factorizeWithSize(ColumnSelectorFactory metricFactory) {
BaseObjectColumnValueSelector selector = metricFactory.makeColumnValueSelector(fieldName);
final SketchAggregator aggregator = new SketchAggregator(selector, size);
return new AggregatorAndSize(aggregator, aggregator.getInitialSizeBytes());
}
use of org.apache.druid.query.aggregation.AggregatorAndSize in project druid by druid-io.
the class DoubleMeanAggregatorFactoryTest method testFactorizeWithSize.
@Test
public void testFactorizeWithSize() {
ColumnSelectorFactory colSelectorFactory = EasyMock.mock(ColumnSelectorFactory.class);
EasyMock.expect(colSelectorFactory.makeColumnValueSelector(EasyMock.anyString())).andReturn(EasyMock.createMock(ColumnValueSelector.class)).anyTimes();
EasyMock.replay(colSelectorFactory);
DoubleMeanAggregatorFactory factory = new DoubleMeanAggregatorFactory("name", "fieldName");
AggregatorAndSize aggregatorAndSize = factory.factorizeWithSize(colSelectorFactory);
Assert.assertEquals(DoubleMeanHolder.MAX_INTERMEDIATE_SIZE, aggregatorAndSize.getInitialSizeBytes());
Assert.assertTrue(aggregatorAndSize.getAggregator() instanceof DoubleMeanAggregator);
}
Aggregations