use of org.apache.druid.query.aggregation.last.DoubleLastAggregatorFactory in project druid by druid-io.
the class TimeseriesQueryRunnerTest method testTimeseriesWithFirstLastAggregator.
@Test
public void testTimeseriesWithFirstLastAggregator() {
// Cannot vectorize due to "doubleFirst", "doubleLast" aggregators.
cannotVectorize();
TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.MONTH_GRAN).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(ImmutableList.of(new DoubleFirstAggregatorFactory("first", "index", null), new DoubleLastAggregatorFactory("last", "index", null))).descending(descending).context(makeContext()).build();
// There's a difference between ascending and descending results since granularity of druid.sample.tsv is days,
// with multiple first and last times. The traversal order difference cause the first and last aggregator
// to select different value from the list of first and last dates
List<Result<TimeseriesResultValue>> expectedAscendingResults = ImmutableList.of(new Result<>(DateTimes.of("2011-01-01"), new TimeseriesResultValue(ImmutableMap.of("first", new Float(100.000000).doubleValue(), "last", new Float(943.497198).doubleValue()))), new Result<>(DateTimes.of("2011-02-01"), new TimeseriesResultValue(ImmutableMap.of("first", new Float(132.123776).doubleValue(), "last", new Float(1101.918270).doubleValue()))), new Result<>(DateTimes.of("2011-03-01"), new TimeseriesResultValue(ImmutableMap.of("first", new Float(153.059937).doubleValue(), "last", new Float(1063.201156).doubleValue()))), new Result<>(DateTimes.of("2011-04-01"), new TimeseriesResultValue(ImmutableMap.of("first", new Float(135.885094).doubleValue(), "last", new Float(780.271977).doubleValue()))));
List<Result<TimeseriesResultValue>> expectedDescendingResults = ImmutableList.of(new Result<>(DateTimes.of("2011-04-01"), new TimeseriesResultValue(ImmutableMap.of("first", new Float(1234.247546).doubleValue(), "last", new Float(106.793700).doubleValue()))), new Result<>(DateTimes.of("2011-03-01"), new TimeseriesResultValue(ImmutableMap.of("first", new Float(1004.940887).doubleValue(), "last", new Float(151.752485).doubleValue()))), new Result<>(DateTimes.of("2011-02-01"), new TimeseriesResultValue(ImmutableMap.of("first", new Float(913.561076).doubleValue(), "last", new Float(122.258195).doubleValue()))), new Result<>(DateTimes.of("2011-01-01"), new TimeseriesResultValue(ImmutableMap.of("first", new Float(800.000000).doubleValue(), "last", new Float(133.740047).doubleValue()))));
Iterable<Result<TimeseriesResultValue>> actualResults = runner.run(QueryPlus.wrap(query)).toList();
if (descending) {
TestHelper.assertExpectedResults(expectedDescendingResults, actualResults);
} else {
TestHelper.assertExpectedResults(expectedAscendingResults, actualResults);
}
}
Aggregations