Search in sources :

Example 31 with TopNResultValue

use of org.apache.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 = new ArrayList<>();
    int index = 0;
    while (index < objects.length) {
        DateTime timestamp = (DateTime) objects[index++];
        List<Map<String, Object>> values = new ArrayList<>();
        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(org.apache.druid.query.topn.TopNResultValue) ArrayList(java.util.ArrayList) ISE(org.apache.druid.java.util.common.ISE) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) DateTime(org.joda.time.DateTime) Result(org.apache.druid.query.Result)

Example 32 with TopNResultValue

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

the class CachingClusteredClientTest method makeTopNResults.

private Iterable<Result<TopNResultValue>> makeTopNResults(List<String> names, Object... objects) {
    Preconditions.checkArgument(names.size() == 7);
    List<Result<TopNResultValue>> retVal = new ArrayList<>();
    int index = 0;
    while (index < objects.length) {
        DateTime timestamp = (DateTime) objects[index++];
        List<Map<String, Object>> values = new ArrayList<>();
        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();
            values.add(ImmutableMap.<String, Object>builder().put(names.get(0), objects[index]).put(names.get(1), rows).put(names.get(2), imps).put(names.get(3), imps).put(names.get(4), imps / rows).put(names.get(5), ((imps * 2) / rows)).put(names.get(6), (imps / (rows * 2))).build());
            index += 3;
        }
        retVal.add(new Result<>(timestamp, new TopNResultValue(values)));
    }
    return retVal;
}
Also used : TopNResultValue(org.apache.druid.query.topn.TopNResultValue) ArrayList(java.util.ArrayList) ISE(org.apache.druid.java.util.common.ISE) Map(java.util.Map) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) DateTime(org.joda.time.DateTime) Result(org.apache.druid.query.Result)

Aggregations

TopNResultValue (org.apache.druid.query.topn.TopNResultValue)32 Result (org.apache.druid.query.Result)28 QueryableIndexSegment (org.apache.druid.segment.QueryableIndexSegment)17 Benchmark (org.openjdk.jmh.annotations.Benchmark)14 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)14 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)14 TopNQueryBuilder (org.apache.druid.query.topn.TopNQueryBuilder)11 Test (org.junit.Test)11 TopNQuery (org.apache.druid.query.topn.TopNQuery)10 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)9 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)7 Map (java.util.Map)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 ArrayList (java.util.ArrayList)5 TopNQueryQueryToolChest (org.apache.druid.query.topn.TopNQueryQueryToolChest)5 ByteBuffer (java.nio.ByteBuffer)4 HashMap (java.util.HashMap)4 Sequence (org.apache.druid.java.util.common.guava.Sequence)4 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)4 GroupByQueryRunnerTest (org.apache.druid.query.groupby.GroupByQueryRunnerTest)4