use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class DoublesSketchSqlAggregatorTest method testQuantileOnInnerQuery.
@Test
public void testQuantileOnInnerQuery() throws Exception {
final List<Object[]> expectedResults;
if (NullHandling.replaceWithDefault()) {
expectedResults = ImmutableList.of(new Object[] { 7.0, 11.0 });
} else {
expectedResults = ImmutableList.of(new Object[] { 5.25, 8.0 });
}
testQuery("SELECT AVG(x), APPROX_QUANTILE_DS(x, 0.98)\n" + "FROM (SELECT dim2, SUM(m1) AS x FROM foo GROUP BY dim2)", Collections.singletonList(GroupByQuery.builder().setDataSource(new QueryDataSource(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).setGranularity(Granularities.ALL).setDimensions(new DefaultDimensionSpec("dim2", "d0")).setAggregatorSpecs(ImmutableList.of(new DoubleSumAggregatorFactory("a0", "m1"))).setContext(QUERY_CONTEXT_DEFAULT).build())).setInterval(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).setGranularity(Granularities.ALL).setAggregatorSpecs(new DoubleSumAggregatorFactory("_a0:sum", "a0"), new CountAggregatorFactory("_a0:count"), new DoublesSketchAggregatorFactory("_a1:agg", "a0", null)).setPostAggregatorSpecs(ImmutableList.of(new ArithmeticPostAggregator("_a0", "quotient", ImmutableList.of(new FieldAccessPostAggregator(null, "_a0:sum"), new FieldAccessPostAggregator(null, "_a0:count"))), new DoublesSketchToQuantilePostAggregator("_a1", makeFieldAccessPostAgg("_a1:agg"), 0.98f))).setContext(QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class HllSketchToStringPostAggregatorTest method testSerde.
@Test
public void testSerde() throws JsonProcessingException {
final PostAggregator there = new HllSketchToStringPostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"));
DefaultObjectMapper mapper = new DefaultObjectMapper();
HllSketchToStringPostAggregator andBackAgain = mapper.readValue(mapper.writeValueAsString(there), HllSketchToStringPostAggregator.class);
Assert.assertEquals(there, andBackAgain);
Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
}
use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class HllSketchToStringPostAggregatorTest method testToString.
@Test
public void testToString() {
final PostAggregator postAgg = new HllSketchToStringPostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"));
Assert.assertEquals("HllSketchToStringPostAggregator{name='post', field=FieldAccessPostAggregator{name='field1', fieldName='sketch'}}", postAgg.toString());
}
use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class HllSketchSqlAggregatorTest method testHllSketchPostAggs.
@Test
public void testHllSketchPostAggs() 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 otherSketchSummary = "### 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";
testQuery("SELECT\n" + " DS_HLL(dim2),\n" + " DS_HLL(m1),\n" + " HLL_SKETCH_ESTIMATE(DS_HLL(dim2)),\n" + " HLL_SKETCH_ESTIMATE(DS_HLL(dim2)) + 1,\n" + " HLL_SKETCH_ESTIMATE(DS_HLL(CONCAT(dim2, 'hello'))),\n" + " ABS(HLL_SKETCH_ESTIMATE(DS_HLL(dim2))),\n" + " HLL_SKETCH_ESTIMATE_WITH_ERROR_BOUNDS(DS_HLL(dim2), 2),\n" + " HLL_SKETCH_ESTIMATE_WITH_ERROR_BOUNDS(DS_HLL(dim2)),\n" + " DS_HLL(POWER(ABS(m1 + 100), 2)),\n" + " APPROX_COUNT_DISTINCT_DS_HLL(dim2),\n" + " HLL_SKETCH_TO_STRING(DS_HLL(dim2)),\n" + " UPPER(HLL_SKETCH_TO_STRING(DS_HLL(dim2))),\n" + " HLL_SKETCH_ESTIMATE(DS_HLL(dim2), true)\n" + "FROM druid.foo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).virtualColumns(new ExpressionVirtualColumn("v0", "concat(\"dim2\",'hello')", ColumnType.STRING, TestExprMacroTable.INSTANCE), new ExpressionVirtualColumn("v1", "pow(abs((\"m1\" + 100)),2)", ColumnType.DOUBLE, TestExprMacroTable.INSTANCE)).aggregators(ImmutableList.of(new HllSketchBuildAggregatorFactory("a0", "dim2", null, null, true), new HllSketchBuildAggregatorFactory("a1", "m1", null, null, true), new HllSketchBuildAggregatorFactory("a2", "v0", null, null, true), new HllSketchBuildAggregatorFactory("a3", "v1", null, null, true), new HllSketchBuildAggregatorFactory("a4", "dim2", null, null, true))).postAggregators(ImmutableList.of(new FieldAccessPostAggregator("p0", "a0"), new FieldAccessPostAggregator("p1", "a1"), new HllSketchToEstimatePostAggregator("p3", new FieldAccessPostAggregator("p2", "a0"), false), new HllSketchToEstimatePostAggregator("p5", new FieldAccessPostAggregator("p4", "a0"), false), new ExpressionPostAggregator("p6", "(\"p5\" + 1)", null, TestExprMacroTable.INSTANCE), new HllSketchToEstimatePostAggregator("p8", new FieldAccessPostAggregator("p7", "a2"), false), new HllSketchToEstimatePostAggregator("p10", new FieldAccessPostAggregator("p9", "a0"), false), new ExpressionPostAggregator("p11", "abs(\"p10\")", null, TestExprMacroTable.INSTANCE), new HllSketchToEstimateWithBoundsPostAggregator("p13", new FieldAccessPostAggregator("p12", "a0"), 2), new HllSketchToEstimateWithBoundsPostAggregator("p15", new FieldAccessPostAggregator("p14", "a0"), 1), new FieldAccessPostAggregator("p16", "a3"), new HllSketchToStringPostAggregator("p18", new FieldAccessPostAggregator("p17", "a0")), new HllSketchToStringPostAggregator("p20", new FieldAccessPostAggregator("p19", "a0")), new ExpressionPostAggregator("p21", "upper(\"p20\")", null, TestExprMacroTable.INSTANCE), new HllSketchToEstimatePostAggregator("p23", new FieldAccessPostAggregator("p22", "a0"), true))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { "\"AgEHDAMIAgDhUv8P63iABQ==\"", "\"AgEHDAMIBgALpZ0PjpTfBY5ElQo+C7UE4jA+DKfcYQQ=\"", 2.000000004967054d, 3.000000004967054d, 3.000000014901161d, 2.000000004967054d, "[2.000000004967054,2.0,2.0001997319422404]", "[2.000000004967054,2.0,2.000099863468538]", "\"AgEHDAMIBgC1EYgH1mlHBwsKPwu5SK8MIiUxB7iZVwU=\"", 2L, sketchSummary, otherSketchSummary, 2.0 }));
}
use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class HllSketchSqlAggregatorTest method testAvgDailyCountDistinctHllSketch.
@Test
public void testAvgDailyCountDistinctHllSketch() throws Exception {
// Can't vectorize due to outer query, which runs on an inline datasource.
cannotVectorize();
final List<Object[]> expectedResults = ImmutableList.of(new Object[] { 1L });
testQuery("SELECT\n" + " AVG(u)\n" + "FROM (" + " SELECT FLOOR(__time TO DAY), APPROX_COUNT_DISTINCT_DS_HLL(cnt) AS u\n" + " FROM druid.foo\n" + " GROUP BY 1\n" + ")", ImmutableList.of(GroupByQuery.builder().setDataSource(new QueryDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(new PeriodGranularity(Period.days(1), null, DateTimeZone.UTC)).aggregators(Collections.singletonList(new HllSketchBuildAggregatorFactory("a0:a", "cnt", null, null, ROUND))).postAggregators(ImmutableList.of(new FinalizingFieldAccessPostAggregator("a0", "a0:a"))).context(QUERY_CONTEXT_DEFAULT).build().withOverriddenContext(BaseCalciteQueryTest.getTimeseriesContextWithFloorTime(ImmutableMap.of(TimeseriesQuery.SKIP_EMPTY_BUCKETS, true, BaseQuery.SQL_QUERY_ID, "dummy"), "d0")))).setInterval(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).setGranularity(Granularities.ALL).setAggregatorSpecs(NullHandling.replaceWithDefault() ? Arrays.asList(new LongSumAggregatorFactory("_a0:sum", "a0"), new CountAggregatorFactory("_a0:count")) : Arrays.asList(new LongSumAggregatorFactory("_a0:sum", "a0"), new FilteredAggregatorFactory(new CountAggregatorFactory("_a0:count"), BaseCalciteQueryTest.not(BaseCalciteQueryTest.selector("a0", null, null))))).setPostAggregatorSpecs(ImmutableList.of(new ArithmeticPostAggregator("_a0", "quotient", ImmutableList.of(new FieldAccessPostAggregator(null, "_a0:sum"), new FieldAccessPostAggregator(null, "_a0:count"))))).setContext(QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
Aggregations