use of org.apache.druid.query.aggregation.DoubleSumAggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByNestedWithInnerQueryOutputNullNumerics.
@Test
public void testGroupByNestedWithInnerQueryOutputNullNumerics() {
cannotVectorize();
if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
}
// Following extractionFn will generate null value for one kind of quality
ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(new ContainsSearchQuerySpec("1200", false));
GroupByQuery subquery = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias"), new ExtractionDimensionSpec("qualityLong", "ql_alias", ColumnType.LONG, extractionFn), new ExtractionDimensionSpec("qualityFloat", "qf_alias", ColumnType.FLOAT, extractionFn), new ExtractionDimensionSpec("qualityDouble", "qd_alias", ColumnType.DOUBLE, extractionFn)).setDimFilter(new InDimFilter("quality", Arrays.asList("entertainment", "business"), null)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
GroupByQuery outerQuery = makeQueryBuilder().setDataSource(subquery).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("ql_alias", "quallong", ColumnType.LONG), new DefaultDimensionSpec("qf_alias", "qualfloat", ColumnType.FLOAT), new DefaultDimensionSpec("qd_alias", "qualdouble", ColumnType.DOUBLE)).setAggregatorSpecs(new LongSumAggregatorFactory("ql_alias_sum", "ql_alias"), new DoubleSumAggregatorFactory("qf_alias_sum", "qf_alias"), new DoubleSumAggregatorFactory("qd_alias_sum", "qd_alias")).setGranularity(QueryRunnerTestHelper.ALL_GRAN).build();
List<ResultRow> expectedResults = Arrays.asList(makeRow(outerQuery, "2011-04-01", "quallong", NullHandling.defaultLongValue(), "qualfloat", NullHandling.defaultFloatValue(), "qualdouble", NullHandling.defaultDoubleValue(), "ql_alias_sum", NullHandling.defaultLongValue(), "qf_alias_sum", NullHandling.defaultFloatValue(), "qd_alias_sum", NullHandling.defaultDoubleValue()), makeRow(outerQuery, "2011-04-01", "quallong", 1200L, "qualfloat", 12000.0, "qualdouble", 12000.0, "ql_alias_sum", 2400L, "qf_alias_sum", 24000.0, "qd_alias_sum", 24000.0));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, outerQuery);
TestHelper.assertExpectedObjects(expectedResults, results, "numerics");
}
use of org.apache.druid.query.aggregation.DoubleSumAggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByNestedWithInnerQueryNumerics.
@Test
public void testGroupByNestedWithInnerQueryNumerics() {
if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
}
GroupByQuery subquery = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias"), new DefaultDimensionSpec("qualityLong", "ql_alias", ColumnType.LONG), new DefaultDimensionSpec("qualityFloat", "qf_alias", ColumnType.FLOAT)).setDimFilter(new InDimFilter("quality", Collections.singletonList("entertainment"), null)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
GroupByQuery outerQuery = makeQueryBuilder().setDataSource(subquery).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("ql_alias", "quallong", ColumnType.LONG), new DefaultDimensionSpec("qf_alias", "qualfloat", ColumnType.FLOAT)).setDimFilter(new AndDimFilter(Lists.newArrayList(new SelectorDimFilter("ql_alias", "1200", null), new BoundDimFilter("qf_alias", "11095.0", "12005.0", true, true, null, null, StringComparators.NUMERIC)))).setAggregatorSpecs(new LongSumAggregatorFactory("ql_alias_sum", "ql_alias"), new DoubleSumAggregatorFactory("qf_alias_sum", "qf_alias")).setGranularity(QueryRunnerTestHelper.ALL_GRAN).build();
List<ResultRow> expectedResults = Collections.singletonList(makeRow(outerQuery, "2011-04-01", "quallong", 1200L, "qualfloat", 12000.0, "ql_alias_sum", 2400L, "qf_alias_sum", 24000.0));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, outerQuery);
TestHelper.assertExpectedObjects(expectedResults, results, "numerics");
}
use of org.apache.druid.query.aggregation.DoubleSumAggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByWithSubtotalsSpecWithRenamedDimensionAndFilter.
// https://github.com/apache/druid/issues/7820
@Test
public void testGroupByWithSubtotalsSpecWithRenamedDimensionAndFilter() {
if (!config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V2)) {
return;
}
GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setVirtualColumns(new ExpressionVirtualColumn("alias", "quality", ColumnType.STRING, TestExprMacroTable.INSTANCE)).setDimensions(Lists.newArrayList(new DefaultDimensionSpec("quality", "quality"), new DefaultDimensionSpec("market", "market"), new DefaultDimensionSpec("alias", "alias_renamed"))).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index"), new FloatSumAggregatorFactory("idxFloat", "indexFloat"), new DoubleSumAggregatorFactory("idxDouble", "index"))).setDimFilter(new SelectorDimFilter("alias", "automotive", null)).setGranularity(QueryRunnerTestHelper.DAY_GRAN).setSubtotalsSpec(ImmutableList.of(ImmutableList.of("alias_renamed"), ImmutableList.of())).build();
List<ResultRow> expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "alias_renamed", "automotive", "rows", 1L, "idx", 135L, "idxFloat", 135.88510131835938f, "idxDouble", 135.88510131835938d), makeRow(query, "2011-04-02", "alias_renamed", "automotive", "rows", 1L, "idx", 147L, "idxFloat", 147.42593f, "idxDouble", 147.42593d), makeRow(query, "2011-04-01T00:00:00.000Z", "rows", 1L, "idx", 135L, "idxFloat", 135.88510131835938f, "idxDouble", 135.88510131835938d), makeRow(query, "2011-04-02T00:00:00.000Z", "rows", 1L, "idx", 147L, "idxFloat", 147.42593f, "idxDouble", 147.42593d));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "subtotal");
}
use of org.apache.druid.query.aggregation.DoubleSumAggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByOrderLimit.
@Test
public void testGroupByOrderLimit() {
GroupByQuery.Builder builder = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setInterval("2011-04-02/2011-04-04").setDimensions(new DefaultDimensionSpec("quality", "alias")).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).addOrderByColumn("rows").addOrderByColumn("alias", OrderByColumnSpec.Direction.DESCENDING).setGranularity(new PeriodGranularity(new Period("P1M"), null, null));
final GroupByQuery query = builder.build();
List<ResultRow> expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "alias", "travel", "rows", 2L, "idx", 243L), makeRow(query, "2011-04-01", "alias", "technology", "rows", 2L, "idx", 177L), makeRow(query, "2011-04-01", "alias", "news", "rows", 2L, "idx", 221L), makeRow(query, "2011-04-01", "alias", "health", "rows", 2L, "idx", 216L), makeRow(query, "2011-04-01", "alias", "entertainment", "rows", 2L, "idx", 319L), makeRow(query, "2011-04-01", "alias", "business", "rows", 2L, "idx", 217L), makeRow(query, "2011-04-01", "alias", "automotive", "rows", 2L, "idx", 269L), makeRow(query, "2011-04-01", "alias", "premium", "rows", 6L, "idx", 4416L), makeRow(query, "2011-04-01", "alias", "mezzanine", "rows", 6L, "idx", 4420L));
QueryRunner<ResultRow> mergeRunner = factory.getToolchest().mergeResults(runner);
TestHelper.assertExpectedObjects(expectedResults, mergeRunner.run(QueryPlus.wrap(query)), "no-limit");
TestHelper.assertExpectedObjects(Iterables.limit(expectedResults, 5), mergeRunner.run(QueryPlus.wrap(builder.setLimit(5).build())), "limited");
// Now try it with an expression based aggregator.
List<AggregatorFactory> aggregatorSpecs = Arrays.asList(QueryRunnerTestHelper.ROWS_COUNT, new DoubleSumAggregatorFactory("idx", null, "index / 2 + indexMin", TestExprMacroTable.INSTANCE));
builder.setLimit(Integer.MAX_VALUE).setAggregatorSpecs(aggregatorSpecs);
expectedResults = makeRows(builder.build(), new String[] { "__time", "alias", "rows", "idx" }, new Object[] { "2011-04-01", "travel", 2L, 365.4876403808594D }, new Object[] { "2011-04-01", "technology", 2L, 267.3737487792969D }, new Object[] { "2011-04-01", "news", 2L, 333.3147277832031D }, new Object[] { "2011-04-01", "health", 2L, 325.467529296875D }, new Object[] { "2011-04-01", "entertainment", 2L, 479.916015625D }, new Object[] { "2011-04-01", "business", 2L, 328.083740234375D }, new Object[] { "2011-04-01", "automotive", 2L, 405.5966796875D }, new Object[] { "2011-04-01", "premium", 6L, 6627.927734375D }, new Object[] { "2011-04-01", "mezzanine", 6L, 6635.47998046875D });
TestHelper.assertExpectedObjects(expectedResults, mergeRunner.run(QueryPlus.wrap(builder.build())), "no-limit");
TestHelper.assertExpectedObjects(Iterables.limit(expectedResults, 5), mergeRunner.run(QueryPlus.wrap(builder.setLimit(5).build())), "limited");
// Now try it with an expression virtual column.
ExpressionVirtualColumn expressionVirtualColumn = new ExpressionVirtualColumn("expr", "index / 2 + indexMin", ColumnType.FLOAT, TestExprMacroTable.INSTANCE);
List<AggregatorFactory> aggregatorSpecs2 = Arrays.asList(QueryRunnerTestHelper.ROWS_COUNT, new DoubleSumAggregatorFactory("idx", "expr"));
builder.setLimit(Integer.MAX_VALUE).setVirtualColumns(expressionVirtualColumn).setAggregatorSpecs(aggregatorSpecs2);
TestHelper.assertExpectedObjects(expectedResults, mergeRunner.run(QueryPlus.wrap(builder.build())), "no-limit");
TestHelper.assertExpectedObjects(Iterables.limit(expectedResults, 5), mergeRunner.run(QueryPlus.wrap(builder.setLimit(5).build())), "limited");
}
use of org.apache.druid.query.aggregation.DoubleSumAggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupBy.
@Test
public void testGroupBy() {
GroupByQuery query = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias")).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index"), new FloatSumAggregatorFactory("idxFloat", "indexFloat"), new DoubleSumAggregatorFactory("idxDouble", "index")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
List<ResultRow> expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "alias", "automotive", "rows", 1L, "idx", 135L, "idxFloat", 135.88510131835938f, "idxDouble", 135.88510131835938d), makeRow(query, "2011-04-01", "alias", "business", "rows", 1L, "idx", 118L, "idxFloat", 118.57034, "idxDouble", 118.57034), makeRow(query, "2011-04-01", "alias", "entertainment", "rows", 1L, "idx", 158L, "idxFloat", 158.747224, "idxDouble", 158.747224), makeRow(query, "2011-04-01", "alias", "health", "rows", 1L, "idx", 120L, "idxFloat", 120.134704, "idxDouble", 120.134704), makeRow(query, "2011-04-01", "alias", "mezzanine", "rows", 3L, "idx", 2870L, "idxFloat", 2871.8866900000003f, "idxDouble", 2871.8866900000003d), makeRow(query, "2011-04-01", "alias", "news", "rows", 1L, "idx", 121L, "idxFloat", 121.58358f, "idxDouble", 121.58358d), makeRow(query, "2011-04-01", "alias", "premium", "rows", 3L, "idx", 2900L, "idxFloat", 2900.798647f, "idxDouble", 2900.798647d), makeRow(query, "2011-04-01", "alias", "technology", "rows", 1L, "idx", 78L, "idxFloat", 78.622547f, "idxDouble", 78.622547d), makeRow(query, "2011-04-01", "alias", "travel", "rows", 1L, "idx", 119L, "idxFloat", 119.922742f, "idxDouble", 119.922742d), makeRow(query, "2011-04-02", "alias", "automotive", "rows", 1L, "idx", 147L, "idxFloat", 147.42593f, "idxDouble", 147.42593d), makeRow(query, "2011-04-02", "alias", "business", "rows", 1L, "idx", 112L, "idxFloat", 112.987027f, "idxDouble", 112.987027d), makeRow(query, "2011-04-02", "alias", "entertainment", "rows", 1L, "idx", 166L, "idxFloat", 166.016049f, "idxDouble", 166.016049d), makeRow(query, "2011-04-02", "alias", "health", "rows", 1L, "idx", 113L, "idxFloat", 113.446008f, "idxDouble", 113.446008d), makeRow(query, "2011-04-02", "alias", "mezzanine", "rows", 3L, "idx", 2447L, "idxFloat", 2448.830613f, "idxDouble", 2448.830613d), makeRow(query, "2011-04-02", "alias", "news", "rows", 1L, "idx", 114L, "idxFloat", 114.290141f, "idxDouble", 114.290141d), makeRow(query, "2011-04-02", "alias", "premium", "rows", 3L, "idx", 2505L, "idxFloat", 2506.415148f, "idxDouble", 2506.415148d), makeRow(query, "2011-04-02", "alias", "technology", "rows", 1L, "idx", 97L, "idxFloat", 97.387433f, "idxDouble", 97.387433d), makeRow(query, "2011-04-02", "alias", "travel", "rows", 1L, "idx", 126L, "idxFloat", 126.411364f, "idxDouble", 126.411364d));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "groupBy");
}
Aggregations