Search in sources :

Example 6 with DoubleLastAggregatorFactory

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);
    }
}
Also used : DoubleLastAggregatorFactory(org.apache.druid.query.aggregation.last.DoubleLastAggregatorFactory) DoubleFirstAggregatorFactory(org.apache.druid.query.aggregation.first.DoubleFirstAggregatorFactory) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

DoubleLastAggregatorFactory (org.apache.druid.query.aggregation.last.DoubleLastAggregatorFactory)6 Test (org.junit.Test)5 FloatLastAggregatorFactory (org.apache.druid.query.aggregation.last.FloatLastAggregatorFactory)3 LongLastAggregatorFactory (org.apache.druid.query.aggregation.last.LongLastAggregatorFactory)3 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)2 DoubleFirstAggregatorFactory (org.apache.druid.query.aggregation.first.DoubleFirstAggregatorFactory)2 FloatFirstAggregatorFactory (org.apache.druid.query.aggregation.first.FloatFirstAggregatorFactory)2 StringFirstAggregatorFactory (org.apache.druid.query.aggregation.first.StringFirstAggregatorFactory)2 FinalizingFieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator)2 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)2 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)2 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)2 File (java.io.File)1 DoubleDimensionSchema (org.apache.druid.data.input.impl.DoubleDimensionSchema)1 FloatDimensionSchema (org.apache.druid.data.input.impl.FloatDimensionSchema)1 LongDimensionSchema (org.apache.druid.data.input.impl.LongDimensionSchema)1 StringDimensionSchema (org.apache.druid.data.input.impl.StringDimensionSchema)1 JavaScriptConfig (org.apache.druid.js.JavaScriptConfig)1 Result (org.apache.druid.query.Result)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1