Search in sources :

Example 6 with SerializablePairLongString

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

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

the class StringFirstTimeseriesQueryTest method testTimeseriesQuery.

@Test
public void testTimeseriesQuery() {
    TimeseriesQueryEngine engine = new TimeseriesQueryEngine();
    TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(ImmutableList.of(new StringFirstAggregatorFactory("nonfolding", CLIENT_TYPE, null, 1024), new StringFirstAggregatorFactory("folding", FIRST_CLIENT_TYPE, null, 1024), new StringFirstAggregatorFactory("nonexistent", "nonexistent", null, 1024), new StringFirstAggregatorFactory("numeric", "cnt", null, 1024))).build();
    List<Result<TimeseriesResultValue>> expectedResults = Collections.singletonList(new Result<>(TIME1, new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("nonfolding", new SerializablePairLongString(TIME1.getMillis(), "iphone")).put("folding", new SerializablePairLongString(TIME1.getMillis(), "iphone")).put("nonexistent", new SerializablePairLongString(DateTimes.MAX.getMillis(), null)).put("numeric", new SerializablePairLongString(DateTimes.MAX.getMillis(), null)).build())));
    final Iterable<Result<TimeseriesResultValue>> iiResults = engine.process(query, new IncrementalIndexStorageAdapter(incrementalIndex)).toList();
    final Iterable<Result<TimeseriesResultValue>> qiResults = engine.process(query, new QueryableIndexStorageAdapter(queryableIndex)).toList();
    TestHelper.assertExpectedResults(expectedResults, iiResults, "incremental index");
    TestHelper.assertExpectedResults(expectedResults, qiResults, "queryable index");
}
Also used : TimeseriesResultValue(org.apache.druid.query.timeseries.TimeseriesResultValue) TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) QueryableIndexStorageAdapter(org.apache.druid.segment.QueryableIndexStorageAdapter) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) Result(org.apache.druid.query.Result) TimeseriesQueryEngine(org.apache.druid.query.timeseries.TimeseriesQueryEngine) IncrementalIndexStorageAdapter(org.apache.druid.segment.incremental.IncrementalIndexStorageAdapter) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 8 with SerializablePairLongString

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

the class StringFirstLastUtilsTest method testWritePairThenReadPairAtBeginningBuffer.

@Test
public void testWritePairThenReadPairAtBeginningBuffer() {
    int positionAtBeginning = 0;
    ByteBuffer buf = ByteBuffer.allocate(BUFFER_CAPACITY);
    StringFirstLastUtils.writePair(buf, positionAtBeginning, PAIR_TO_WRITE, MAX_BYTE_TO_WRITE);
    SerializablePairLongString actual = StringFirstLastUtils.readPair(buf, positionAtBeginning);
    Assert.assertEquals(PAIR_TO_WRITE, actual);
}
Also used : SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 9 with SerializablePairLongString

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

the class StringFirstAggregationTest method testCombineLeftRightSame.

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

Example 10 with SerializablePairLongString

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

the class StringFirstAggregationTest method testCombineLeftLower.

@Test
public void testCombineLeftLower() {
    SerializablePairLongString pair1 = new SerializablePairLongString(1467225000L, "AAAA");
    SerializablePairLongString pair2 = new SerializablePairLongString(1467240000L, "BBBB");
    Assert.assertEquals(pair1, stringFirstAggFactory.combine(pair1, pair2));
}
Also used : SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) 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