Search in sources :

Example 51 with FieldAccessPostAggregator

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

the class HllSketchToEstimatePostAggregatorTest method testResultArraySignature.

@Test
public void testResultArraySignature() {
    final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2000/3000").granularity(Granularities.HOUR).aggregators(new CountAggregatorFactory("count"), new HllSketchMergeAggregatorFactory("hllMerge", "col", null, null, false)).postAggregators(new HllSketchToEstimatePostAggregator("hllEstimate", new FieldAccessPostAggregator(null, "hllMerge"), false), new HllSketchToEstimatePostAggregator("hllEstimateRound", new FieldAccessPostAggregator(null, "hllMerge"), true)).build();
    Assert.assertEquals(RowSignature.builder().addTimeColumn().add("count", ColumnType.LONG).add("hllMerge", null).add("hllEstimate", ColumnType.DOUBLE).add("hllEstimateRound", ColumnType.LONG).build(), new TimeseriesQueryQueryToolChest().resultArraySignature(query));
}
Also used : FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) TimeseriesQueryQueryToolChest(org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest) Test(org.junit.Test)

Example 52 with FieldAccessPostAggregator

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

the class HllSketchToEstimatePostAggregatorTest method testToString.

@Test
public void testToString() {
    final PostAggregator postAgg = new HllSketchToEstimatePostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"), true);
    Assert.assertEquals("HllSketchToEstimatePostAggregator{name='post', field=FieldAccessPostAggregator{name='field1', fieldName='sketch'}, round=true}", 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 53 with FieldAccessPostAggregator

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

the class HllSketchToEstimatePostAggregatorTest method testSerde.

@Test
public void testSerde() throws JsonProcessingException {
    final PostAggregator there = new HllSketchToEstimatePostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"), true);
    DefaultObjectMapper mapper = new DefaultObjectMapper();
    HllSketchToEstimatePostAggregator andBackAgain = mapper.readValue(mapper.writeValueAsString(there), HllSketchToEstimatePostAggregator.class);
    Assert.assertEquals(there, andBackAgain);
    Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
}
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) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 54 with FieldAccessPostAggregator

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

the class HllSketchSqlAggregatorTest method testtHllSketchPostAggsPostSort.

@Test
public void testtHllSketchPostAggsPostSort() throws Exception {
    final String sketchSummary = "### HLL SKETCH SUMMARY: \n" + "  Log Config K   : 12\n" + "  Hll Target     : HLL_4\n" + "  Current Mode   : LIST\n" + "  Memory         : false\n" + "  LB             : 2.0\n" + "  Estimate       : 2.000000004967054\n" + "  UB             : 2.000099863468538\n" + "  OutOfOrder Flag: false\n" + "  Coupon Count   : 2\n";
    final String sql = "SELECT DS_HLL(dim2) as y FROM druid.foo ORDER BY HLL_SKETCH_ESTIMATE(DS_HLL(dim2)) DESC LIMIT 10";
    testQuery(StringUtils.format("SELECT HLL_SKETCH_ESTIMATE(y), HLL_SKETCH_TO_STRING(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 HllSketchBuildAggregatorFactory("a0", "dim2", null, null, true))).postAggregators(ImmutableList.of(new FieldAccessPostAggregator("p0", "a0"), new HllSketchToEstimatePostAggregator("p2", new FieldAccessPostAggregator("p1", "a0"), false), new HllSketchToEstimatePostAggregator("s1", new FieldAccessPostAggregator("s0", "p0"), false), new HllSketchToStringPostAggregator("s3", new FieldAccessPostAggregator("s2", "p0")))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 2.000000004967054d, sketchSummary }));
}
Also used : FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) HllSketchToEstimatePostAggregator(org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimatePostAggregator) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) HllSketchToStringPostAggregator(org.apache.druid.query.aggregation.datasketches.hll.HllSketchToStringPostAggregator) HllSketchBuildAggregatorFactory(org.apache.druid.query.aggregation.datasketches.hll.HllSketchBuildAggregatorFactory) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 55 with FieldAccessPostAggregator

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

the class HllSketchAggregatorFactoryTest method testResultArraySignature.

@Test
public void testResultArraySignature() {
    final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2000/3000").granularity(Granularities.HOUR).aggregators(new CountAggregatorFactory("count"), new HllSketchBuildAggregatorFactory("hllBuild", "col", null, null, false), new HllSketchBuildAggregatorFactory("hllBuildRound", "col", null, null, true), new HllSketchMergeAggregatorFactory("hllMerge", "col", null, null, false), new HllSketchMergeAggregatorFactory("hllMergeRound", "col", null, null, true)).postAggregators(new FieldAccessPostAggregator("hllBuild-access", "hllBuild"), new FinalizingFieldAccessPostAggregator("hllBuild-finalize", "hllBuild"), new FieldAccessPostAggregator("hllBuildRound-access", "hllBuildRound"), new FinalizingFieldAccessPostAggregator("hllBuildRound-finalize", "hllBuildRound"), new FieldAccessPostAggregator("hllMerge-access", "hllMerge"), new FinalizingFieldAccessPostAggregator("hllMerge-finalize", "hllMerge"), new FieldAccessPostAggregator("hllMergeRound-access", "hllMergeRound"), new FinalizingFieldAccessPostAggregator("hllMergeRound-finalize", "hllMergeRound")).build();
    Assert.assertEquals(RowSignature.builder().addTimeColumn().add("count", ColumnType.LONG).add("hllBuild", null).add("hllBuildRound", null).add("hllMerge", null).add("hllMergeRound", null).add("hllBuild-access", HllSketchBuildAggregatorFactory.TYPE).add("hllBuild-finalize", ColumnType.DOUBLE).add("hllBuildRound-access", HllSketchBuildAggregatorFactory.TYPE).add("hllBuildRound-finalize", ColumnType.LONG).add("hllMerge-access", HllSketchMergeAggregatorFactory.TYPE).add("hllMerge-finalize", ColumnType.DOUBLE).add("hllMergeRound-access", HllSketchMergeAggregatorFactory.TYPE).add("hllMergeRound-finalize", ColumnType.LONG).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)

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