Search in sources :

Example 31 with TopNResultValue

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

the class CachingClusteredClientTest method testOutOfOrderSequenceMerging.

@Test
public void testOutOfOrderSequenceMerging() throws Exception {
    List<Sequence<Result<TopNResultValue>>> sequences = ImmutableList.of(Sequences.simple(makeTopNResultsWithoutRename(new DateTime("2011-01-07"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, new DateTime("2011-01-08"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, new DateTime("2011-01-09"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983)), Sequences.simple(makeTopNResultsWithoutRename(new DateTime("2011-01-06T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, new DateTime("2011-01-07T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, new DateTime("2011-01-08T01"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, new DateTime("2011-01-09T01"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983)));
    TestHelper.assertExpectedResults(makeTopNResultsWithoutRename(new DateTime("2011-01-06T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, new DateTime("2011-01-07"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, new DateTime("2011-01-07T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, new DateTime("2011-01-08"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, new DateTime("2011-01-08T01"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, new DateTime("2011-01-09"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983, new DateTime("2011-01-09T01"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983), client.mergeCachedAndUncachedSequences(new TopNQueryBuilder().dataSource("test").intervals("2011-01-06/2011-01-10").dimension("a").metric("b").threshold(3).aggregators(Arrays.<AggregatorFactory>asList(new CountAggregatorFactory("b"))).build(), sequences));
}
Also used : TopNResultValue(io.druid.query.topn.TopNResultValue) TopNQueryBuilder(io.druid.query.topn.TopNQueryBuilder) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) Sequence(io.druid.java.util.common.guava.Sequence) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) HyperUniquesAggregatorFactory(io.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFactory) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) DateTime(org.joda.time.DateTime) Test(org.junit.Test) GroupByQueryRunnerTest(io.druid.query.groupby.GroupByQueryRunnerTest)

Example 32 with TopNResultValue

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

the class CachingQueryRunnerTest method makeTopNResults.

private List<Result> makeTopNResults(boolean cachedResults, Object... objects) {
    List<Result> retVal = Lists.newArrayList();
    int index = 0;
    while (index < objects.length) {
        DateTime timestamp = (DateTime) objects[index++];
        List<Map<String, Object>> values = Lists.newArrayList();
        while (index < objects.length && !(objects[index] instanceof DateTime)) {
            if (objects.length - index < 3) {
                throw new ISE("expect 3 values for each entry in the top list, had %d values left.", objects.length - index);
            }
            final double imps = ((Number) objects[index + 2]).doubleValue();
            final double rows = ((Number) objects[index + 1]).doubleValue();
            if (cachedResults) {
                values.add(ImmutableMap.of("top_dim", objects[index], "rows", rows, "imps", imps, "impers", imps));
            } else {
                values.add(ImmutableMap.of("top_dim", objects[index], "rows", rows, "imps", imps, "impers", imps, "avg_imps_per_row", imps / rows));
            }
            index += 3;
        }
        retVal.add(new Result<>(timestamp, new TopNResultValue(values)));
    }
    return retVal;
}
Also used : TopNResultValue(io.druid.query.topn.TopNResultValue) ISE(io.druid.java.util.common.ISE) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result)

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