Search in sources :

Example 11 with CountAggregator

use of io.druid.query.aggregation.CountAggregator in project druid by druid-io.

the class DoubleLeastPostAggregatorTest method testCompute.

@Test
public void testCompute() {
    final String aggName = "rows";
    DoubleLeastPostAggregator leastPostAggregator;
    CountAggregator agg = new CountAggregator();
    agg.aggregate();
    agg.aggregate();
    agg.aggregate();
    Map<String, Object> metricValues = new HashMap<String, Object>();
    metricValues.put(aggName, agg.get());
    List<PostAggregator> postAggregatorList = Lists.newArrayList(new ConstantPostAggregator("roku", 6D), new FieldAccessPostAggregator("rows", aggName));
    leastPostAggregator = new DoubleLeastPostAggregator("least", postAggregatorList);
    Assert.assertEquals(3.0, leastPostAggregator.compute(metricValues));
}
Also used : PostAggregator(io.druid.query.aggregation.PostAggregator) HashMap(java.util.HashMap) CountAggregator(io.druid.query.aggregation.CountAggregator) Test(org.junit.Test)

Example 12 with CountAggregator

use of io.druid.query.aggregation.CountAggregator in project druid by druid-io.

the class FieldAccessPostAggregatorTest method testCompute.

@Test
public void testCompute() {
    final String aggName = "rows";
    FieldAccessPostAggregator fieldAccessPostAggregator;
    fieldAccessPostAggregator = new FieldAccessPostAggregator("To be, or not to be, that is the question:", "rows");
    CountAggregator agg = new CountAggregator();
    Map<String, Object> metricValues = new HashMap<String, Object>();
    metricValues.put(aggName, agg.get());
    Assert.assertEquals(new Long(0L), fieldAccessPostAggregator.compute(metricValues));
    agg.aggregate();
    agg.aggregate();
    agg.aggregate();
    metricValues.put(aggName, agg.get());
    Assert.assertEquals(new Long(3L), fieldAccessPostAggregator.compute(metricValues));
}
Also used : HashMap(java.util.HashMap) CountAggregator(io.druid.query.aggregation.CountAggregator) Test(org.junit.Test)

Example 13 with CountAggregator

use of io.druid.query.aggregation.CountAggregator in project druid by druid-io.

the class ArithmeticPostAggregatorTest method testCompute.

@Test
public void testCompute() {
    final String aggName = "rows";
    ArithmeticPostAggregator arithmeticPostAggregator;
    ExpressionPostAggregator expressionPostAggregator;
    CountAggregator agg = new CountAggregator();
    agg.aggregate();
    agg.aggregate();
    agg.aggregate();
    Map<String, Object> metricValues = new HashMap<String, Object>();
    metricValues.put(aggName, agg.get());
    List<PostAggregator> postAggregatorList = Lists.newArrayList(new ConstantPostAggregator("roku", 6D), new FieldAccessPostAggregator("rows", "rows"));
    for (PostAggregator postAggregator : postAggregatorList) {
        metricValues.put(postAggregator.getName(), postAggregator.compute(metricValues));
    }
    arithmeticPostAggregator = new ArithmeticPostAggregator("add", "+", postAggregatorList);
    expressionPostAggregator = new ExpressionPostAggregator("add", "roku + rows");
    Assert.assertEquals(9.0, arithmeticPostAggregator.compute(metricValues));
    Assert.assertEquals(9.0, expressionPostAggregator.compute(metricValues));
    arithmeticPostAggregator = new ArithmeticPostAggregator("subtract", "-", postAggregatorList);
    expressionPostAggregator = new ExpressionPostAggregator("add", "roku - rows");
    Assert.assertEquals(3.0, arithmeticPostAggregator.compute(metricValues));
    Assert.assertEquals(3.0, expressionPostAggregator.compute(metricValues));
    arithmeticPostAggregator = new ArithmeticPostAggregator("multiply", "*", postAggregatorList);
    expressionPostAggregator = new ExpressionPostAggregator("add", "roku * rows");
    Assert.assertEquals(18.0, arithmeticPostAggregator.compute(metricValues));
    Assert.assertEquals(18.0, expressionPostAggregator.compute(metricValues));
    arithmeticPostAggregator = new ArithmeticPostAggregator("divide", "/", postAggregatorList);
    expressionPostAggregator = new ExpressionPostAggregator("add", "roku / rows");
    Assert.assertEquals(2.0, arithmeticPostAggregator.compute(metricValues));
    Assert.assertEquals(2.0, expressionPostAggregator.compute(metricValues));
}
Also used : PostAggregator(io.druid.query.aggregation.PostAggregator) HashMap(java.util.HashMap) CountAggregator(io.druid.query.aggregation.CountAggregator) Test(org.junit.Test)

Aggregations

CountAggregator (io.druid.query.aggregation.CountAggregator)13 Test (org.junit.Test)13 PostAggregator (io.druid.query.aggregation.PostAggregator)11 HashMap (java.util.HashMap)11 Comparator (java.util.Comparator)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1 Sequence (io.druid.java.util.common.guava.Sequence)1 Query (io.druid.query.Query)1 QueryRunner (io.druid.query.QueryRunner)1 Result (io.druid.query.Result)1 SegmentDescriptor (io.druid.query.SegmentDescriptor)1 Aggregator (io.druid.query.aggregation.Aggregator)1 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)1 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)1 GroupByQueryRunnerTest (io.druid.query.groupby.GroupByQueryRunnerTest)1 TimeseriesQuery (io.druid.query.timeseries.TimeseriesQuery)1 TimeseriesResultBuilder (io.druid.query.timeseries.TimeseriesResultBuilder)1 TimeseriesResultValue (io.druid.query.timeseries.TimeseriesResultValue)1 SegmentMissingException (io.druid.segment.SegmentMissingException)1