Search in sources :

Example 26 with TopNResultValue

use of io.druid.query.topn.TopNResultValue in project druid by druid-io.

the class SchemalessTestFullTest method testFilteredTopN.

private void testFilteredTopN(QueryRunner runner, List<Result<TopNResultValue>> expectedResults, String failMsg) {
    TopNQuery query = new TopNQueryBuilder().dataSource(dataSource).granularity(allGran).dimension(marketDimension).filters(marketDimension, "spot").metric(indexMetric).threshold(3).intervals(fullOnInterval).aggregators(Lists.<AggregatorFactory>newArrayList(Iterables.concat(commonAggregators, Lists.newArrayList(new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index"))))).postAggregators(Arrays.<PostAggregator>asList(addRowsIndexConstant)).build();
    failMsg += " filtered topN ";
    HashMap<String, Object> context = new HashMap<>();
    Iterable<Result<TopNResultValue>> actualResults = Sequences.toList(runner.run(query, context), Lists.<Result<TopNResultValue>>newArrayList());
    TestHelper.assertExpectedResults(expectedResults, actualResults, failMsg);
}
Also used : TopNQueryBuilder(io.druid.query.topn.TopNQueryBuilder) TopNResultValue(io.druid.query.topn.TopNResultValue) DoubleMaxAggregatorFactory(io.druid.query.aggregation.DoubleMaxAggregatorFactory) PostAggregator(io.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(io.druid.query.aggregation.post.FieldAccessPostAggregator) ArithmeticPostAggregator(io.druid.query.aggregation.post.ArithmeticPostAggregator) ConstantPostAggregator(io.druid.query.aggregation.post.ConstantPostAggregator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopNQuery(io.druid.query.topn.TopNQuery) DoubleMinAggregatorFactory(io.druid.query.aggregation.DoubleMinAggregatorFactory) Result(io.druid.query.Result)

Example 27 with TopNResultValue

use of io.druid.query.topn.TopNResultValue in project druid by druid-io.

the class SchemalessTestFullTest method testFullOnTopN.

private void testFullOnTopN(QueryRunner runner, List<Result<TopNResultValue>> expectedResults, String failMsg) {
    TopNQuery query = new TopNQueryBuilder().dataSource(dataSource).granularity(allGran).dimension(marketDimension).metric(indexMetric).threshold(3).intervals(fullOnInterval).aggregators(Lists.<AggregatorFactory>newArrayList(Iterables.concat(commonAggregators, Lists.newArrayList(new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index"))))).postAggregators(Arrays.<PostAggregator>asList(addRowsIndexConstant)).build();
    failMsg += " topN ";
    HashMap<String, Object> context = new HashMap<>();
    Iterable<Result<TopNResultValue>> actualResults = Sequences.toList(runner.run(query, context), Lists.<Result<TopNResultValue>>newArrayList());
    TestHelper.assertExpectedResults(expectedResults, actualResults, failMsg);
}
Also used : TopNQueryBuilder(io.druid.query.topn.TopNQueryBuilder) TopNResultValue(io.druid.query.topn.TopNResultValue) DoubleMaxAggregatorFactory(io.druid.query.aggregation.DoubleMaxAggregatorFactory) PostAggregator(io.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(io.druid.query.aggregation.post.FieldAccessPostAggregator) ArithmeticPostAggregator(io.druid.query.aggregation.post.ArithmeticPostAggregator) ConstantPostAggregator(io.druid.query.aggregation.post.ConstantPostAggregator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopNQuery(io.druid.query.topn.TopNQuery) DoubleMinAggregatorFactory(io.druid.query.aggregation.DoubleMinAggregatorFactory) Result(io.druid.query.Result)

Example 28 with TopNResultValue

use of io.druid.query.topn.TopNResultValue in project druid by druid-io.

the class VarianceTopNQueryTest method testFullOnTopNOverUniques.

@Test
public void testFullOnTopNOverUniques() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(QueryRunnerTestHelper.marketDimension).metric(QueryRunnerTestHelper.uniqueMetric).threshold(3).intervals(QueryRunnerTestHelper.fullOnInterval).aggregators(Lists.<AggregatorFactory>newArrayList(Iterables.concat(VarianceTestHelper.commonPlusVarAggregators, Lists.newArrayList(new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index"))))).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
    List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<TopNResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>builder().put("market", "spot").put("rows", 837L).put("index", 95606.57232284546D).put("addRowsIndexConstant", 96444.57232284546D).put("uniques", QueryRunnerTestHelper.UNIQUES_9).put("maxIndex", 277.2735290527344D).put("minIndex", 59.02102279663086D).put("index_var", 439.3851694586573D).build(), ImmutableMap.<String, Object>builder().put("market", "total_market").put("rows", 186L).put("index", 215679.82879638672D).put("addRowsIndexConstant", 215866.82879638672D).put("uniques", QueryRunnerTestHelper.UNIQUES_2).put("maxIndex", 1743.9217529296875D).put("minIndex", 792.3260498046875D).put("index_var", 27679.900887366413D).build(), ImmutableMap.<String, Object>builder().put("market", "upfront").put("rows", 186L).put("index", 192046.1060180664D).put("addRowsIndexConstant", 192233.1060180664D).put("uniques", QueryRunnerTestHelper.UNIQUES_2).put("maxIndex", 1870.06103515625D).put("minIndex", 545.9906005859375D).put("index_var", 79699.9780741607D).build()))));
    assertExpectedResults(expectedResults, query);
}
Also used : TopNQueryBuilder(io.druid.query.topn.TopNQueryBuilder) TopNResultValue(io.druid.query.topn.TopNResultValue) DoubleMaxAggregatorFactory(io.druid.query.aggregation.DoubleMaxAggregatorFactory) PostAggregator(io.druid.query.aggregation.PostAggregator) TopNQuery(io.druid.query.topn.TopNQuery) DoubleMinAggregatorFactory(io.druid.query.aggregation.DoubleMinAggregatorFactory) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) Test(org.junit.Test) TopNQueryRunnerTest(io.druid.query.topn.TopNQueryRunnerTest)

Example 29 with TopNResultValue

use of io.druid.query.topn.TopNResultValue in project druid by druid-io.

the class DistinctCountTopNQueryTest method testTopNWithDistinctCountAgg.

@Test
public void testTopNWithDistinctCountAgg() throws Exception {
    TopNQueryEngine engine = new TopNQueryEngine(new StupidPool<ByteBuffer>("TopNQueryEngine-bufferPool", new Supplier<ByteBuffer>() {

        @Override
        public ByteBuffer get() {
            return ByteBuffer.allocate(1024 * 1024);
        }
    }));
    IncrementalIndex index = new OnheapIncrementalIndex(0, Granularities.SECOND, new AggregatorFactory[] { new CountAggregatorFactory("cnt") }, 1000);
    String visitor_id = "visitor_id";
    String client_type = "client_type";
    DateTime time = new DateTime("2016-03-04T00:00:00.000Z");
    long timestamp = time.getMillis();
    index.add(new MapBasedInputRow(timestamp, Lists.newArrayList(visitor_id, client_type), ImmutableMap.<String, Object>of(visitor_id, "0", client_type, "iphone")));
    index.add(new MapBasedInputRow(timestamp, Lists.newArrayList(visitor_id, client_type), ImmutableMap.<String, Object>of(visitor_id, "1", client_type, "iphone")));
    index.add(new MapBasedInputRow(timestamp, Lists.newArrayList(visitor_id, client_type), ImmutableMap.<String, Object>of(visitor_id, "2", client_type, "android")));
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).dimension(client_type).metric("UV").threshold(10).aggregators(Lists.newArrayList(QueryRunnerTestHelper.rowsCount, new DistinctCountAggregatorFactory("UV", visitor_id, null))).build();
    final Iterable<Result<TopNResultValue>> results = Sequences.toList(engine.query(query, new IncrementalIndexStorageAdapter(index)), Lists.<Result<TopNResultValue>>newLinkedList());
    List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<>(time, new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>of(client_type, "iphone", "UV", 2L, "rows", 2L), ImmutableMap.<String, Object>of(client_type, "android", "UV", 1L, "rows", 1L)))));
    TestHelper.assertExpectedResults(expectedResults, results);
}
Also used : TopNQueryBuilder(io.druid.query.topn.TopNQueryBuilder) TopNResultValue(io.druid.query.topn.TopNResultValue) IncrementalIndex(io.druid.segment.incremental.IncrementalIndex) OnheapIncrementalIndex(io.druid.segment.incremental.OnheapIncrementalIndex) OnheapIncrementalIndex(io.druid.segment.incremental.OnheapIncrementalIndex) ByteBuffer(java.nio.ByteBuffer) DateTime(org.joda.time.DateTime) TopNQueryEngine(io.druid.query.topn.TopNQueryEngine) Result(io.druid.query.Result) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) IncrementalIndexStorageAdapter(io.druid.segment.incremental.IncrementalIndexStorageAdapter) TopNQuery(io.druid.query.topn.TopNQuery) Supplier(com.google.common.base.Supplier) MapBasedInputRow(io.druid.data.input.MapBasedInputRow) Test(org.junit.Test)

Example 30 with TopNResultValue

use of io.druid.query.topn.TopNResultValue in project druid by druid-io.

the class AppendTest method testTopNSeries.

@Test
public void testTopNSeries() {
    List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<TopNResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>builder().put("market", "spot").put("rows", 3L).put("index", 300.0D).put("addRowsIndexConstant", 304.0D).put("uniques", 0.0D).put("maxIndex", 100.0).put("minIndex", 100.0).build(), new HashMap<String, Object>() {

        {
            put("market", null);
            put("rows", 3L);
            put("index", 200.0D);
            put("addRowsIndexConstant", 204.0D);
            put("uniques", 0.0D);
            put("maxIndex", 100.0);
            put("minIndex", 0.0);
        }
    }, ImmutableMap.<String, Object>builder().put("market", "total_market").put("rows", 2L).put("index", 200.0D).put("addRowsIndexConstant", 203.0D).put("uniques", 1.0002442201269182D).put("maxIndex", 100.0D).put("minIndex", 100.0D).build()))));
    TopNQuery query = makeTopNQuery();
    QueryRunner runner = TestQueryRunners.makeTopNQueryRunner(segment);
    HashMap<String, Object> context = new HashMap<String, Object>();
    TestHelper.assertExpectedResults(expectedResults, runner.run(query, context));
}
Also used : TopNResultValue(io.druid.query.topn.TopNResultValue) HashMap(java.util.HashMap) TopNQuery(io.druid.query.topn.TopNQuery) DateTime(org.joda.time.DateTime) QueryRunner(io.druid.query.QueryRunner) Result(io.druid.query.Result) Test(org.junit.Test)

Aggregations

TopNResultValue (io.druid.query.topn.TopNResultValue)32 Result (io.druid.query.Result)30 QueryableIndexSegment (io.druid.segment.QueryableIndexSegment)15 Benchmark (org.openjdk.jmh.annotations.Benchmark)15 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)15 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)15 DateTime (org.joda.time.DateTime)14 TopNQuery (io.druid.query.topn.TopNQuery)11 Test (org.junit.Test)11 HashMap (java.util.HashMap)10 TopNQueryBuilder (io.druid.query.topn.TopNQueryBuilder)9 QueryRunner (io.druid.query.QueryRunner)6 DoubleMaxAggregatorFactory (io.druid.query.aggregation.DoubleMaxAggregatorFactory)5 DoubleMinAggregatorFactory (io.druid.query.aggregation.DoubleMinAggregatorFactory)5 PostAggregator (io.druid.query.aggregation.PostAggregator)5 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)4 ArithmeticPostAggregator (io.druid.query.aggregation.post.ArithmeticPostAggregator)3 ConstantPostAggregator (io.druid.query.aggregation.post.ConstantPostAggregator)3 FieldAccessPostAggregator (io.druid.query.aggregation.post.FieldAccessPostAggregator)3 GroupByQueryRunnerTest (io.druid.query.groupby.GroupByQueryRunnerTest)3