Search in sources :

Example 21 with SerializablePairLongString

use of org.apache.druid.query.aggregation.SerializablePairLongString 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 22 with SerializablePairLongString

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

the class StringFirstAggregationTest method testCombineRightLower.

@Test
public void testCombineRightLower() {
    SerializablePairLongString pair1 = new SerializablePairLongString(1467240000L, "AAAA");
    SerializablePairLongString pair2 = new SerializablePairLongString(1467225000L, "BBBB");
    Assert.assertEquals(pair2, stringFirstAggFactory.combine(pair1, pair2));
}
Also used : SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 23 with SerializablePairLongString

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

the class StringLastBufferAggregator method aggregate.

@Override
public void aggregate(ByteBuffer buf, int position) {
    if (timeSelector.isNull()) {
        return;
    }
    if (needsFoldCheck) {
        // Less efficient code path when folding is a possibility (we must read the value selector first just in case
        // it's a foldable object).
        final SerializablePairLongString inPair = StringFirstLastUtils.readPairFromSelectors(timeSelector, valueSelector);
        if (inPair != null) {
            final long lastTime = buf.getLong(position);
            if (inPair.lhs >= lastTime) {
                StringFirstLastUtils.writePair(buf, position, new SerializablePairLongString(inPair.lhs, inPair.rhs), maxStringBytes);
            }
        }
    } else {
        final long time = timeSelector.getLong();
        final long lastTime = buf.getLong(position);
        if (time >= lastTime) {
            final String value = DimensionHandlerUtils.convertObjectToString(valueSelector.getObject());
            StringFirstLastUtils.writePair(buf, position, new SerializablePairLongString(time, value), maxStringBytes);
        }
    }
}
Also used : SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString)

Aggregations

SerializablePairLongString (org.apache.druid.query.aggregation.SerializablePairLongString)23 Test (org.junit.Test)17 ByteBuffer (java.nio.ByteBuffer)11 TestLongColumnSelector (org.apache.druid.query.aggregation.TestLongColumnSelector)8 TestObjectColumnSelector (org.apache.druid.query.aggregation.TestObjectColumnSelector)8 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)4 Result (org.apache.druid.query.Result)3 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)2 TimeseriesQueryEngine (org.apache.druid.query.timeseries.TimeseriesQueryEngine)2 TimeseriesResultValue (org.apache.druid.query.timeseries.TimeseriesResultValue)2 QueryableIndexStorageAdapter (org.apache.druid.segment.QueryableIndexStorageAdapter)2 IncrementalIndexStorageAdapter (org.apache.druid.segment.incremental.IncrementalIndexStorageAdapter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Nullable (javax.annotation.Nullable)1 TableDataSource (org.apache.druid.query.TableDataSource)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)1 StringLastAggregatorFactory (org.apache.druid.query.aggregation.last.StringLastAggregatorFactory)1 ConstantPostAggregator (org.apache.druid.query.aggregation.post.ConstantPostAggregator)1 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)1