Search in sources :

Example 96 with CountAggregatorFactory

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, "");
}
Also used : ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) InDimFilter(io.druid.query.filter.InDimFilter) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) Row(io.druid.data.input.Row) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 97 with CountAggregatorFactory

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));
}
Also used : LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) MapBasedRow(io.druid.data.input.MapBasedRow) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) Test(org.junit.Test)

Example 98 with CountAggregatorFactory

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();
}
Also used : CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 99 with CountAggregatorFactory

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);
}
Also used : CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) MultipleIntervalSegmentSpec(io.druid.query.spec.MultipleIntervalSegmentSpec) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 100 with CountAggregatorFactory

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);
}
Also used : CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)102 Test (org.junit.Test)81 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)54 Interval (org.joda.time.Interval)35 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)33 DateTime (org.joda.time.DateTime)30 Result (io.druid.query.Result)27 OnheapIncrementalIndex (io.druid.segment.incremental.OnheapIncrementalIndex)25 IncrementalIndex (io.druid.segment.incremental.IncrementalIndex)23 DoubleSumAggregatorFactory (io.druid.query.aggregation.DoubleSumAggregatorFactory)19 FilteredAggregatorFactory (io.druid.query.aggregation.FilteredAggregatorFactory)18 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)16 TimeseriesQuery (io.druid.query.timeseries.TimeseriesQuery)16 TimeseriesResultValue (io.druid.query.timeseries.TimeseriesResultValue)16 File (java.io.File)15 TimeseriesQueryEngine (io.druid.query.timeseries.TimeseriesQueryEngine)14 TimeseriesQueryRunnerFactory (io.druid.query.timeseries.TimeseriesQueryRunnerFactory)14 QueryRunner (io.druid.query.QueryRunner)13 TimeseriesQueryQueryToolChest (io.druid.query.timeseries.TimeseriesQueryQueryToolChest)13 MapBasedInputRow (io.druid.data.input.MapBasedInputRow)12