Search in sources :

Example 1 with TopNResultValue

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

the class CachingClusteredClientTest method testOutOfOrderSequenceMerging.

@Test
public void testOutOfOrderSequenceMerging() {
    List<Sequence<Result<TopNResultValue>>> sequences = ImmutableList.of(Sequences.simple(makeTopNResultsWithoutRename(DateTimes.of("2011-01-07"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, DateTimes.of("2011-01-08"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, DateTimes.of("2011-01-09"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983)), Sequences.simple(makeTopNResultsWithoutRename(DateTimes.of("2011-01-06T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, DateTimes.of("2011-01-07T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, DateTimes.of("2011-01-08T01"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, DateTimes.of("2011-01-09T01"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983)));
    TestHelper.assertExpectedResults(makeTopNResultsWithoutRename(DateTimes.of("2011-01-06T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, DateTimes.of("2011-01-07"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, DateTimes.of("2011-01-07T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, DateTimes.of("2011-01-08"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, DateTimes.of("2011-01-08T01"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, DateTimes.of("2011-01-09"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983, DateTimes.of("2011-01-09T01"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983), mergeSequences(new TopNQueryBuilder().dataSource("test").intervals("2011-01-06/2011-01-10").dimension("a").metric("b").threshold(3).aggregators(new CountAggregatorFactory("b")).randomQueryId().build(), sequences));
}
Also used : TopNResultValue(org.apache.druid.query.topn.TopNResultValue) TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) Sequence(org.apache.druid.java.util.common.guava.Sequence) Test(org.junit.Test)

Example 2 with TopNResultValue

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

the class BackgroundCachePopulatorTest 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) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DateTime(org.joda.time.DateTime) Result(org.apache.druid.query.Result)

Example 3 with TopNResultValue

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

the class DummyStringVirtualColumnTest method testTopN.

private void testTopN(List<Segment> segments, boolean enableRowBasedMethods, boolean enableColumnBasedMethods) {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(Granularities.ALL).dimension(VSTRING_DIM).metric(COUNT).threshold(1).aggregators(new CountAggregatorFactory(COUNT)).virtualColumns(new DummyStringVirtualColumn(QueryRunnerTestHelper.MARKET_DIMENSION, VSTRING_DIM, enableRowBasedMethods, enableColumnBasedMethods, false, true)).intervals("2000/2030").build();
    List rows = topNTestHelper.runQueryOnSegmentsObjs(segments, query).toList();
    List<Result<TopNResultValue>> expectedRows = Collections.singletonList(new Result<>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Collections.<Map<String, Object>>singletonList(ImmutableMap.<String, Object>builder().put(COUNT, 1674L).put(VSTRING_DIM, "spot").build()))));
    TestHelper.assertExpectedResults(expectedRows, (List<Result<TopNResultValue>>) rows, "failed");
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) TopNResultValue(org.apache.druid.query.topn.TopNResultValue) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) TopNQuery(org.apache.druid.query.topn.TopNQuery) List(java.util.List) Result(org.apache.druid.query.Result)

Example 4 with TopNResultValue

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

the class SchemalessTestSimpleTest method testFullOnTopN.

// @Test TODO: Handling of null values is inconsistent right now, need to make it all consistent and re-enable test
// TODO: Complain to Eric when you see this.  It shouldn't be like this...
@Ignore
@SuppressWarnings("unused")
public void testFullOnTopN() {
    TopNQuery query = new TopNQueryBuilder().dataSource(dataSource).granularity(ALL_GRAN).dimension(marketDimension).metric(indexMetric).threshold(3).intervals(fullOnInterval).aggregators(Lists.newArrayList(Iterables.concat(commonAggregators, Lists.newArrayList(new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index"))))).postAggregators(addRowsIndexConstant).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.asList(new DimensionAndMetricValueExtractor(ImmutableMap.<String, Object>builder().put("market", "spot").put("rows", 4L).put("index", 400.0D).put("addRowsIndexConstant", 405.0D).put("uniques", 1.0002442201269182D).put("maxIndex", 100.0).put("minIndex", 100.0).build()), new DimensionAndMetricValueExtractor(ImmutableMap.<String, Object>builder().put("market", "").put("rows", 2L).put("index", 200.0D).put("addRowsIndexConstant", 203.0D).put("uniques", 0.0).put("maxIndex", 100.0D).put("minIndex", 100.0D).build()), new DimensionAndMetricValueExtractor(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())))));
    try (CloseableStupidPool<ByteBuffer> pool = TestQueryRunners.createDefaultNonBlockingPool()) {
        QueryRunner runner = TestQueryRunners.makeTopNQueryRunner(segment, pool);
        TestHelper.assertExpectedResults(expectedResults, runner.run(QueryPlus.wrap(query)));
    }
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) TopNResultValue(org.apache.druid.query.topn.TopNResultValue) DoubleMaxAggregatorFactory(org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory) TopNQuery(org.apache.druid.query.topn.TopNQuery) DoubleMinAggregatorFactory(org.apache.druid.query.aggregation.DoubleMinAggregatorFactory) ByteBuffer(java.nio.ByteBuffer) DimensionAndMetricValueExtractor(org.apache.druid.query.topn.DimensionAndMetricValueExtractor) QueryRunner(org.apache.druid.query.QueryRunner) Result(org.apache.druid.query.Result) Ignore(org.junit.Ignore)

Example 5 with TopNResultValue

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

the class TestHelper method assertTopNResultValue.

private static void assertTopNResultValue(String msg, Result expected, Result actual) {
    TopNResultValue expectedVal = (TopNResultValue) expected.getValue();
    TopNResultValue actualVal = (TopNResultValue) actual.getValue();
    List<Row> listExpectedRows = expectedVal.getValue().stream().map(dimensionAndMetricValueExtractor -> new MapBasedRow(expected.getTimestamp(), dimensionAndMetricValueExtractor.getBaseObject())).collect(Collectors.toList());
    List<Row> listActualRows = actualVal.getValue().stream().map(dimensionAndMetricValueExtractor -> new MapBasedRow(actual.getTimestamp(), dimensionAndMetricValueExtractor.getBaseObject())).collect(Collectors.toList());
    Assert.assertEquals("Size of list must match", listExpectedRows.size(), listActualRows.size());
    IntStream.range(0, listExpectedRows.size()).forEach(value -> assertRow(StringUtils.format("%s, on value number [%s]", msg, value), listExpectedRows.get(value), listActualRows.get(value)));
}
Also used : TopNResultValue(org.apache.druid.query.topn.TopNResultValue) IntStream(java.util.stream.IntStream) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) ComparableList(org.apache.druid.segment.data.ComparableList) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) MapBasedRow(org.apache.druid.data.input.MapBasedRow) SegmentWriteOutMediumFactory(org.apache.druid.segment.writeout.SegmentWriteOutMediumFactory) HashMap(java.util.HashMap) TimeseriesResultValue(org.apache.druid.query.timeseries.TimeseriesResultValue) Row(org.apache.druid.data.input.Row) Lists(com.google.common.collect.Lists) Map(java.util.Map) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember) ComparableStringArray(org.apache.druid.segment.data.ComparableStringArray) PruneSpecsHolder(org.apache.druid.timeline.DataSegment.PruneSpecsHolder) Sequence(org.apache.druid.java.util.common.guava.Sequence) TopNResultValue(org.apache.druid.query.topn.TopNResultValue) Iterator(java.util.Iterator) ResultRow(org.apache.druid.query.groupby.ResultRow) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DruidSecondaryModule(org.apache.druid.guice.DruidSecondaryModule) StringUtils(org.apache.druid.java.util.common.StringUtils) IOException(java.io.IOException) TestExprMacroTable(org.apache.druid.query.expression.TestExprMacroTable) Collectors(java.util.stream.Collectors) ExprEval(org.apache.druid.math.expr.ExprEval) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) UncheckedIOException(java.io.UncheckedIOException) Result(org.apache.druid.query.Result) List(java.util.List) ColumnConfig(org.apache.druid.segment.column.ColumnConfig) GuiceAnnotationIntrospector(org.apache.druid.guice.GuiceAnnotationIntrospector) Preconditions(com.google.common.base.Preconditions) Assert(org.junit.Assert) MapBasedRow(org.apache.druid.data.input.MapBasedRow) MapBasedRow(org.apache.druid.data.input.MapBasedRow) Row(org.apache.druid.data.input.Row) ResultRow(org.apache.druid.query.groupby.ResultRow)

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