Search in sources :

Example 1 with AggregatorAndSize

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;
}
Also used : AggregatorAndSize(org.apache.druid.query.aggregation.AggregatorAndSize) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory)

Example 2 with AggregatorAndSize

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);
}
Also used : AggregatorAndSize(org.apache.druid.query.aggregation.AggregatorAndSize) TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) Aggregator(org.apache.druid.query.aggregation.Aggregator) Test(org.junit.Test)

Example 3 with AggregatorAndSize

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());
}
Also used : AggregatorAndSize(org.apache.druid.query.aggregation.AggregatorAndSize) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) Test(org.junit.Test)

Example 4 with AggregatorAndSize

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());
}
Also used : AggregatorAndSize(org.apache.druid.query.aggregation.AggregatorAndSize) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector)

Example 5 with AggregatorAndSize

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);
}
Also used : AggregatorAndSize(org.apache.druid.query.aggregation.AggregatorAndSize) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) Test(org.junit.Test)

Aggregations

AggregatorAndSize (org.apache.druid.query.aggregation.AggregatorAndSize)5 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)3 Test (org.junit.Test)3 Aggregator (org.apache.druid.query.aggregation.Aggregator)1 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)1 TestObjectColumnSelector (org.apache.druid.query.aggregation.TestObjectColumnSelector)1 BaseObjectColumnValueSelector (org.apache.druid.segment.BaseObjectColumnValueSelector)1