Search in sources :

Example 1 with TestObjectColumnSelector

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

the class ArrayOfDoublesSketchAggregatorFactoryTest method makeAggregateCombiner.

@Test
public void makeAggregateCombiner() {
    AggregatorFactory aggregatorFactory = new ArrayOfDoublesSketchAggregatorFactory("", "", null, null, null);
    AggregatorFactory combiningFactory = aggregatorFactory.getCombiningFactory();
    AggregateCombiner<ArrayOfDoublesSketch> combiner = combiningFactory.makeAggregateCombiner();
    ArrayOfDoublesUpdatableSketch sketch1 = new ArrayOfDoublesUpdatableSketchBuilder().build();
    sketch1.update("a", new double[] { 1 });
    ArrayOfDoublesUpdatableSketch sketch2 = new ArrayOfDoublesUpdatableSketchBuilder().build();
    sketch2.update("b", new double[] { 1 });
    sketch2.update("c", new double[] { 1 });
    TestObjectColumnSelector<ArrayOfDoublesSketch> selector = new TestObjectColumnSelector<ArrayOfDoublesSketch>(new ArrayOfDoublesSketch[] { sketch1, sketch2 });
    combiner.reset(selector);
    Assert.assertEquals(1, combiner.getObject().getEstimate(), 0);
    selector.increment();
    combiner.fold(selector);
    Assert.assertEquals(3, combiner.getObject().getEstimate(), 0);
}
Also used : ArrayOfDoublesUpdatableSketchBuilder(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketchBuilder) ArrayOfDoublesUpdatableSketch(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketch) TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) ArrayOfDoublesSketch(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch) Test(org.junit.Test)

Example 2 with TestObjectColumnSelector

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

the class StringLastBufferAggregatorTest method testNonStringValue.

@Test
public void testNonStringValue() {
    final long[] timestamps = { 1526724000L, 1526724600L };
    final Double[] doubles = { null, 2.00 };
    Integer maxStringBytes = 1024;
    TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps);
    TestObjectColumnSelector<Double> objectColumnSelector = new TestObjectColumnSelector<>(doubles);
    StringLastAggregatorFactory factory = new StringLastAggregatorFactory("billy", "billy", null, maxStringBytes);
    StringLastBufferAggregator agg = new StringLastBufferAggregator(longColumnSelector, objectColumnSelector, maxStringBytes, false);
    ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSize());
    int position = 0;
    agg.init(buf, position);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < timestamps.length; i++) {
        aggregateBuffer(longColumnSelector, objectColumnSelector, agg, buf, position);
    }
    SerializablePairLongString sp = ((SerializablePairLongString) agg.get(buf, position));
    Assert.assertEquals(1526724600L, (long) sp.lhs);
    Assert.assertEquals("2.0", sp.rhs);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) ByteBuffer(java.nio.ByteBuffer) TestLongColumnSelector(org.apache.druid.query.aggregation.TestLongColumnSelector) Test(org.junit.Test)

Example 3 with TestObjectColumnSelector

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

the class StringLastBufferAggregatorTest method testNullBufferAggregate.

@Test
public void testNullBufferAggregate() {
    final long[] timestamps = { 1111L, 2222L, 6666L, 4444L, 5555L };
    final String[] strings = { "CCCC", "AAAA", "BBBB", null, "EEEE" };
    Integer maxStringBytes = 1024;
    TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps);
    TestObjectColumnSelector<String> objectColumnSelector = new TestObjectColumnSelector<>(strings);
    StringLastAggregatorFactory factory = new StringLastAggregatorFactory("billy", "billy", null, maxStringBytes);
    StringLastBufferAggregator agg = new StringLastBufferAggregator(longColumnSelector, objectColumnSelector, maxStringBytes, false);
    ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSize());
    int position = 0;
    agg.init(buf, position);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < timestamps.length; i++) {
        aggregateBuffer(longColumnSelector, objectColumnSelector, agg, buf, position);
    }
    SerializablePairLongString sp = ((SerializablePairLongString) agg.get(buf, position));
    Assert.assertEquals("expected last string value", strings[2], sp.rhs);
    Assert.assertEquals("last string timestamp is the biggest", new Long(timestamps[2]), sp.lhs);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) ByteBuffer(java.nio.ByteBuffer) TestLongColumnSelector(org.apache.druid.query.aggregation.TestLongColumnSelector) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) Test(org.junit.Test)

Example 4 with TestObjectColumnSelector

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

the class StringLastBufferAggregatorTest method testBufferAggregate.

@Test
public void testBufferAggregate() {
    final long[] timestamps = { 1526724600L, 1526724700L, 1526724800L, 1526725900L, 1526725000L };
    final String[] strings = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE" };
    Integer maxStringBytes = 1024;
    TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps);
    TestObjectColumnSelector<String> objectColumnSelector = new TestObjectColumnSelector<>(strings);
    StringLastAggregatorFactory factory = new StringLastAggregatorFactory("billy", "billy", null, maxStringBytes);
    StringLastBufferAggregator agg = new StringLastBufferAggregator(longColumnSelector, objectColumnSelector, maxStringBytes, false);
    ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSize());
    int position = 0;
    agg.init(buf, position);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < timestamps.length; i++) {
        aggregateBuffer(longColumnSelector, objectColumnSelector, agg, buf, position);
    }
    SerializablePairLongString sp = ((SerializablePairLongString) agg.get(buf, position));
    Assert.assertEquals("expected last string value", "DDDD", sp.rhs);
    Assert.assertEquals("last string timestamp is the biggest", new Long(1526725900L), sp.lhs);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) ByteBuffer(java.nio.ByteBuffer) TestLongColumnSelector(org.apache.druid.query.aggregation.TestLongColumnSelector) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) Test(org.junit.Test)

Example 5 with TestObjectColumnSelector

use of org.apache.druid.query.aggregation.TestObjectColumnSelector 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)

Aggregations

TestObjectColumnSelector (org.apache.druid.query.aggregation.TestObjectColumnSelector)21 Test (org.junit.Test)21 ByteBuffer (java.nio.ByteBuffer)14 SerializablePairLongString (org.apache.druid.query.aggregation.SerializablePairLongString)8 TestLongColumnSelector (org.apache.druid.query.aggregation.TestLongColumnSelector)8 Aggregator (org.apache.druid.query.aggregation.Aggregator)4 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)3 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)3 AggregateCombiner (org.apache.druid.query.aggregation.AggregateCombiner)2 GroupByQueryRunnerTest (org.apache.druid.query.groupby.GroupByQueryRunnerTest)2 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)2 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ArrayOfDoublesSketch (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch)1 ArrayOfDoublesUpdatableSketch (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketch)1 ArrayOfDoublesUpdatableSketchBuilder (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketchBuilder)1 AggregatorAndSize (org.apache.druid.query.aggregation.AggregatorAndSize)1