Search in sources :

Example 11 with TestDoubleColumnSelectorImpl

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

the class DoublesSketchToQuantilesPostAggregatorTest method normalCase.

@Test
public void normalCase() {
    final double[] values = new double[] { 1, 2, 3, 4, 5 };
    final TestDoubleColumnSelectorImpl selector = new TestDoubleColumnSelectorImpl(values);
    final Aggregator agg = new DoublesSketchBuildAggregator(selector, 8);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < values.length; i++) {
        agg.aggregate();
        selector.increment();
    }
    final Map<String, Object> fields = new HashMap<>();
    fields.put("sketch", agg.get());
    final PostAggregator postAgg = new DoublesSketchToQuantilesPostAggregator("quantiles", new FieldAccessPostAggregator("field", "sketch"), new double[] { 0, 0.5, 1 });
    final double[] quantiles = (double[]) postAgg.compute(fields);
    Assert.assertNotNull(quantiles);
    Assert.assertEquals(3, quantiles.length);
    Assert.assertEquals(1.0, quantiles[0], 0);
    Assert.assertEquals(3.0, quantiles[1], 0);
    Assert.assertEquals(5.0, quantiles[2], 0);
}
Also used : FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) HashMap(java.util.HashMap) Aggregator(org.apache.druid.query.aggregation.Aggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) TestDoubleColumnSelectorImpl(org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl) Test(org.junit.Test)

Example 12 with TestDoubleColumnSelectorImpl

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

the class DoubleAnyAggregationTest method setup.

@Before
public void setup() {
    doubleAnyAggFactory = new DoubleAnyAggregatorFactory("billy", "nilly");
    combiningAggFactory = (DoubleAnyAggregatorFactory) doubleAnyAggFactory.getCombiningFactory();
    valueSelector = new TestDoubleColumnSelectorImpl(doubles);
    objectSelector = new TestObjectColumnSelector<>(objects);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(valueSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("billy")).andReturn(objectSelector);
    EasyMock.replay(colSelectorFactory);
}
Also used : ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) TestDoubleColumnSelectorImpl(org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl) Before(org.junit.Before)

Aggregations

TestDoubleColumnSelectorImpl (org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl)12 HashMap (java.util.HashMap)9 Aggregator (org.apache.druid.query.aggregation.Aggregator)9 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)9 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)9 Test (org.junit.Test)9 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)3 Before (org.junit.Before)3 TestLongColumnSelector (org.apache.druid.query.aggregation.TestLongColumnSelector)2