use of org.apache.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 org.apache.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<>();
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));
}
use of org.apache.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", null, TestExprMacroTable.INSTANCE);
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", null, TestExprMacroTable.INSTANCE);
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", null, TestExprMacroTable.INSTANCE);
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", null, TestExprMacroTable.INSTANCE);
Assert.assertEquals(2.0, arithmeticPostAggregator.compute(metricValues));
Assert.assertEquals(2.0, expressionPostAggregator.compute(metricValues));
}
use of org.apache.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));
}
use of org.apache.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 = new HashMap<>();
metricValues.put(aggName, agg.get());
FinalizingFieldAccessPostAggregator postAgg = new FinalizingFieldAccessPostAggregator("final_rows", aggName);
Assert.assertEquals(new Long(3L), postAgg.compute(metricValues));
}
Aggregations