Search in sources :

Example 1 with HllSketchToEstimatePostAggregator

use of org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimatePostAggregator 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 2 with HllSketchToEstimatePostAggregator

use of org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimatePostAggregator in project druid by druid-io.

the class HllSketchEstimateOperatorConversion method toPostAggregator.

@Nullable
@Override
public PostAggregator toPostAggregator(PlannerContext plannerContext, RowSignature rowSignature, RexNode rexNode, PostAggregatorVisitor postAggregatorVisitor) {
    final List<RexNode> operands = ((RexCall) rexNode).getOperands();
    final PostAggregator firstOperand = OperatorConversions.toPostAggregator(plannerContext, rowSignature, operands.get(0), postAggregatorVisitor);
    if (firstOperand == null) {
        return null;
    }
    boolean round = HllSketchAggregatorFactory.DEFAULT_ROUND;
    if (operands.size() == 2) {
        if (!operands.get(1).isA(SqlKind.LITERAL)) {
            return null;
        }
        round = RexLiteral.booleanValue(operands.get(1));
    }
    return new HllSketchToEstimatePostAggregator(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), firstOperand, round);
}
Also used : RexCall(org.apache.calcite.rex.RexCall) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) HllSketchToEstimatePostAggregator(org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimatePostAggregator) HllSketchToEstimatePostAggregator(org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimatePostAggregator) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

Example 3 with HllSketchToEstimatePostAggregator

use of org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimatePostAggregator 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 }));
}
Also used : ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) ExpressionPostAggregator(org.apache.druid.query.aggregation.post.ExpressionPostAggregator) 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) HllSketchToEstimateWithBoundsPostAggregator(org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimateWithBoundsPostAggregator) HllSketchBuildAggregatorFactory(org.apache.druid.query.aggregation.datasketches.hll.HllSketchBuildAggregatorFactory) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Aggregations

HllSketchToEstimatePostAggregator (org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimatePostAggregator)3 HllSketchBuildAggregatorFactory (org.apache.druid.query.aggregation.datasketches.hll.HllSketchBuildAggregatorFactory)2 HllSketchToStringPostAggregator (org.apache.druid.query.aggregation.datasketches.hll.HllSketchToStringPostAggregator)2 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)2 FinalizingFieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator)2 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)2 BaseCalciteQueryTest (org.apache.druid.sql.calcite.BaseCalciteQueryTest)2 Test (org.junit.Test)2 Nullable (javax.annotation.Nullable)1 RexCall (org.apache.calcite.rex.RexCall)1 RexNode (org.apache.calcite.rex.RexNode)1 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)1 HllSketchToEstimateWithBoundsPostAggregator (org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimateWithBoundsPostAggregator)1 ExpressionPostAggregator (org.apache.druid.query.aggregation.post.ExpressionPostAggregator)1 ExpressionVirtualColumn (org.apache.druid.segment.virtual.ExpressionVirtualColumn)1