Search in sources :

Example 6 with TestObjectColumnSelector

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

the class StringLastAggregationTest method testStringLastAggregateCombiner.

@Test
public void testStringLastAggregateCombiner() {
    TestObjectColumnSelector columnSelector = new TestObjectColumnSelector<>(pairs);
    AggregateCombiner stringFirstAggregateCombiner = combiningAggFactory.makeAggregateCombiner();
    stringFirstAggregateCombiner.reset(columnSelector);
    Assert.assertEquals(pairs[0], stringFirstAggregateCombiner.getObject());
    columnSelector.increment();
    stringFirstAggregateCombiner.fold(columnSelector);
    Assert.assertEquals(pairs[1], stringFirstAggregateCombiner.getObject());
    stringFirstAggregateCombiner.reset(columnSelector);
    Assert.assertEquals(pairs[1], stringFirstAggregateCombiner.getObject());
}
Also used : AggregateCombiner(org.apache.druid.query.aggregation.AggregateCombiner) TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) Test(org.junit.Test)

Example 7 with TestObjectColumnSelector

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

the class StringFirstBufferAggregatorTest method testNoStringValue.

@Test
public void testNoStringValue() {
    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);
    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(1526724000L, (long) sp.lhs);
    Assert.assertEquals(null, 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 8 with TestObjectColumnSelector

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

the class StringFirstBufferAggregatorTest method testBufferAggregateWithFoldCheck.

@Test
public void testBufferAggregateWithFoldCheck() {
    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, true);
    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)

Example 9 with TestObjectColumnSelector

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

the class StringFirstAggregationTest method testStringFirstAggregateCombiner.

@Test
public void testStringFirstAggregateCombiner() {
    TestObjectColumnSelector columnSelector = new TestObjectColumnSelector<>(pairs);
    AggregateCombiner stringFirstAggregateCombiner = combiningAggFactory.makeAggregateCombiner();
    stringFirstAggregateCombiner.reset(columnSelector);
    Assert.assertEquals(pairs[0], stringFirstAggregateCombiner.getObject());
    columnSelector.increment();
    stringFirstAggregateCombiner.fold(columnSelector);
    Assert.assertEquals(pairs[0], stringFirstAggregateCombiner.getObject());
    stringFirstAggregateCombiner.reset(columnSelector);
    Assert.assertEquals(pairs[1], stringFirstAggregateCombiner.getObject());
}
Also used : AggregateCombiner(org.apache.druid.query.aggregation.AggregateCombiner) TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 10 with TestObjectColumnSelector

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

the class StringFirstBufferAggregatorTest method testNullBufferAggregate.

@Test
public void testNullBufferAggregate() {
    final long[] timestamps = { 2222L, 1111L, 3333L, 4444L, 5555L };
    final String[] strings = { null, "AAAA", "BBBB", "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[1], sp.rhs);
    Assert.assertEquals("last string timestamp is the biggest", new Long(timestamps[1]), 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