use of io.druid.query.aggregation.first.LongFirstAggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testSubqueryWithFirstLast.
@Test
public void testSubqueryWithFirstLast() {
GroupByQuery subquery = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.fullOnInterval).setDimensions(ImmutableList.<DimensionSpec>of(new DefaultDimensionSpec("market", "market"))).setAggregatorSpecs(ImmutableList.<AggregatorFactory>of(QueryRunnerTestHelper.rowsCount, new LongFirstAggregatorFactory("innerfirst", "index"), new LongLastAggregatorFactory("innerlast", "index"))).setGranularity(QueryRunnerTestHelper.dayGran).setContext(ImmutableMap.<String, Object>of("finalize", true)).build();
GroupByQuery query = GroupByQuery.builder().setDataSource(subquery).setQuerySegmentSpec(QueryRunnerTestHelper.fullOnInterval).setDimensions(Lists.<DimensionSpec>newArrayList()).setAggregatorSpecs(ImmutableList.<AggregatorFactory>of(new LongFirstAggregatorFactory("first", "innerfirst"), new LongLastAggregatorFactory("last", "innerlast"))).setGranularity(QueryRunnerTestHelper.monthGran).build();
List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-01-01", "first", 100L, "last", 943L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-02-01", "first", 132L, "last", 1101L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-03-01", "first", 153L, "last", 1063L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "first", 135L, "last", 780L));
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "");
}
use of io.druid.query.aggregation.first.LongFirstAggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByWithNoResult.
@Test
public void testGroupByWithNoResult() {
GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.emptyInterval).setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("market", "market"))).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, QueryRunnerTestHelper.indexLongSum, QueryRunnerTestHelper.qualityCardinality, new LongFirstAggregatorFactory("first", "index"), new LongLastAggregatorFactory("last", "index"))).setGranularity(QueryRunnerTestHelper.dayGran).build();
List<Row> expectedResults = ImmutableList.of();
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
assertEquals(expectedResults, results);
}
use of io.druid.query.aggregation.first.LongFirstAggregatorFactory in project druid by druid-io.
the class TopNQueryRunnerTest method testTopNOverFirstLastAggregator.
@Test
public void testTopNOverFirstLastAggregator() {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.monthGran).dimension(QueryRunnerTestHelper.marketDimension).metric("last").threshold(3).intervals(QueryRunnerTestHelper.fullOnInterval).aggregators(Arrays.<AggregatorFactory>asList(new LongFirstAggregatorFactory("first", "index"), new LongLastAggregatorFactory("last", "index"))).build();
List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<>(new DateTime("2011-01-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>builder().put("market", "total_market").put("first", 1000L).put("last", 1127L).build(), ImmutableMap.<String, Object>builder().put("market", "upfront").put("first", 800L).put("last", 943L).build(), ImmutableMap.<String, Object>builder().put("market", "spot").put("first", 100L).put("last", 155L).build()))), new Result<>(new DateTime("2011-02-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>builder().put("market", "total_market").put("first", 1203L).put("last", 1292L).build(), ImmutableMap.<String, Object>builder().put("market", "upfront").put("first", 1667L).put("last", 1101L).build(), ImmutableMap.<String, Object>builder().put("market", "spot").put("first", 132L).put("last", 114L).build()))), new Result<>(new DateTime("2011-03-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>builder().put("market", "total_market").put("first", 1124L).put("last", 1366L).build(), ImmutableMap.<String, Object>builder().put("market", "upfront").put("first", 1166L).put("last", 1063L).build(), ImmutableMap.<String, Object>builder().put("market", "spot").put("first", 153L).put("last", 125L).build()))), new Result<>(new DateTime("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>builder().put("market", "total_market").put("first", 1314L).put("last", 1029L).build(), ImmutableMap.<String, Object>builder().put("market", "upfront").put("first", 1447L).put("last", 780L).build(), ImmutableMap.<String, Object>builder().put("market", "spot").put("first", 135L).put("last", 120L).build()))));
assertExpectedResults(expectedResults, query);
}
use of io.druid.query.aggregation.first.LongFirstAggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByWithFirstLast.
@Test
public void testGroupByWithFirstLast() {
GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.fullOnInterval).setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("market", "market"))).setAggregatorSpecs(Arrays.asList(new LongFirstAggregatorFactory("first", "index"), new LongLastAggregatorFactory("last", "index"))).setGranularity(QueryRunnerTestHelper.monthGran).build();
List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-01-01", "market", "spot", "first", 100L, "last", 155L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-01-01", "market", "total_market", "first", 1000L, "last", 1127L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-01-01", "market", "upfront", "first", 800L, "last", 943L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-02-01", "market", "spot", "first", 132L, "last", 114L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-02-01", "market", "total_market", "first", 1203L, "last", 1292L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-02-01", "market", "upfront", "first", 1667L, "last", 1101L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-03-01", "market", "spot", "first", 153L, "last", 125L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-03-01", "market", "total_market", "first", 1124L, "last", 1366L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-03-01", "market", "upfront", "first", 1166L, "last", 1063L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "market", "spot", "first", 135L, "last", 120L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "market", "total_market", "first", 1314L, "last", 1029L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "market", "upfront", "first", 1447L, "last", 780L));
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "");
}
Aggregations