Search in sources :

Example 16 with TestObjectColumnSelector

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

the class StringLastBufferAggregatorTest 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);
    StringLastAggregatorFactory factory = new StringLastAggregatorFactory("billy", "billy", null, maxStringBytes);
    StringLastBufferAggregator agg = new StringLastBufferAggregator(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", "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 17 with TestObjectColumnSelector

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

the class StringAnyBufferAggregatorTest method testContainsNullBufferAggregate.

@Test
public void testContainsNullBufferAggregate() {
    final String[] strings = { "CCCC", "AAAA", "BBBB", null, "EEEE" };
    Integer maxStringBytes = 1024;
    TestObjectColumnSelector<String> objectColumnSelector = new TestObjectColumnSelector<>(strings);
    StringAnyAggregatorFactory factory = new StringAnyAggregatorFactory("billy", "billy", maxStringBytes);
    StringAnyBufferAggregator agg = new StringAnyBufferAggregator(objectColumnSelector, maxStringBytes);
    ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSize());
    int position = 0;
    agg.init(buf, position);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < strings.length; i++) {
        aggregateBuffer(objectColumnSelector, agg, buf, position);
    }
    String result = ((String) agg.get(buf, position));
    Assert.assertEquals(strings[0], result);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 18 with TestObjectColumnSelector

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

the class StringAnyBufferAggregatorTest method testNullFirstBufferAggregate.

@Test
public void testNullFirstBufferAggregate() {
    final String[] strings = { null, "CCCC", "AAAA", "BBBB", "EEEE" };
    Integer maxStringBytes = 1024;
    TestObjectColumnSelector<String> objectColumnSelector = new TestObjectColumnSelector<>(strings);
    StringAnyAggregatorFactory factory = new StringAnyAggregatorFactory("billy", "billy", maxStringBytes);
    StringAnyBufferAggregator agg = new StringAnyBufferAggregator(objectColumnSelector, maxStringBytes);
    ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSize());
    int position = 0;
    agg.init(buf, position);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < strings.length; i++) {
        aggregateBuffer(objectColumnSelector, agg, buf, position);
    }
    String result = ((String) agg.get(buf, position));
    Assert.assertNull(result);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 19 with TestObjectColumnSelector

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

the class StringAnyBufferAggregatorTest method testBufferAggregate.

@Test
public void testBufferAggregate() {
    final String[] strings = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE" };
    Integer maxStringBytes = 1024;
    TestObjectColumnSelector<String> objectColumnSelector = new TestObjectColumnSelector<>(strings);
    StringAnyAggregatorFactory factory = new StringAnyAggregatorFactory("billy", "billy", maxStringBytes);
    StringAnyBufferAggregator agg = new StringAnyBufferAggregator(objectColumnSelector, maxStringBytes);
    ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSize());
    int position = 0;
    agg.init(buf, position);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < strings.length; i++) {
        aggregateBuffer(objectColumnSelector, agg, buf, position);
    }
    String result = ((String) agg.get(buf, position));
    Assert.assertEquals(strings[0], result);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 20 with TestObjectColumnSelector

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

the class StringAnyBufferAggregatorTest method testNonStringValue.

@Test
public void testNonStringValue() {
    final Double[] doubles = { 1.00, 2.00 };
    Integer maxStringBytes = 1024;
    TestObjectColumnSelector<Double> objectColumnSelector = new TestObjectColumnSelector<>(doubles);
    StringAnyAggregatorFactory factory = new StringAnyAggregatorFactory("billy", "billy", maxStringBytes);
    StringAnyBufferAggregator agg = new StringAnyBufferAggregator(objectColumnSelector, maxStringBytes);
    ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSize());
    int position = 0;
    agg.init(buf, position);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < doubles.length; i++) {
        aggregateBuffer(objectColumnSelector, agg, buf, position);
    }
    String result = ((String) agg.get(buf, position));
    Assert.assertEquals("1.0", result);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) ByteBuffer(java.nio.ByteBuffer) 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