Search in sources :

Example 1 with SerializablePairLongString

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

the class TimeseriesQueryQueryToolChestTest method testCacheStrategy.

@Test
public void testCacheStrategy() throws Exception {
    CacheStrategy<Result<TimeseriesResultValue>, Object, TimeseriesQuery> strategy = TOOL_CHEST.getCacheStrategy(new TimeseriesQuery(new TableDataSource("dummy"), new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2015-01-01/2015-01-02"))), descending, VirtualColumns.EMPTY, null, Granularities.ALL, ImmutableList.of(new CountAggregatorFactory("metric1"), new LongSumAggregatorFactory("metric0", "metric0"), new StringLastAggregatorFactory("complexMetric", "test", null, null)), ImmutableList.of(new ConstantPostAggregator("post", 10)), 0, null));
    final Result<TimeseriesResultValue> result1 = new Result<>(// test timestamps that result in integer size millis
    DateTimes.utc(123L), new TimeseriesResultValue(ImmutableMap.of("metric1", 2, "metric0", 3, "complexMetric", new SerializablePairLongString(123L, "val1"))));
    Object preparedValue = strategy.prepareForSegmentLevelCache().apply(result1);
    ObjectMapper objectMapper = TestHelper.makeJsonMapper();
    Object fromCacheValue = objectMapper.readValue(objectMapper.writeValueAsBytes(preparedValue), strategy.getCacheObjectClazz());
    Result<TimeseriesResultValue> fromCacheResult = strategy.pullFromSegmentLevelCache().apply(fromCacheValue);
    Assert.assertEquals(result1, fromCacheResult);
    final Result<TimeseriesResultValue> result2 = new Result<>(// test timestamps that result in integer size millis
    DateTimes.utc(123L), new TimeseriesResultValue(ImmutableMap.of("metric1", 2, "metric0", 3, "complexMetric", "val1", "post", 10)));
    Object preparedResultLevelCacheValue = strategy.prepareForCache(true).apply(result2);
    Object fromResultLevelCacheValue = objectMapper.readValue(objectMapper.writeValueAsBytes(preparedResultLevelCacheValue), strategy.getCacheObjectClazz());
    Result<TimeseriesResultValue> fromResultLevelCacheRes = strategy.pullFromCache(true).apply(fromResultLevelCacheValue);
    Assert.assertEquals(result2, fromResultLevelCacheRes);
    final Result<TimeseriesResultValue> result3 = new Result<>(// null timestamp similar to grandTotal
    null, new TimeseriesResultValue(ImmutableMap.of("metric1", 2, "metric0", 3, "complexMetric", "val1", "post", 10)));
    preparedResultLevelCacheValue = strategy.prepareForCache(true).apply(result3);
    fromResultLevelCacheValue = objectMapper.readValue(objectMapper.writeValueAsBytes(preparedResultLevelCacheValue), strategy.getCacheObjectClazz());
    fromResultLevelCacheRes = strategy.pullFromCache(true).apply(fromResultLevelCacheValue);
    Assert.assertEquals(result3, fromResultLevelCacheRes);
}
Also used : LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) StringLastAggregatorFactory(org.apache.druid.query.aggregation.last.StringLastAggregatorFactory) ConstantPostAggregator(org.apache.druid.query.aggregation.post.ConstantPostAggregator) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) Result(org.apache.druid.query.Result) TableDataSource(org.apache.druid.query.TableDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with SerializablePairLongString

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

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

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

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

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