Search in sources :

Example 6 with TestFloatColumnSelector

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

the class FloatAnyAggregationTest method setup.

@Before
public void setup() {
    floatAnyAggFactory = new FloatAnyAggregatorFactory("billy", "nilly");
    combiningAggFactory = (FloatAnyAggregatorFactory) floatAnyAggFactory.getCombiningFactory();
    valueSelector = new TestFloatColumnSelector(floats);
    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 : TestFloatColumnSelector(org.apache.druid.query.aggregation.TestFloatColumnSelector) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) Before(org.junit.Before)

Example 7 with TestFloatColumnSelector

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

the class ApproximateHistogramPostAggregatorTest method testApproxHistogramCompute.

@Test
public void testApproxHistogramCompute() {
    ApproximateHistogram ah = buildHistogram(10, VALUES);
    final TestFloatColumnSelector selector = new TestFloatColumnSelector(VALUES);
    ApproximateHistogramAggregator agg = new ApproximateHistogramAggregator(selector, 10, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < VALUES.length; i++) {
        agg.aggregate();
        selector.increment();
    }
    Map<String, Object> metricValues = new HashMap<String, Object>();
    metricValues.put("price", agg.get());
    ApproximateHistogramPostAggregator approximateHistogramPostAggregator = new EqualBucketsPostAggregator("approxHist", "price", 5);
    Assert.assertEquals(ah.toHistogram(5), approximateHistogramPostAggregator.compute(metricValues));
}
Also used : TestFloatColumnSelector(org.apache.druid.query.aggregation.TestFloatColumnSelector) HashMap(java.util.HashMap) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 8 with TestFloatColumnSelector

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

the class ApproximateHistogramAggregatorTest method testBufferAggregate.

@Test
public void testBufferAggregate() {
    final float[] values = { 23, 19, 10, 16, 36, 2, 9, 32, 30, 45 };
    final int resolution = 5;
    final int numBuckets = 5;
    final TestFloatColumnSelector selector = new TestFloatColumnSelector(values);
    ApproximateHistogramAggregatorFactory factory = new ApproximateHistogramAggregatorFactory("billy", "billy", resolution, numBuckets, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, false);
    ApproximateHistogramBufferAggregator agg = new ApproximateHistogramBufferAggregator(selector, resolution);
    ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSizeWithNulls());
    int position = 0;
    agg.init(buf, position);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < values.length; i++) {
        aggregateBuffer(selector, agg, buf, position);
    }
    ApproximateHistogram h = ((ApproximateHistogram) agg.get(buf, position));
    Assert.assertArrayEquals("final bin positions don't match expected positions", new float[] { 2, 9.5f, 19.33f, 32.67f, 45f }, h.positions, 0.01f);
    Assert.assertArrayEquals("final bin counts don't match expected counts", new long[] { 1, 2, 3, 3, 1 }, h.bins());
    Assert.assertEquals("getMin value doesn't match expected getMin", 2, h.min(), 0);
    Assert.assertEquals("getMax value doesn't match expected getMax", 45, h.max(), 0);
    Assert.assertEquals("bin count doesn't match expected bin count", 5, h.binCount());
}
Also used : TestFloatColumnSelector(org.apache.druid.query.aggregation.TestFloatColumnSelector) ByteBuffer(java.nio.ByteBuffer) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 9 with TestFloatColumnSelector

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

the class FixedBucketsHistogramBufferAggregatorTest method testBufferAggregate.

@Test
public void testBufferAggregate() {
    final float[] values = { 23, 19, 10, 16, 36, 2, 9, 32, 30, 45 };
    final TestFloatColumnSelector selector = new TestFloatColumnSelector(values);
    FixedBucketsHistogramAggregatorFactory factory = new FixedBucketsHistogramAggregatorFactory("billy", "billy", 5, 0, 50, FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW, false);
    FixedBucketsHistogramBufferAggregator agg = new FixedBucketsHistogramBufferAggregator(selector, 0, 50, 5, FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW);
    ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSizeWithNulls());
    int position = 0;
    agg.init(buf, position);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < values.length; i++) {
        aggregateBuffer(selector, agg, buf, position);
    }
    FixedBucketsHistogram h = ((FixedBucketsHistogram) agg.get(buf, position));
    Assert.assertArrayEquals("final bin counts don't match expected counts", new long[] { 2, 3, 1, 3, 1 }, h.getHistogram());
    Assert.assertEquals("getMin value doesn't match expected getMin", 2, h.getMin(), 0);
    Assert.assertEquals("getMax value doesn't match expected getMax", 45, h.getMax(), 0);
    Assert.assertEquals("count doesn't match expected count", 10, h.getCount());
}
Also used : TestFloatColumnSelector(org.apache.druid.query.aggregation.TestFloatColumnSelector) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

TestFloatColumnSelector (org.apache.druid.query.aggregation.TestFloatColumnSelector)9 Test (org.junit.Test)5 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)4 Before (org.junit.Before)4 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)3 ByteBuffer (java.nio.ByteBuffer)2 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)2 TestLongColumnSelector (org.apache.druid.query.aggregation.TestLongColumnSelector)2 HashMap (java.util.HashMap)1