Search in sources :

Example 6 with TestDoubleColumnSelectorImpl

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

the class DoublesSketchToRankPostAggregatorTest method emptySketch.

@Test
public void emptySketch() {
    final TestDoubleColumnSelectorImpl selector = new TestDoubleColumnSelectorImpl(null);
    final Aggregator agg = new DoublesSketchBuildAggregator(selector, 8);
    final Map<String, Object> fields = new HashMap<>();
    fields.put("sketch", agg.get());
    final PostAggregator postAgg = new DoublesSketchToRankPostAggregator("rank", new FieldAccessPostAggregator("field", "sketch"), 0);
    final double rank = (double) postAgg.compute(fields);
    Assert.assertTrue(Double.isNaN(rank));
}
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 7 with TestDoubleColumnSelectorImpl

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

the class DoubleLastAggregationTest method setup.

@Before
public void setup() {
    doubleLastAggFactory = new DoubleLastAggregatorFactory("billy", "nilly", null);
    combiningAggFactory = (DoubleLastAggregatorFactory) doubleLastAggFactory.getCombiningFactory();
    timeSelector = new TestLongColumnSelector(times);
    customTimeSelector = new TestLongColumnSelector(customTimes);
    valueSelector = new TestDoubleColumnSelectorImpl(doubles);
    objectSelector = new TestObjectColumnSelector<>(pairs);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector(ColumnHolder.TIME_COLUMN_NAME)).andReturn(timeSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("customTime")).andReturn(customTimeSelector);
    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) TestLongColumnSelector(org.apache.druid.query.aggregation.TestLongColumnSelector) TestDoubleColumnSelectorImpl(org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl) Before(org.junit.Before)

Example 8 with TestDoubleColumnSelectorImpl

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

the class DoubleFirstAggregationTest method setup.

@Before
public void setup() {
    doubleFirstAggFactory = new DoubleFirstAggregatorFactory("billy", "nilly", null);
    combiningAggFactory = (DoubleFirstAggregatorFactory) doubleFirstAggFactory.getCombiningFactory();
    timeSelector = new TestLongColumnSelector(times);
    customTimeSelector = new TestLongColumnSelector(customTimes);
    valueSelector = new TestDoubleColumnSelectorImpl(doubleValues);
    objectSelector = new TestObjectColumnSelector<>(pairs);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector(ColumnHolder.TIME_COLUMN_NAME)).andReturn(timeSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("customTime")).andReturn(customTimeSelector);
    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) TestLongColumnSelector(org.apache.druid.query.aggregation.TestLongColumnSelector) TestDoubleColumnSelectorImpl(org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl) Before(org.junit.Before)

Example 9 with TestDoubleColumnSelectorImpl

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

the class DoublesSketchToHistogramPostAggregatorTest method splitPoints.

@Test
public void splitPoints() {
    final double[] values = new double[] { 1, 2, 3, 4, 5, 6 };
    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 DoublesSketchToHistogramPostAggregator("histogram", new FieldAccessPostAggregator("field", "sketch"), // splits distribution into two bins of equal mass
    new double[] { 3.5 }, null);
    final double[] histogram = (double[]) postAgg.compute(fields);
    Assert.assertNotNull(histogram);
    Assert.assertEquals(2, histogram.length);
    Assert.assertEquals(3.0, histogram[0], 0);
    Assert.assertEquals(3.0, histogram[1], 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 10 with TestDoubleColumnSelectorImpl

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

the class DoublesSketchToHistogramPostAggregatorTest method numBins.

@Test
public void numBins() {
    final double[] values = new double[] { 1, 2, 3, 4, 5, 6 };
    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 DoublesSketchToHistogramPostAggregator("histogram", new FieldAccessPostAggregator("field", "sketch"), null, // two bins of equal mass
    2);
    final double[] histogram = (double[]) postAgg.compute(fields);
    Assert.assertNotNull(histogram);
    Assert.assertEquals(2, histogram.length);
    Assert.assertEquals(3.0, histogram[0], 0);
    Assert.assertEquals(3.0, histogram[1], 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)

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