use of io.druid.query.aggregation.CountAggregatorFactory in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByNumericStringsAsNumericWithDecoration.
@Test
public void testGroupByNumericStringsAsNumericWithDecoration() {
if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
}
// rows with `technology` have `170000` in the qualityNumericString field
RegexFilteredDimensionSpec regexSpec = new RegexFilteredDimensionSpec(new DefaultDimensionSpec("qualityNumericString", "ql", ValueType.LONG), "170000");
ListFilteredDimensionSpec listFilteredSpec = new ListFilteredDimensionSpec(new DefaultDimensionSpec("qualityNumericString", "qf", ValueType.FLOAT), Sets.newHashSet("170000"), true);
GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setDimensions(Lists.<DimensionSpec>newArrayList(regexSpec, listFilteredSpec)).setDimFilter(new InDimFilter("quality", Arrays.asList("entertainment", "technology"), null)).setAggregatorSpecs(Arrays.<AggregatorFactory>asList(new CountAggregatorFactory("count"))).setGranularity(QueryRunnerTestHelper.allGran).build();
// "entertainment" rows are excluded by the decorated specs, they become empty rows
List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "ql", 0L, "qf", 0.0, "count", 2L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "ql", 170000L, "qf", 170000.0, "count", 2L));
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "");
}
use of io.druid.query.aggregation.CountAggregatorFactory in project druid by druid-io.
the class BufferGrouperTest method testSimple.
@Test
public void testSimple() {
final TestColumnSelectorFactory columnSelectorFactory = GrouperTestUtil.newColumnSelectorFactory();
final Grouper<Integer> grouper = new BufferGrouper<>(Suppliers.ofInstance(ByteBuffer.allocate(1000)), GrouperTestUtil.intKeySerde(), columnSelectorFactory, new AggregatorFactory[] { new LongSumAggregatorFactory("valueSum", "value"), new CountAggregatorFactory("count") }, Integer.MAX_VALUE, 0, 0);
grouper.init();
columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.<String, Object>of("value", 10L)));
grouper.aggregate(12);
grouper.aggregate(6);
grouper.aggregate(10);
grouper.aggregate(6);
grouper.aggregate(12);
grouper.aggregate(12);
final List<Grouper.Entry<Integer>> expected = ImmutableList.of(new Grouper.Entry<>(6, new Object[] { 20L, 2L }), new Grouper.Entry<>(10, new Object[] { 10L, 1L }), new Grouper.Entry<>(12, new Object[] { 30L, 3L }));
final List<Grouper.Entry<Integer>> unsortedEntries = Lists.newArrayList(grouper.iterator(false));
final List<Grouper.Entry<Integer>> sortedEntries = Lists.newArrayList(grouper.iterator(true));
Assert.assertEquals(expected, sortedEntries);
Assert.assertEquals(expected, Ordering.from(new Comparator<Grouper.Entry<Integer>>() {
@Override
public int compare(Grouper.Entry<Integer> o1, Grouper.Entry<Integer> o2) {
return Ints.compare(o1.getKey(), o2.getKey());
}
}).sortedCopy(unsortedEntries));
}
use of io.druid.query.aggregation.CountAggregatorFactory in project druid by druid-io.
the class ConcurrentGrouperTest method testAggregate.
@Test
public void testAggregate() throws InterruptedException, ExecutionException {
final ConcurrentGrouper<Long> grouper = new ConcurrentGrouper<>(bufferSupplier, keySerdeFactory, null_factory, new AggregatorFactory[] { new CountAggregatorFactory("cnt") }, 24, 0.7f, 1, null, null, 8);
Future<?>[] futures = new Future[8];
for (int i = 0; i < 8; i++) {
futures[i] = service.submit(new Runnable() {
@Override
public void run() {
grouper.init();
for (long i = 0; i < 100; i++) {
grouper.aggregate(0L);
}
}
});
}
for (Future eachFuture : futures) {
eachFuture.get();
}
grouper.close();
}
use of io.druid.query.aggregation.CountAggregatorFactory in project druid by druid-io.
the class TieredBrokerHostSelectorTest method testSelectMultiInterval2.
@Test
public void testSelectMultiInterval2() throws Exception {
String brokerName = (String) brokerSelector.select(Druids.newTimeseriesQueryBuilder().dataSource("test").aggregators(Arrays.<AggregatorFactory>asList(new CountAggregatorFactory("count"))).intervals(new MultipleIntervalSegmentSpec(Arrays.<Interval>asList(new Interval("2011-08-31/2011-09-01"), new Interval("2012-08-31/2012-09-01"), new Interval("2013-08-31/2013-09-01")))).build()).lhs;
Assert.assertEquals("coldBroker", brokerName);
}
use of io.druid.query.aggregation.CountAggregatorFactory in project druid by druid-io.
the class TieredBrokerHostSelectorTest method testBasicSelect.
@Test
public void testBasicSelect() throws Exception {
String brokerName = (String) brokerSelector.select(Druids.newTimeseriesQueryBuilder().dataSource("test").granularity("all").aggregators(Arrays.<AggregatorFactory>asList(new CountAggregatorFactory("rows"))).intervals(Arrays.<Interval>asList(new Interval("2011-08-31/2011-09-01"))).build()).lhs;
Assert.assertEquals("coldBroker", brokerName);
}
Aggregations