Search in sources :

Example 1 with LongLastAggregatorFactory

use of io.druid.query.aggregation.last.LongLastAggregatorFactory 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, "");
}
Also used : LongLastAggregatorFactory(io.druid.query.aggregation.last.LongLastAggregatorFactory) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) LongFirstAggregatorFactory(io.druid.query.aggregation.first.LongFirstAggregatorFactory) Row(io.druid.data.input.Row) DoubleMaxAggregatorFactory(io.druid.query.aggregation.DoubleMaxAggregatorFactory) LongMaxAggregatorFactory(io.druid.query.aggregation.LongMaxAggregatorFactory) DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) LongFirstAggregatorFactory(io.druid.query.aggregation.first.LongFirstAggregatorFactory) FilteredAggregatorFactory(io.druid.query.aggregation.FilteredAggregatorFactory) JavaScriptAggregatorFactory(io.druid.query.aggregation.JavaScriptAggregatorFactory) CardinalityAggregatorFactory(io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) HyperUniquesAggregatorFactory(io.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFactory) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) LongLastAggregatorFactory(io.druid.query.aggregation.last.LongLastAggregatorFactory) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 2 with LongLastAggregatorFactory

use of io.druid.query.aggregation.last.LongLastAggregatorFactory 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);
}
Also used : DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) LongLastAggregatorFactory(io.druid.query.aggregation.last.LongLastAggregatorFactory) LongFirstAggregatorFactory(io.druid.query.aggregation.first.LongFirstAggregatorFactory) Row(io.druid.data.input.Row) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 3 with LongLastAggregatorFactory

use of io.druid.query.aggregation.last.LongLastAggregatorFactory 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);
}
Also used : LongLastAggregatorFactory(io.druid.query.aggregation.last.LongLastAggregatorFactory) LongFirstAggregatorFactory(io.druid.query.aggregation.first.LongFirstAggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) DoubleFirstAggregatorFactory(io.druid.query.aggregation.first.DoubleFirstAggregatorFactory) DoubleMaxAggregatorFactory(io.druid.query.aggregation.DoubleMaxAggregatorFactory) HyperUniquesAggregatorFactory(io.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFactory) DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) LongFirstAggregatorFactory(io.druid.query.aggregation.first.LongFirstAggregatorFactory) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) FilteredAggregatorFactory(io.druid.query.aggregation.FilteredAggregatorFactory) DoubleMinAggregatorFactory(io.druid.query.aggregation.DoubleMinAggregatorFactory) CardinalityAggregatorFactory(io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) LongLastAggregatorFactory(io.druid.query.aggregation.last.LongLastAggregatorFactory) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) Test(org.junit.Test)

Example 4 with LongLastAggregatorFactory

use of io.druid.query.aggregation.last.LongLastAggregatorFactory 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, "");
}
Also used : DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) LongLastAggregatorFactory(io.druid.query.aggregation.last.LongLastAggregatorFactory) LongFirstAggregatorFactory(io.druid.query.aggregation.first.LongFirstAggregatorFactory) Row(io.druid.data.input.Row) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Aggregations

LongFirstAggregatorFactory (io.druid.query.aggregation.first.LongFirstAggregatorFactory)4 LongLastAggregatorFactory (io.druid.query.aggregation.last.LongLastAggregatorFactory)4 Test (org.junit.Test)4 Row (io.druid.data.input.Row)3 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)3 DimensionSpec (io.druid.query.dimension.DimensionSpec)3 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)3 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)3 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)3 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)2 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)2 DoubleMaxAggregatorFactory (io.druid.query.aggregation.DoubleMaxAggregatorFactory)2 DoubleSumAggregatorFactory (io.druid.query.aggregation.DoubleSumAggregatorFactory)2 FilteredAggregatorFactory (io.druid.query.aggregation.FilteredAggregatorFactory)2 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)2 CardinalityAggregatorFactory (io.druid.query.aggregation.cardinality.CardinalityAggregatorFactory)2 HyperUniquesAggregatorFactory (io.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFactory)2 Result (io.druid.query.Result)1 DoubleMinAggregatorFactory (io.druid.query.aggregation.DoubleMinAggregatorFactory)1 JavaScriptAggregatorFactory (io.druid.query.aggregation.JavaScriptAggregatorFactory)1