Search in sources :

Example 81 with FieldAccessPostAggregator

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());
}
Also used : FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) Test(org.junit.Test)

Example 82 with FieldAccessPostAggregator

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);
}
Also used : SketchMergeAggregatorFactory(org.apache.druid.query.aggregation.datasketches.theta.SketchMergeAggregatorFactory) FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) SketchEstimatePostAggregator(org.apache.druid.query.aggregation.datasketches.theta.SketchEstimatePostAggregator) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 83 with FieldAccessPostAggregator

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));
}
Also used : FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) TimeseriesQueryQueryToolChest(org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest) Test(org.junit.Test)

Example 84 with FieldAccessPostAggregator

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);
}
Also used : ArithmeticPostAggregator(org.apache.druid.query.aggregation.post.ArithmeticPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) DoubleSumAggregatorFactory(org.apache.druid.query.aggregation.DoubleSumAggregatorFactory) ArithmeticPostAggregator(org.apache.druid.query.aggregation.post.ArithmeticPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) ConstantPostAggregator(org.apache.druid.query.aggregation.post.ConstantPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) DoubleSumAggregatorFactory(org.apache.druid.query.aggregation.DoubleSumAggregatorFactory) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) Test(org.junit.Test)

Example 85 with FieldAccessPostAggregator

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");
}
Also used : ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)108 Test (org.junit.Test)97 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)45 ArithmeticPostAggregator (org.apache.druid.query.aggregation.post.ArithmeticPostAggregator)32 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)30 FinalizingFieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator)24 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)22 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)22 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)17 TimeseriesQueryQueryToolChest (org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest)17 ConstantPostAggregator (org.apache.druid.query.aggregation.post.ConstantPostAggregator)15 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)15 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)14 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)12 HashMap (java.util.HashMap)11 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)11 QueryDataSource (org.apache.druid.query.QueryDataSource)10 Aggregator (org.apache.druid.query.aggregation.Aggregator)10 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)10 BaseCalciteQueryTest (org.apache.druid.sql.calcite.BaseCalciteQueryTest)10