Search in sources :

Example 31 with PostAggregator

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

the class DoublesSketchToStringPostAggregatorTest method testComparator.

@Test
public void testComparator() {
    expectedException.expect(IAE.class);
    expectedException.expectMessage("Comparing sketch summaries is not supported");
    final PostAggregator postAgg = new DoublesSketchToStringPostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"));
    postAgg.getComparator();
}
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 32 with PostAggregator

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

the class DoublesSketchToStringPostAggregatorTest method testSerde.

@Test
public void testSerde() throws JsonProcessingException {
    final PostAggregator there = new DoublesSketchToStringPostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"));
    DefaultObjectMapper mapper = new DefaultObjectMapper();
    DoublesSketchToStringPostAggregator andBackAgain = mapper.readValue(mapper.writeValueAsString(there), DoublesSketchToStringPostAggregator.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 33 with PostAggregator

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

the class ThetaSketchSetBaseOperatorConversion method toPostAggregator.

@Nullable
@Override
public PostAggregator toPostAggregator(PlannerContext plannerContext, RowSignature rowSignature, RexNode rexNode, PostAggregatorVisitor postAggregatorVisitor) {
    final List<RexNode> operands = ((RexCall) rexNode).getOperands();
    final List<PostAggregator> inputPostAggs = new ArrayList<>();
    Integer size = 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;
                    }
                    size = RexLiteral.intValue(operand);
                } catch (ClassCastException cce) {
                    return null;
                }
            } else {
                return null;
            }
        } else {
            inputPostAggs.add(convertedPostAgg);
            operandCounter++;
        }
    }
    return new SketchSetPostAggregator(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), getSetOperationName(), size, inputPostAggs);
}
Also used : RexCall(org.apache.calcite.rex.RexCall) SketchSetPostAggregator(org.apache.druid.query.aggregation.datasketches.theta.SketchSetPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) SketchSetPostAggregator(org.apache.druid.query.aggregation.datasketches.theta.SketchSetPostAggregator) ArrayList(java.util.ArrayList) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

Example 34 with PostAggregator

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

the class HllSketchToEstimateWithBoundsPostAggregatorTest method testSerde.

@Test
public void testSerde() throws JsonProcessingException {
    final PostAggregator there = new HllSketchToEstimateWithBoundsPostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"), 2);
    DefaultObjectMapper mapper = new DefaultObjectMapper();
    HllSketchToEstimateWithBoundsPostAggregator andBackAgain = mapper.readValue(mapper.writeValueAsString(there), HllSketchToEstimateWithBoundsPostAggregator.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 35 with PostAggregator

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

the class DoublesSketchToCDFPostAggregatorTest method testComparator.

@Test
public void testComparator() {
    expectedException.expect(IAE.class);
    expectedException.expectMessage("Comparing histograms is not supported");
    final PostAggregator postAgg = new DoublesSketchToCDFPostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"), new double[] { 0.25, 0.75 });
    postAgg.getComparator();
}
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