Search in sources :

Example 56 with ConstantPostAggregator

use of org.apache.druid.query.aggregation.post.ConstantPostAggregator in project druid by druid-io.

the class VarianceGroupByQueryTest method testGroupByZtestPostAgg.

@Test
public void testGroupByZtestPostAgg() {
    // test postaggs from 'teststats' package in here since we've already gone to the trouble of setting up the test
    GroupByQuery query = queryBuilder.setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias")).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, VarianceTestHelper.INDEX_VARIANCE_AGGR, new LongSumAggregatorFactory("idx", "index")).setPostAggregatorSpecs(ImmutableList.of(VarianceTestHelper.STD_DEV_OF_INDEX_POST_AGGR, // these inputs are totally nonsensical, i just want the code path to be executed
    new ZtestPostAggregator("ztest", new FieldAccessPostAggregator("f1", "idx"), new ConstantPostAggregator("f2", 100000L), new FieldAccessPostAggregator("f3", "index_stddev"), new ConstantPostAggregator("f2", 100000L)))).setLimitSpec(new DefaultLimitSpec(OrderByColumnSpec.descending("ztest"), 1)).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
    VarianceTestHelper.RowBuilder builder = new VarianceTestHelper.RowBuilder(new String[] { "alias", "rows", "idx", "index_stddev", "index_var", "ztest" });
    List<ResultRow> expectedResults = builder.add("2011-04-01", "premium", 3L, 2900.0, 726.632270328514, 527994.4562827706, 36.54266309285626).build(query);
    Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    TestHelper.assertExpectedObjects(expectedResults, results, "groupBy");
}
Also used : ResultRow(org.apache.druid.query.groupby.ResultRow) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ConstantPostAggregator(org.apache.druid.query.aggregation.post.ConstantPostAggregator) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ZtestPostAggregator(org.apache.druid.query.aggregation.teststats.ZtestPostAggregator) GroupByQuery(org.apache.druid.query.groupby.GroupByQuery) GroupByQueryRunnerTest(org.apache.druid.query.groupby.GroupByQueryRunnerTest) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 57 with ConstantPostAggregator

use of org.apache.druid.query.aggregation.post.ConstantPostAggregator in project druid by druid-io.

the class ArrayOfDoublesSketchToQuantilesSketchPostAggregatorTest method testToString.

@Test
public void testToString() {
    PostAggregator postAgg = new ArrayOfDoublesSketchToQuantilesSketchPostAggregator("a", new ConstantPostAggregator("", 0), 2, 16);
    Assert.assertEquals("ArrayOfDoublesSketchToQuantilesSketchPostAggregator{name='a', field=ConstantPostAggregator{name='', constantValue=0}, column=2, k=16}", postAgg.toString());
}
Also used : PostAggregator(org.apache.druid.query.aggregation.PostAggregator) ConstantPostAggregator(org.apache.druid.query.aggregation.post.ConstantPostAggregator) ConstantPostAggregator(org.apache.druid.query.aggregation.post.ConstantPostAggregator) Test(org.junit.Test)

Example 58 with ConstantPostAggregator

use of org.apache.druid.query.aggregation.post.ConstantPostAggregator in project druid by druid-io.

the class ArrayOfDoublesSketchToVariancesPostAggregatorTest method testResultArraySignature.

@Test
public void testResultArraySignature() {
    final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2000/3000").granularity(Granularities.HOUR).aggregators(new CountAggregatorFactory("count")).postAggregators(new ArrayOfDoublesSketchToVariancesPostAggregator("a", new ConstantPostAggregator("", 0))).build();
    Assert.assertEquals(RowSignature.builder().addTimeColumn().add("count", ColumnType.LONG).add("a", ColumnType.DOUBLE_ARRAY).build(), new TimeseriesQueryQueryToolChest().resultArraySignature(query));
}
Also used : TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) ConstantPostAggregator(org.apache.druid.query.aggregation.post.ConstantPostAggregator) TimeseriesQueryQueryToolChest(org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest) Test(org.junit.Test)

Example 59 with ConstantPostAggregator

use of org.apache.druid.query.aggregation.post.ConstantPostAggregator in project druid by druid-io.

the class ArrayOfDoublesSketchToStringPostAggregatorTest method testComparator.

@Test
public void testComparator() {
    expectedException.expect(IAE.class);
    expectedException.expectMessage("Comparing sketch summaries is not supported");
    final PostAggregator postAgg = new ArrayOfDoublesSketchToStringPostAggregator("a", new ConstantPostAggregator("", 0));
    postAgg.getComparator();
}
Also used : PostAggregator(org.apache.druid.query.aggregation.PostAggregator) ConstantPostAggregator(org.apache.druid.query.aggregation.post.ConstantPostAggregator) ConstantPostAggregator(org.apache.druid.query.aggregation.post.ConstantPostAggregator) Test(org.junit.Test)

Example 60 with ConstantPostAggregator

use of org.apache.druid.query.aggregation.post.ConstantPostAggregator in project druid by druid-io.

the class ArrayOfDoublesSketchToStringPostAggregatorTest method testSerde.

@Test
public void testSerde() throws JsonProcessingException {
    final PostAggregator there = new ArrayOfDoublesSketchToStringPostAggregator("a", new ConstantPostAggregator("", 0));
    DefaultObjectMapper mapper = new DefaultObjectMapper();
    ArrayOfDoublesSketchToStringPostAggregator andBackAgain = mapper.readValue(mapper.writeValueAsString(there), ArrayOfDoublesSketchToStringPostAggregator.class);
    Assert.assertEquals(there, andBackAgain);
    Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
}
Also used : PostAggregator(org.apache.druid.query.aggregation.PostAggregator) ConstantPostAggregator(org.apache.druid.query.aggregation.post.ConstantPostAggregator) ConstantPostAggregator(org.apache.druid.query.aggregation.post.ConstantPostAggregator) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

ConstantPostAggregator (org.apache.druid.query.aggregation.post.ConstantPostAggregator)61 Test (org.junit.Test)58 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)33 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)14 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)14 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)12 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)11 ArithmeticPostAggregator (org.apache.druid.query.aggregation.post.ArithmeticPostAggregator)10 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)9 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)8 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)8 TimeseriesQueryQueryToolChest (org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)4 Result (org.apache.druid.query.Result)3 TableDataSource (org.apache.druid.query.TableDataSource)3 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)3 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)3 EqualToHavingSpec (org.apache.druid.query.groupby.having.EqualToHavingSpec)3 GreaterThanHavingSpec (org.apache.druid.query.groupby.having.GreaterThanHavingSpec)3