use of io.druid.query.aggregation.AggregatorFactory in project druid by druid-io.
the class FinalizingFieldAccessPostAggregatorTest method testComputedInArithmeticPostAggregator.
@Test
public void testComputedInArithmeticPostAggregator() {
String aggName = "billy";
AggregatorFactory aggFactory = EasyMock.createMock(AggregatorFactory.class);
EasyMock.expect(aggFactory.finalizeComputation("test")).andReturn(new Long(3L)).times(1);
EasyMock.replay(aggFactory);
FinalizingFieldAccessPostAggregator postAgg = FinalizingFieldAccessPostAggregator.buildDecorated("final_billy", aggName, ImmutableMap.of(aggName, aggFactory));
Map<String, Object> metricValues = Maps.newHashMap();
metricValues.put(aggName, "test");
List<PostAggregator> postAggsList = Lists.newArrayList(new ConstantPostAggregator("roku", 6), postAgg);
ArithmeticPostAggregator arithmeticPostAggregator = new ArithmeticPostAggregator("add", "+", postAggsList);
Assert.assertEquals(new Double(9.0f), arithmeticPostAggregator.compute(metricValues));
EasyMock.verify();
}
use of io.druid.query.aggregation.AggregatorFactory in project druid by druid-io.
the class FinalizingFieldAccessPostAggregatorTest method testComparatorsWithFinalizing.
@Test
public void testComparatorsWithFinalizing() throws Exception {
String aggName = "billy";
AggregatorFactory aggFactory = EasyMock.createMock(AggregatorFactory.class);
EasyMock.expect(aggFactory.finalizeComputation("test_val1")).andReturn(new Long(10L)).times(1);
EasyMock.expect(aggFactory.finalizeComputation("test_val2")).andReturn(new Long(21)).times(1);
EasyMock.expect(aggFactory.finalizeComputation("test_val3")).andReturn(new Long(3)).times(1);
EasyMock.expect(aggFactory.finalizeComputation("test_val4")).andReturn(null).times(1);
EasyMock.expect(aggFactory.getComparator()).andReturn(Ordering.natural().<Long>nullsLast()).times(1);
EasyMock.replay(aggFactory);
FinalizingFieldAccessPostAggregator postAgg = FinalizingFieldAccessPostAggregator.buildDecorated("final_billy", aggName, ImmutableMap.of(aggName, aggFactory));
List<Object> computedValues = Lists.newArrayList();
computedValues.add(postAgg.compute(ImmutableMap.of(aggName, (Object) "test_val1")));
computedValues.add(postAgg.compute(ImmutableMap.of(aggName, (Object) "test_val2")));
computedValues.add(postAgg.compute(ImmutableMap.of(aggName, (Object) "test_val3")));
computedValues.add(postAgg.compute(ImmutableMap.of(aggName, (Object) "test_val4")));
Collections.sort(computedValues, postAgg.getComparator());
Assert.assertArrayEquals(new Object[] { 3L, 10L, 21L, null }, computedValues.toArray(new Object[] {}));
EasyMock.verify();
}
use of io.druid.query.aggregation.AggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByWithUniquesAndPostAggWithSameName.
@Test(expected = IllegalArgumentException.class)
public void testGroupByWithUniquesAndPostAggWithSameName() {
GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setAggregatorSpecs(Arrays.<AggregatorFactory>asList(QueryRunnerTestHelper.rowsCount, new HyperUniquesAggregatorFactory("quality_uniques", "quality_uniques"))).setPostAggregatorSpecs(Arrays.<PostAggregator>asList(new HyperUniqueFinalizingPostAggregator("quality_uniques", "quality_uniques"))).setGranularity(QueryRunnerTestHelper.allGran).build();
List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "rows", 26L, "quality_uniques", QueryRunnerTestHelper.UNIQUES_9));
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "");
}
use of io.druid.query.aggregation.AggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testSubqueryWithFirstLast.
@Test
public void testSubqueryWithFirstLast() {
GroupByQuery subquery = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.fullOnInterval).setDimensions(ImmutableList.<DimensionSpec>of(new DefaultDimensionSpec("market", "market"))).setAggregatorSpecs(ImmutableList.<AggregatorFactory>of(QueryRunnerTestHelper.rowsCount, new LongFirstAggregatorFactory("innerfirst", "index"), new LongLastAggregatorFactory("innerlast", "index"))).setGranularity(QueryRunnerTestHelper.dayGran).setContext(ImmutableMap.<String, Object>of("finalize", true)).build();
GroupByQuery query = GroupByQuery.builder().setDataSource(subquery).setQuerySegmentSpec(QueryRunnerTestHelper.fullOnInterval).setDimensions(Lists.<DimensionSpec>newArrayList()).setAggregatorSpecs(ImmutableList.<AggregatorFactory>of(new LongFirstAggregatorFactory("first", "innerfirst"), new LongLastAggregatorFactory("last", "innerlast"))).setGranularity(QueryRunnerTestHelper.monthGran).build();
List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-01-01", "first", 100L, "last", 943L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-02-01", "first", 132L, "last", 1101L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-03-01", "first", 153L, "last", 1063L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "first", 135L, "last", 780L));
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "");
}
use of io.druid.query.aggregation.AggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testDifferentGroupingSubqueryWithFilter.
@Test
public void testDifferentGroupingSubqueryWithFilter() {
GroupByQuery subquery = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("quality", "quality"))).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"))).setGranularity(QueryRunnerTestHelper.dayGran).build();
GroupByQuery query = GroupByQuery.builder().setDataSource(subquery).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setAggregatorSpecs(Arrays.<AggregatorFactory>asList(new DoubleMaxAggregatorFactory("idx", "idx"))).setDimFilter(new OrDimFilter(Lists.<DimFilter>newArrayList(new SelectorDimFilter("quality", "automotive", null), new SelectorDimFilter("quality", "premium", null), new SelectorDimFilter("quality", "mezzanine", null), new SelectorDimFilter("quality", "business", null), new SelectorDimFilter("quality", "entertainment", null), new SelectorDimFilter("quality", "health", null), new SelectorDimFilter("quality", "news", null), new SelectorDimFilter("quality", "technology", null), new SelectorDimFilter("quality", "travel", null)))).setGranularity(QueryRunnerTestHelper.dayGran).build();
List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "idx", 2900.0), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "idx", 2505.0));
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "");
}
Aggregations