use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class SketchToStringPostAggregatorTest method testToString.
@Test
public void testToString() {
final PostAggregator postAgg = new SketchToStringPostAggregator("summary", new FieldAccessPostAggregator("field", "sketch"));
Assert.assertEquals("SketchToStringPostAggregator{name='summary', field=FieldAccessPostAggregator{name='field', fieldName='sketch'}}", postAgg.toString());
}
use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class ThetaSketchSqlAggregatorTest method testThetaSketchPostAggsPostSort.
@Test
public void testThetaSketchPostAggsPostSort() throws Exception {
final String sql = "SELECT DS_THETA(dim2) as y FROM druid.foo ORDER BY THETA_SKETCH_ESTIMATE(DS_THETA(dim2)) DESC LIMIT 10";
final List<Object[]> expectedResults = ImmutableList.of(new Object[] { 2.0d });
testQuery(StringUtils.format("SELECT THETA_SKETCH_ESTIMATE(y) from (%s)", sql), ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).aggregators(ImmutableList.of(new SketchMergeAggregatorFactory("a0", "dim2", null, null, null, null))).postAggregators(new FieldAccessPostAggregator("p0", "a0"), new SketchEstimatePostAggregator("p2", new FieldAccessPostAggregator("p1", "a0"), null), new SketchEstimatePostAggregator("s1", new FieldAccessPostAggregator("s0", "p0"), null)).context(QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class ArrayOfDoublesSketchAggregatorFactoryTest method testResultArraySignature.
@Test
public void testResultArraySignature() {
final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2000/3000").granularity(Granularities.HOUR).aggregators(new CountAggregatorFactory("count"), new ArrayOfDoublesSketchAggregatorFactory("arrayOfDoublesSketch", "col", 1, ImmutableList.of("met"), 1)).postAggregators(new FieldAccessPostAggregator("a", "arrayOfDoublesSketch"), new FinalizingFieldAccessPostAggregator("b", "arrayOfDoublesSketch")).build();
Assert.assertEquals(RowSignature.builder().addTimeColumn().add("count", ColumnType.LONG).add("arrayOfDoublesSketch", null).add("a", ArrayOfDoublesSketchModule.BUILD_TYPE).add("b", ColumnType.DOUBLE).build(), new TimeseriesQueryQueryToolChest().resultArraySignature(query));
}
use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class QueriesTest method testVerifyAggregationsMissingVal.
@Test
public void testVerifyAggregationsMissingVal() {
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", "idx2"), 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.post.FieldAccessPostAggregator in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByWithSubtotalsSpecGeneral.
@Test
public void testGroupByWithSubtotalsSpecGeneral() {
if (!config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V2)) {
return;
}
GroupByQuery query = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setVirtualColumns(new ExpressionVirtualColumn("alias", "quality", ColumnType.STRING, TestExprMacroTable.INSTANCE)).setDimensions(Lists.newArrayList(new DefaultDimensionSpec("quality", "quality2"), new DefaultDimensionSpec("market", "market2"), new DefaultDimensionSpec("alias", "alias2"))).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index"))).setPostAggregatorSpecs(Collections.singletonList(new FieldAccessPostAggregator("idxPostAgg", "idx"))).setGranularity(QueryRunnerTestHelper.DAY_GRAN).setSubtotalsSpec(ImmutableList.of(ImmutableList.of("alias2"), ImmutableList.of("market2"), ImmutableList.of())).build();
List<ResultRow> expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "alias2", "automotive", "rows", 1L, "idx", 135L, "idxPostAgg", 135L), makeRow(query, "2011-04-01", "alias2", "business", "rows", 1L, "idx", 118L, "idxPostAgg", 118L), makeRow(query, "2011-04-01", "alias2", "entertainment", "rows", 1L, "idx", 158L, "idxPostAgg", 158L), makeRow(query, "2011-04-01", "alias2", "health", "rows", 1L, "idx", 120L, "idxPostAgg", 120L), makeRow(query, "2011-04-01", "alias2", "mezzanine", "rows", 3L, "idx", 2870L, "idxPostAgg", 2870L), makeRow(query, "2011-04-01", "alias2", "news", "rows", 1L, "idx", 121L, "idxPostAgg", 121L), makeRow(query, "2011-04-01", "alias2", "premium", "rows", 3L, "idx", 2900L, "idxPostAgg", 2900L), makeRow(query, "2011-04-01", "alias2", "technology", "rows", 1L, "idx", 78L, "idxPostAgg", 78L), makeRow(query, "2011-04-01", "alias2", "travel", "rows", 1L, "idx", 119L, "idxPostAgg", 119L), makeRow(query, "2011-04-02", "alias2", "automotive", "rows", 1L, "idx", 147L, "idxPostAgg", 147L), makeRow(query, "2011-04-02", "alias2", "business", "rows", 1L, "idx", 112L, "idxPostAgg", 112L), makeRow(query, "2011-04-02", "alias2", "entertainment", "rows", 1L, "idx", 166L, "idxPostAgg", 166L), makeRow(query, "2011-04-02", "alias2", "health", "rows", 1L, "idx", 113L, "idxPostAgg", 113L), makeRow(query, "2011-04-02", "alias2", "mezzanine", "rows", 3L, "idx", 2447L, "idxPostAgg", 2447L), makeRow(query, "2011-04-02", "alias2", "news", "rows", 1L, "idx", 114L, "idxPostAgg", 114L), makeRow(query, "2011-04-02", "alias2", "premium", "rows", 3L, "idx", 2505L, "idxPostAgg", 2505L), makeRow(query, "2011-04-02", "alias2", "technology", "rows", 1L, "idx", 97L, "idxPostAgg", 97L), makeRow(query, "2011-04-02", "alias2", "travel", "rows", 1L, "idx", 126L, "idxPostAgg", 126L), makeRow(query, "2011-04-01T00:00:00.000Z", "market2", "spot", "rows", 9L, "idx", 1102L, "idxPostAgg", 1102L), makeRow(query, "2011-04-01T00:00:00.000Z", "market2", "total_market", "rows", 2L, "idx", 2836L, "idxPostAgg", 2836L), makeRow(query, "2011-04-01T00:00:00.000Z", "market2", "upfront", "rows", 2L, "idx", 2681L, "idxPostAgg", 2681L), makeRow(query, "2011-04-02T00:00:00.000Z", "market2", "spot", "rows", 9L, "idx", 1120L, "idxPostAgg", 1120L), makeRow(query, "2011-04-02T00:00:00.000Z", "market2", "total_market", "rows", 2L, "idx", 2514L, "idxPostAgg", 2514L), makeRow(query, "2011-04-02T00:00:00.000Z", "market2", "upfront", "rows", 2L, "idx", 2193L, "idxPostAgg", 2193L), makeRow(query, "2011-04-01T00:00:00.000Z", "rows", 13L, "idx", 6619L, "idxPostAgg", 6619L), makeRow(query, "2011-04-02T00:00:00.000Z", "rows", 13L, "idx", 5827L, "idxPostAgg", 5827L));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "subtotal");
}
Aggregations