Search in sources :

Example 21 with PostAggregator

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

the class TDigestSketchToQuantilePostAggregatorTest method testToString.

@Test
public void testToString() {
    PostAggregator postAgg = new TDigestSketchToQuantilePostAggregator("post", new ConstantPostAggregator("", 100), 0.5);
    Assert.assertEquals("TDigestSketchToQuantilePostAggregator{name='post', field=ConstantPostAggregator{name='', constantValue=100}, fraction=0.5}", 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 22 with PostAggregator

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

the class DoublesSketchListArgBaseOperatorConversion method toPostAggregator.

@Nullable
@Override
public PostAggregator toPostAggregator(PlannerContext plannerContext, RowSignature rowSignature, RexNode rexNode, PostAggregatorVisitor postAggregatorVisitor) {
    final List<RexNode> operands = ((RexCall) rexNode).getOperands();
    final double[] args = new double[operands.size() - 1];
    PostAggregator inputSketchPostAgg = null;
    int operandCounter = 0;
    for (RexNode operand : operands) {
        final PostAggregator convertedPostAgg = OperatorConversions.toPostAggregator(plannerContext, rowSignature, operand, postAggregatorVisitor);
        if (convertedPostAgg == null) {
            if (operandCounter > 0) {
                try {
                    if (!operand.isA(SqlKind.LITERAL)) {
                        return null;
                    }
                    double arg = ((Number) RexLiteral.value(operand)).doubleValue();
                    args[operandCounter - 1] = arg;
                } catch (ClassCastException cce) {
                    return null;
                }
            } else {
                return null;
            }
        } else {
            if (operandCounter == 0) {
                inputSketchPostAgg = convertedPostAgg;
            } else {
                if (!operand.isA(SqlKind.LITERAL)) {
                    return null;
                }
            }
        }
        operandCounter++;
    }
    if (inputSketchPostAgg == null) {
        return null;
    }
    return makePostAgg(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), inputSketchPostAgg, args);
}
Also used : RexCall(org.apache.calcite.rex.RexCall) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

Example 23 with PostAggregator

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

the class DoublesSketchSingleArgBaseOperatorConversion 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;
    }
    if (!operands.get(1).isA(SqlKind.LITERAL)) {
        return null;
    }
    final float arg = ((Number) RexLiteral.value(operands.get(1))).floatValue();
    return makePostAgg(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), firstOperand, arg);
}
Also used : RexCall(org.apache.calcite.rex.RexCall) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

Example 24 with PostAggregator

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

the class DoublesSketchToHistogramPostAggregatorTest method emptySketch.

@Test
public void emptySketch() {
    final TestDoubleColumnSelectorImpl selector = new TestDoubleColumnSelectorImpl(null);
    final Aggregator agg = new DoublesSketchBuildAggregator(selector, 8);
    final Map<String, Object> fields = new HashMap<>();
    fields.put("sketch", agg.get());
    final PostAggregator postAgg = new DoublesSketchToHistogramPostAggregator("histogram", new FieldAccessPostAggregator("field", "sketch"), new double[] { 3.5 }, null);
    final double[] histogram = (double[]) postAgg.compute(fields);
    Assert.assertNotNull(histogram);
    Assert.assertEquals(2, histogram.length);
    Assert.assertTrue(Double.isNaN(histogram[0]));
    Assert.assertTrue(Double.isNaN(histogram[1]));
}
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) HashMap(java.util.HashMap) Aggregator(org.apache.druid.query.aggregation.Aggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) TestDoubleColumnSelectorImpl(org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl) Test(org.junit.Test)

Example 25 with PostAggregator

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

the class DoublesSketchToHistogramPostAggregatorTest method testToString.

@Test
public void testToString() {
    final PostAggregator postAgg = new DoublesSketchToHistogramPostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"), new double[] { 0.25, 0.75 }, null);
    Assert.assertEquals("DoublesSketchToHistogramPostAggregator{name='post', field=FieldAccessPostAggregator{name='field1', fieldName='sketch'}, splitPoints=[0.25, 0.75], numBins=null}", 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)

Aggregations

PostAggregator (org.apache.druid.query.aggregation.PostAggregator)135 Test (org.junit.Test)98 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)48 ConstantPostAggregator (org.apache.druid.query.aggregation.post.ConstantPostAggregator)41 HashMap (java.util.HashMap)29 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)21 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)20 Nullable (javax.annotation.Nullable)16 Aggregator (org.apache.druid.query.aggregation.Aggregator)13 Comparator (java.util.Comparator)12 RexCall (org.apache.calcite.rex.RexCall)11 RexNode (org.apache.calcite.rex.RexNode)11 CountAggregator (org.apache.druid.query.aggregation.CountAggregator)10 ArrayList (java.util.ArrayList)9 TestDoubleColumnSelectorImpl (org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl)9 Map (java.util.Map)8 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)8 Function (com.google.common.base.Function)7 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)7 List (java.util.List)6