use of org.apache.druid.query.aggregation.CountAggregatorFactory in project druid by druid-io.
the class QueriesTest method testVerifyAggregationsMultiLevel.
@Test
public void testVerifyAggregationsMultiLevel() {
List<AggregatorFactory> aggFactories = Arrays.asList(new CountAggregatorFactory("count"), new DoubleSumAggregatorFactory("idx", "index"), new DoubleSumAggregatorFactory("rev", "revenue"));
List<PostAggregator> postAggs = Arrays.asList(new ArithmeticPostAggregator("divideStuff", "/", Arrays.asList(new ArithmeticPostAggregator("addStuff", "+", Arrays.asList(new FieldAccessPostAggregator("idx", "idx"), new ConstantPostAggregator("const", 1))), new ArithmeticPostAggregator("subtractStuff", "-", Arrays.asList(new FieldAccessPostAggregator("rev", "rev"), new ConstantPostAggregator("const", 1))))), new ArithmeticPostAggregator("addStuff", "+", Arrays.asList(new FieldAccessPostAggregator("divideStuff", "divideStuff"), new FieldAccessPostAggregator("count", "count"))));
boolean exceptionOccured = false;
try {
Queries.prepareAggregations(ImmutableList.of(), aggFactories, postAggs);
} catch (IllegalArgumentException e) {
exceptionOccured = true;
}
Assert.assertFalse(exceptionOccured);
}
use of org.apache.druid.query.aggregation.CountAggregatorFactory in project druid by druid-io.
the class QueriesTest method testVerifyAggregations.
@Test
public void testVerifyAggregations() {
List<AggregatorFactory> aggFactories = Arrays.asList(new CountAggregatorFactory("count"), new DoubleSumAggregatorFactory("idx", "index"), new DoubleSumAggregatorFactory("rev", "revenue"));
List<PostAggregator> postAggs = Collections.singletonList(new ArithmeticPostAggregator("addStuff", "+", Arrays.asList(new FieldAccessPostAggregator("idx", "idx"), new FieldAccessPostAggregator("count", "count"))));
boolean exceptionOccured = false;
try {
Queries.prepareAggregations(ImmutableList.of(), aggFactories, postAggs);
} catch (IllegalArgumentException e) {
exceptionOccured = true;
}
Assert.assertFalse(exceptionOccured);
}
use of org.apache.druid.query.aggregation.CountAggregatorFactory in project druid by druid-io.
the class QueriesTest method testVerifyAggregationsMultiLevelMissingVal.
@Test
public void testVerifyAggregationsMultiLevelMissingVal() {
List<AggregatorFactory> aggFactories = Arrays.asList(new CountAggregatorFactory("count"), new DoubleSumAggregatorFactory("idx", "index"), new DoubleSumAggregatorFactory("rev", "revenue"));
List<PostAggregator> postAggs = Arrays.asList(new ArithmeticPostAggregator("divideStuff", "/", Arrays.asList(new ArithmeticPostAggregator("addStuff", "+", Arrays.asList(new FieldAccessPostAggregator("idx", "idx"), new ConstantPostAggregator("const", 1))), new ArithmeticPostAggregator("subtractStuff", "-", Arrays.asList(new FieldAccessPostAggregator("rev", "rev2"), new ConstantPostAggregator("const", 1))))), new ArithmeticPostAggregator("addStuff", "+", Arrays.asList(new FieldAccessPostAggregator("divideStuff", "divideStuff"), new FieldAccessPostAggregator("count", "count"))));
boolean exceptionOccured = false;
try {
Queries.prepareAggregations(ImmutableList.of(), aggFactories, postAggs);
} catch (IllegalArgumentException e) {
exceptionOccured = true;
}
Assert.assertTrue(exceptionOccured);
}
use of org.apache.druid.query.aggregation.CountAggregatorFactory in project druid by druid-io.
the class VectorizedVirtualColumnTest method testGroupByNoVirtual.
private void testGroupByNoVirtual(ColumnCapabilities capabilities, Map<String, Object> context) {
GroupByQuery query = new GroupByQuery.Builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setGranularity(Granularities.ALL).setVirtualColumns().addDimension(new DefaultDimensionSpec("placement", "placement", capabilities.toColumnType())).setAggregatorSpecs(new CountAggregatorFactory(COUNT)).setInterval("2000/2030").setContext(context).build();
List<ResultRow> rows = groupByTestHelper.runQueryOnSegmentsObjs(segments, query).toList();
List<ResultRow> expectedRows = Collections.singletonList(GroupByQueryRunnerTestHelper.createExpectedRow(query, "2000", COUNT, 2418L, "placement", "preferred"));
TestHelper.assertExpectedObjects(expectedRows, rows, "failed");
}
use of org.apache.druid.query.aggregation.CountAggregatorFactory in project druid by druid-io.
the class DummyStringVirtualColumnTest method testTopN.
private void testTopN(List<Segment> segments, boolean enableRowBasedMethods, boolean enableColumnBasedMethods) {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(Granularities.ALL).dimension(VSTRING_DIM).metric(COUNT).threshold(1).aggregators(new CountAggregatorFactory(COUNT)).virtualColumns(new DummyStringVirtualColumn(QueryRunnerTestHelper.MARKET_DIMENSION, VSTRING_DIM, enableRowBasedMethods, enableColumnBasedMethods, false, true)).intervals("2000/2030").build();
List rows = topNTestHelper.runQueryOnSegmentsObjs(segments, query).toList();
List<Result<TopNResultValue>> expectedRows = Collections.singletonList(new Result<>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Collections.<Map<String, Object>>singletonList(ImmutableMap.<String, Object>builder().put(COUNT, 1674L).put(VSTRING_DIM, "spot").build()))));
TestHelper.assertExpectedResults(expectedRows, (List<Result<TopNResultValue>>) rows, "failed");
}
Aggregations