use of io.druid.query.aggregation.CountAggregator in project druid by druid-io.
the class LongLeastPostAggregatorTest method testComparator.
@Test
public void testComparator() {
final String aggName = "rows";
LongLeastPostAggregator 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 LongLeastPostAggregator("leastPostAggregator", 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));
}
use of io.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));
}
use of io.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));
}
use of io.druid.query.aggregation.CountAggregator in project druid by druid-io.
the class FinalizingFieldAccessPostAggregatorTest method testComputeWithoutFinalizing.
@Test(expected = UnsupportedOperationException.class)
public void testComputeWithoutFinalizing() {
String aggName = "rows";
Aggregator agg = new CountAggregator();
agg.aggregate();
agg.aggregate();
agg.aggregate();
Map<String, Object> metricValues = Maps.newHashMap();
metricValues.put(aggName, agg.get());
FinalizingFieldAccessPostAggregator postAgg = new FinalizingFieldAccessPostAggregator("final_rows", aggName);
Assert.assertEquals(new Long(3L), postAgg.compute(metricValues));
}
use of io.druid.query.aggregation.CountAggregator in project druid by druid-io.
the class SpecificSegmentQueryRunnerTest method testRetry2.
@SuppressWarnings("unchecked")
@Test
public void testRetry2() throws Exception {
final ObjectMapper mapper = new DefaultObjectMapper();
SegmentDescriptor descriptor = new SegmentDescriptor(new Interval("2012-01-01T00:00:00Z/P1D"), "version", 0);
TimeseriesResultBuilder builder = new TimeseriesResultBuilder(new DateTime("2012-01-01T00:00:00Z"));
CountAggregator rows = new CountAggregator();
rows.aggregate();
builder.addMetric("rows", rows);
final Result<TimeseriesResultValue> value = builder.build();
final SpecificSegmentQueryRunner queryRunner = new SpecificSegmentQueryRunner(new QueryRunner() {
@Override
public Sequence run(Query query, Map responseContext) {
return Sequences.withEffect(Sequences.simple(Arrays.asList(value)), new Runnable() {
@Override
public void run() {
throw new SegmentMissingException("FAILSAUCE");
}
}, MoreExecutors.sameThreadExecutor());
}
}, new SpecificSegmentSpec(descriptor));
final Map<String, Object> responseContext = Maps.newHashMap();
TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("foo").granularity(Granularities.ALL).intervals(ImmutableList.of(new Interval("2012-01-01T00:00:00Z/P1D"))).aggregators(ImmutableList.<AggregatorFactory>of(new CountAggregatorFactory("rows"))).build();
Sequence results = queryRunner.run(query, responseContext);
List<Result<TimeseriesResultValue>> res = Sequences.toList(results, Lists.<Result<TimeseriesResultValue>>newArrayList());
Assert.assertEquals(1, res.size());
Result<TimeseriesResultValue> theVal = res.get(0);
Assert.assertTrue(1L == theVal.getValue().getLongMetric("rows"));
validate(mapper, descriptor, responseContext);
}
Aggregations