Search in sources :

Example 11 with TestObjectColumnSelector

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

the class SketchAggregationTest method testUpdateUnionWithNullInList.

@Test
public void testUpdateUnionWithNullInList() {
    List<String> value = new ArrayList<>();
    value.add("foo");
    value.add(null);
    value.add("");
    value.add("bar");
    List[] columnValues = new List[] { value };
    final TestObjectColumnSelector selector = new TestObjectColumnSelector(columnValues);
    final Aggregator agg = new SketchAggregator(selector, 4096);
    agg.aggregate();
    Assert.assertFalse(agg.isNull());
    Assert.assertNotNull(agg.get());
    Assert.assertTrue(agg.get() instanceof SketchHolder);
    Assert.assertEquals(2, ((SketchHolder) agg.get()).getEstimate(), 0);
    Assert.assertNotNull(((SketchHolder) agg.get()).getSketch());
    Assert.assertEquals(2, ((SketchHolder) agg.get()).getSketch().getEstimate(), 0);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) ArrayList(java.util.ArrayList) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) Aggregator(org.apache.druid.query.aggregation.Aggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) GroupByQueryRunnerTest(org.apache.druid.query.groupby.GroupByQueryRunnerTest) Test(org.junit.Test)

Example 12 with TestObjectColumnSelector

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

the class SketchAggregationTest method testUpdateUnionWithDouble.

@Test
public void testUpdateUnionWithDouble() {
    Double[] columnValues = new Double[] { 2.0 };
    final TestObjectColumnSelector selector = new TestObjectColumnSelector(columnValues);
    final Aggregator agg = new SketchAggregator(selector, 4096);
    agg.aggregate();
    Assert.assertFalse(agg.isNull());
    Assert.assertNotNull(agg.get());
    Assert.assertTrue(agg.get() instanceof SketchHolder);
    Assert.assertEquals(1, ((SketchHolder) agg.get()).getEstimate(), 0);
    Assert.assertNotNull(((SketchHolder) agg.get()).getSketch());
    Assert.assertEquals(1, ((SketchHolder) agg.get()).getSketch().getEstimate(), 0);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) Aggregator(org.apache.druid.query.aggregation.Aggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) GroupByQueryRunnerTest(org.apache.druid.query.groupby.GroupByQueryRunnerTest) Test(org.junit.Test)

Example 13 with TestObjectColumnSelector

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

the class SketchToStringPostAggregatorTest method testCompute.

@Test
public void testCompute() {
    // not going to iterate over the selector since getting a summary of an empty sketch is sufficient
    final TestObjectColumnSelector selector = new TestObjectColumnSelector(new Object[0]);
    final Aggregator agg = new SketchAggregator(selector, 4096);
    final Map<String, Object> fields = new HashMap<>();
    fields.put("sketch", agg.get());
    final PostAggregator postAgg = new SketchToStringPostAggregator("summary", new FieldAccessPostAggregator("field", "sketch"));
    final String summary = (String) postAgg.compute(fields);
    Assert.assertNotNull(summary);
    Assert.assertTrue(summary.contains("SUMMARY"));
}
Also used : FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) 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) Test(org.junit.Test)

Example 14 with TestObjectColumnSelector

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

the class VarianceAggregatorTest method testObjectVarianceBufferAggregatorWithZeroCount.

@Test
public void testObjectVarianceBufferAggregatorWithZeroCount() {
    VarianceAggregatorCollector holder1 = new VarianceAggregatorCollector().add(1.1f);
    VarianceAggregatorCollector holder2 = new VarianceAggregatorCollector().add(2.7f);
    VarianceAggregatorCollector holder3 = new VarianceAggregatorCollector();
    VarianceAggregatorCollector[] values = { holder1, holder2, holder3 };
    TestObjectColumnSelector<VarianceAggregatorCollector> selector = new TestObjectColumnSelector(values);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(selector);
    EasyMock.expect(colSelectorFactory.getColumnCapabilities("nilly")).andReturn(new ColumnCapabilitiesImpl().setType(VarianceAggregatorFactory.TYPE));
    EasyMock.replay(colSelectorFactory);
    VarianceBufferAggregator agg = (VarianceBufferAggregator) aggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[aggFactory.getMaxIntermediateSizeWithNulls()]);
    agg.init(buffer, 0);
    assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 0, 0d, 0d);
    aggregate(selector, agg, buffer, 0);
    assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 1, 1.1d, 0d);
    aggregate(selector, agg, buffer, 0);
    assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 2, 3.8d, 1.28d);
    aggregate(selector, agg, buffer, 0);
    assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 2, 3.8d, 1.28d);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) ByteBuffer(java.nio.ByteBuffer) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 15 with TestObjectColumnSelector

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

the class StringFirstBufferAggregatorTest 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);
    StringFirstAggregatorFactory factory = new StringFirstAggregatorFactory("billy", "billy", null, maxStringBytes);
    StringFirstBufferAggregator agg = new StringFirstBufferAggregator(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[0], sp.rhs);
    Assert.assertEquals("last string timestamp is the biggest", new Long(timestamps[0]), 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)

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