Search in sources :

Example 6 with CountAggregator

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

the class LongGreatestPostAggregatorTest method testComparator.

@Test
public void testComparator() {
    final String aggName = "rows";
    LongGreatestPostAggregator greatestPostAggregator;
    CountAggregator agg = new CountAggregator();
    Map<String, Object> metricValues = new HashMap<String, Object>();
    metricValues.put(aggName, agg.get());
    List<PostAggregator> postAggregatorList = Lists.newArrayList(new ConstantPostAggregator("roku", 2D), new FieldAccessPostAggregator("rows", aggName));
    greatestPostAggregator = new LongGreatestPostAggregator("greatest", postAggregatorList);
    Comparator comp = greatestPostAggregator.getComparator();
    Object before = greatestPostAggregator.compute(metricValues);
    agg.aggregate();
    agg.aggregate();
    agg.aggregate();
    metricValues.put(aggName, agg.get());
    Object after = greatestPostAggregator.compute(metricValues);
    Assert.assertEquals(-1, comp.compare(before, after));
    Assert.assertEquals(0, comp.compare(before, before));
    Assert.assertEquals(0, comp.compare(after, after));
    Assert.assertEquals(1, comp.compare(after, before));
}
Also used : PostAggregator(io.druid.query.aggregation.PostAggregator) HashMap(java.util.HashMap) CountAggregator(io.druid.query.aggregation.CountAggregator) Comparator(java.util.Comparator) Test(org.junit.Test)

Example 7 with CountAggregator

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

the class LongGreatestPostAggregatorTest method testCompute.

@Test
public void testCompute() {
    final String aggName = "rows";
    LongGreatestPostAggregator greatestPostAggregator;
    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));
    greatestPostAggregator = new LongGreatestPostAggregator("greatest", postAggregatorList);
    Assert.assertEquals(Long.valueOf(6), greatestPostAggregator.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 8 with CountAggregator

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

the class ArithmeticPostAggregatorTest method testComparator.

@Test
public void testComparator() {
    final String aggName = "rows";
    ArithmeticPostAggregator arithmeticPostAggregator;
    CountAggregator agg = new CountAggregator();
    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"));
    arithmeticPostAggregator = new ArithmeticPostAggregator("add", "+", postAggregatorList);
    Comparator comp = arithmeticPostAggregator.getComparator();
    Object before = arithmeticPostAggregator.compute(metricValues);
    agg.aggregate();
    agg.aggregate();
    agg.aggregate();
    metricValues.put(aggName, agg.get());
    Object after = arithmeticPostAggregator.compute(metricValues);
    Assert.assertEquals(-1, comp.compare(before, after));
    Assert.assertEquals(0, comp.compare(before, before));
    Assert.assertEquals(0, comp.compare(after, after));
    Assert.assertEquals(1, comp.compare(after, before));
}
Also used : PostAggregator(io.druid.query.aggregation.PostAggregator) HashMap(java.util.HashMap) CountAggregator(io.druid.query.aggregation.CountAggregator) Comparator(java.util.Comparator) Test(org.junit.Test)

Example 9 with CountAggregator

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

the class DoubleGreatestPostAggregatorTest method testCompute.

@Test
public void testCompute() {
    final String aggName = "rows";
    DoubleGreatestPostAggregator greatestPostAggregator;
    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));
    greatestPostAggregator = new DoubleGreatestPostAggregator("greatest", postAggregatorList);
    Assert.assertEquals(6.0, greatestPostAggregator.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 10 with CountAggregator

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

the class DoubleGreatestPostAggregatorTest method testComparator.

@Test
public void testComparator() {
    final String aggName = "rows";
    DoubleGreatestPostAggregator greatestPostAggregator;
    CountAggregator agg = new CountAggregator();
    Map<String, Object> metricValues = new HashMap<String, Object>();
    metricValues.put(aggName, agg.get());
    List<PostAggregator> postAggregatorList = Lists.newArrayList(new ConstantPostAggregator("roku", 2D), new FieldAccessPostAggregator("rows", aggName));
    greatestPostAggregator = new DoubleGreatestPostAggregator("greatest", postAggregatorList);
    Comparator comp = greatestPostAggregator.getComparator();
    Object before = greatestPostAggregator.compute(metricValues);
    agg.aggregate();
    agg.aggregate();
    agg.aggregate();
    metricValues.put(aggName, agg.get());
    Object after = greatestPostAggregator.compute(metricValues);
    Assert.assertEquals(-1, comp.compare(before, after));
    Assert.assertEquals(0, comp.compare(before, before));
    Assert.assertEquals(0, comp.compare(after, after));
    Assert.assertEquals(1, comp.compare(after, before));
}
Also used : PostAggregator(io.druid.query.aggregation.PostAggregator) HashMap(java.util.HashMap) CountAggregator(io.druid.query.aggregation.CountAggregator) Comparator(java.util.Comparator) 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