Search in sources :

Example 1 with CountAggregator

use of org.apache.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(org.apache.druid.query.aggregation.PostAggregator) HashMap(java.util.HashMap) CountAggregator(org.apache.druid.query.aggregation.CountAggregator) Comparator(java.util.Comparator) Test(org.junit.Test)

Example 2 with CountAggregator

use of org.apache.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(org.apache.druid.query.aggregation.PostAggregator) HashMap(java.util.HashMap) CountAggregator(org.apache.druid.query.aggregation.CountAggregator) Test(org.junit.Test)

Example 3 with CountAggregator

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

the class DoubleLeastPostAggregatorTest method testComparator.

@Test
public void testComparator() {
    final String aggName = "rows";
    DoubleLeastPostAggregator leastPostAggregator;
    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));
    leastPostAggregator = new DoubleLeastPostAggregator("least", postAggregatorList);
    Comparator comp = leastPostAggregator.getComparator();
    Object before = leastPostAggregator.compute(metricValues);
    agg.aggregate();
    agg.aggregate();
    agg.aggregate();
    metricValues.put(aggName, agg.get());
    Object after = leastPostAggregator.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(org.apache.druid.query.aggregation.PostAggregator) HashMap(java.util.HashMap) CountAggregator(org.apache.druid.query.aggregation.CountAggregator) Comparator(java.util.Comparator) Test(org.junit.Test)

Example 4 with CountAggregator

use of org.apache.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(org.apache.druid.query.aggregation.CountAggregator) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 5 with CountAggregator

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

the class LongLeastPostAggregatorTest method testCompute.

@Test
public void testCompute() {
    final String aggName = "rows";
    LongLeastPostAggregator 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 LongLeastPostAggregator("leastPostAggregator", postAggregatorList);
    Assert.assertEquals(Long.valueOf(3), leastPostAggregator.compute(metricValues));
}
Also used : PostAggregator(org.apache.druid.query.aggregation.PostAggregator) HashMap(java.util.HashMap) CountAggregator(org.apache.druid.query.aggregation.CountAggregator) Test(org.junit.Test)

Aggregations

CountAggregator (org.apache.druid.query.aggregation.CountAggregator)13 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)11 Comparator (java.util.Comparator)5 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)1 Sequence (org.apache.druid.java.util.common.guava.Sequence)1 QueryPlus (org.apache.druid.query.QueryPlus)1 QueryRunner (org.apache.druid.query.QueryRunner)1 Result (org.apache.druid.query.Result)1 SegmentDescriptor (org.apache.druid.query.SegmentDescriptor)1 Aggregator (org.apache.druid.query.aggregation.Aggregator)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1 ResponseContext (org.apache.druid.query.context.ResponseContext)1 GroupByQueryRunnerTest (org.apache.druid.query.groupby.GroupByQueryRunnerTest)1 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)1 TimeseriesResultBuilder (org.apache.druid.query.timeseries.TimeseriesResultBuilder)1 TimeseriesResultValue (org.apache.druid.query.timeseries.TimeseriesResultValue)1