Search in sources :

Example 11 with TopNQueryConfig

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

the class MultiValuedDimensionTest method testTopNExpression.

@Test
public void testTopNExpression() {
    TopNQuery query = new TopNQueryBuilder().dataSource("xx").granularity(Granularities.ALL).dimension(new DefaultDimensionSpec("texpr", "texpr")).virtualColumns(new ExpressionVirtualColumn("texpr", "map(x -> concat(x, 'foo'), tags)", ColumnType.STRING, TestExprMacroTable.INSTANCE)).metric("count").intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(new CountAggregatorFactory("count")).threshold(15).build();
    try (CloseableStupidPool<ByteBuffer> pool = TestQueryRunners.createDefaultNonBlockingPool()) {
        QueryRunnerFactory factory = new TopNQueryRunnerFactory(pool, new TopNQueryQueryToolChest(new TopNQueryConfig()), QueryRunnerTestHelper.NOOP_QUERYWATCHER);
        QueryRunner<Result<TopNResultValue>> runner = QueryRunnerTestHelper.makeQueryRunner(factory, new QueryableIndexSegment(queryableIndex, SegmentId.dummy("sid1")), null);
        Sequence<Result<TopNResultValue>> result = runner.run(QueryPlus.wrap(query));
        List<Map<String, Object>> expected = ImmutableList.<Map<String, Object>>builder().add(ImmutableMap.of("texpr", "t3foo", "count", 2L)).add(ImmutableMap.of("texpr", "t5foo", "count", 2L)).add(new HashMap<String, Object>() {

            {
                put("texpr", NullHandling.sqlCompatible() ? "foo" : null);
                put("count", 1L);
            }
        }).add(ImmutableMap.of("texpr", "t1foo", "count", 1L)).add(ImmutableMap.of("texpr", "t2foo", "count", 1L)).add(ImmutableMap.of("texpr", "t4foo", "count", 1L)).add(ImmutableMap.of("texpr", "t6foo", "count", 1L)).add(ImmutableMap.of("texpr", "t7foo", "count", 1L)).build();
        List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<TopNResultValue>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(expected)));
        TestHelper.assertExpectedObjects(expectedResults, result.toList(), "filteredDim");
    }
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) QueryableIndexSegment(org.apache.druid.segment.QueryableIndexSegment) TopNResultValue(org.apache.druid.query.topn.TopNResultValue) ByteBuffer(java.nio.ByteBuffer) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) TopNQueryRunnerFactory(org.apache.druid.query.topn.TopNQueryRunnerFactory) TopNQueryConfig(org.apache.druid.query.topn.TopNQueryConfig) TopNQuery(org.apache.druid.query.topn.TopNQuery) TopNQueryRunnerFactory(org.apache.druid.query.topn.TopNQueryRunnerFactory) TopNQueryQueryToolChest(org.apache.druid.query.topn.TopNQueryQueryToolChest) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) GroupByQueryRunnerTest(org.apache.druid.query.groupby.GroupByQueryRunnerTest) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 12 with TopNQueryConfig

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

the class MultiValuedDimensionTest method testTopNExpressionAutoTransform.

@Test
public void testTopNExpressionAutoTransform() {
    TopNQuery query = new TopNQueryBuilder().dataSource("xx").granularity(Granularities.ALL).dimension(new DefaultDimensionSpec("texpr", "texpr")).virtualColumns(new ExpressionVirtualColumn("texpr", "concat(tags, 'foo')", ColumnType.STRING, TestExprMacroTable.INSTANCE)).metric("count").intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(new CountAggregatorFactory("count")).threshold(15).build();
    try (CloseableStupidPool<ByteBuffer> pool = TestQueryRunners.createDefaultNonBlockingPool()) {
        QueryRunnerFactory factory = new TopNQueryRunnerFactory(pool, new TopNQueryQueryToolChest(new TopNQueryConfig()), QueryRunnerTestHelper.NOOP_QUERYWATCHER);
        QueryRunner<Result<TopNResultValue>> runner = QueryRunnerTestHelper.makeQueryRunner(factory, new QueryableIndexSegment(queryableIndex, SegmentId.dummy("sid1")), null);
        Sequence<Result<TopNResultValue>> result = runner.run(QueryPlus.wrap(query));
        List<Map<String, Object>> expected = ImmutableList.<Map<String, Object>>builder().add(ImmutableMap.of("texpr", "t3foo", "count", 2L)).add(ImmutableMap.of("texpr", "t5foo", "count", 2L)).add(ImmutableMap.of("texpr", "foo", "count", 1L)).add(ImmutableMap.of("texpr", "t1foo", "count", 1L)).add(ImmutableMap.of("texpr", "t2foo", "count", 1L)).add(ImmutableMap.of("texpr", "t4foo", "count", 1L)).add(ImmutableMap.of("texpr", "t6foo", "count", 1L)).add(ImmutableMap.of("texpr", "t7foo", "count", 1L)).build();
        List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<TopNResultValue>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(expected)));
        TestHelper.assertExpectedObjects(expectedResults, result.toList(), "filteredDim");
    }
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) QueryableIndexSegment(org.apache.druid.segment.QueryableIndexSegment) TopNResultValue(org.apache.druid.query.topn.TopNResultValue) ByteBuffer(java.nio.ByteBuffer) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) TopNQueryRunnerFactory(org.apache.druid.query.topn.TopNQueryRunnerFactory) TopNQueryConfig(org.apache.druid.query.topn.TopNQueryConfig) TopNQuery(org.apache.druid.query.topn.TopNQuery) TopNQueryRunnerFactory(org.apache.druid.query.topn.TopNQueryRunnerFactory) TopNQueryQueryToolChest(org.apache.druid.query.topn.TopNQueryQueryToolChest) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) GroupByQueryRunnerTest(org.apache.druid.query.groupby.GroupByQueryRunnerTest) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 13 with TopNQueryConfig

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

the class MultiValuedDimensionTest method testTopNWithDimFilterAndWithFilteredDimSpec.

@Test
public void testTopNWithDimFilterAndWithFilteredDimSpec() {
    TopNQuery query = new TopNQueryBuilder().dataSource("xx").granularity(Granularities.ALL).dimension(new ListFilteredDimensionSpec(new DefaultDimensionSpec("tags", "tags"), ImmutableSet.of("t3"), null)).metric("count").intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(new CountAggregatorFactory("count")).threshold(5).filters(new SelectorDimFilter("tags", "t3", null)).build();
    try (CloseableStupidPool<ByteBuffer> pool = TestQueryRunners.createDefaultNonBlockingPool()) {
        QueryRunnerFactory factory = new TopNQueryRunnerFactory(pool, new TopNQueryQueryToolChest(new TopNQueryConfig()), QueryRunnerTestHelper.NOOP_QUERYWATCHER);
        QueryRunner<Result<TopNResultValue>> runner = QueryRunnerTestHelper.makeQueryRunner(factory, new QueryableIndexSegment(queryableIndex, SegmentId.dummy("sid1")), null);
        Sequence<Result<TopNResultValue>> result = runner.run(QueryPlus.wrap(query));
        List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<TopNResultValue>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Collections.<Map<String, Object>>singletonList(ImmutableMap.of("tags", "t3", "count", 2L)))));
        TestHelper.assertExpectedObjects(expectedResults, result.toList(), "filteredDim");
    }
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) QueryableIndexSegment(org.apache.druid.segment.QueryableIndexSegment) TopNResultValue(org.apache.druid.query.topn.TopNResultValue) ByteBuffer(java.nio.ByteBuffer) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ListFilteredDimensionSpec(org.apache.druid.query.dimension.ListFilteredDimensionSpec) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) TopNQueryRunnerFactory(org.apache.druid.query.topn.TopNQueryRunnerFactory) TopNQueryConfig(org.apache.druid.query.topn.TopNQueryConfig) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) TopNQuery(org.apache.druid.query.topn.TopNQuery) TopNQueryRunnerFactory(org.apache.druid.query.topn.TopNQueryRunnerFactory) TopNQueryQueryToolChest(org.apache.druid.query.topn.TopNQueryQueryToolChest) GroupByQueryRunnerTest(org.apache.druid.query.groupby.GroupByQueryRunnerTest) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 14 with TopNQueryConfig

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

the class ApproximateHistogramTopNQueryTest method constructorFeeder.

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> constructorFeeder() {
    final CloseableStupidPool<ByteBuffer> defaultPool = TestQueryRunners.createDefaultNonBlockingPool();
    final CloseableStupidPool<ByteBuffer> customPool = new CloseableStupidPool<>("TopNQueryRunnerFactory-bufferPool", () -> ByteBuffer.allocate(2000));
    RESOURCE_CLOSER.register(defaultPool);
    RESOURCE_CLOSER.register(customPool);
    return QueryRunnerTestHelper.transformToConstructionFeeder(Iterables.concat(QueryRunnerTestHelper.makeQueryRunners(new TopNQueryRunnerFactory(defaultPool, new TopNQueryQueryToolChest(new TopNQueryConfig()), QueryRunnerTestHelper.NOOP_QUERYWATCHER)), QueryRunnerTestHelper.makeQueryRunners(new TopNQueryRunnerFactory(customPool, new TopNQueryQueryToolChest(new TopNQueryConfig()), QueryRunnerTestHelper.NOOP_QUERYWATCHER))));
}
Also used : TopNQueryConfig(org.apache.druid.query.topn.TopNQueryConfig) TopNQueryRunnerFactory(org.apache.druid.query.topn.TopNQueryRunnerFactory) TopNQueryQueryToolChest(org.apache.druid.query.topn.TopNQueryQueryToolChest) CloseableStupidPool(org.apache.druid.collections.CloseableStupidPool) ByteBuffer(java.nio.ByteBuffer)

Example 15 with TopNQueryConfig

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

the class FixedBucketsHistogramTopNQueryTest method constructorFeeder.

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> constructorFeeder() {
    final CloseableStupidPool<ByteBuffer> defaultPool = TestQueryRunners.createDefaultNonBlockingPool();
    final CloseableStupidPool<ByteBuffer> customPool = new CloseableStupidPool<>("TopNQueryRunnerFactory-bufferPool", () -> ByteBuffer.allocate(2000));
    RESOURCE_CLOSER.register(defaultPool);
    RESOURCE_CLOSER.register(customPool);
    return QueryRunnerTestHelper.transformToConstructionFeeder(Iterables.concat(QueryRunnerTestHelper.makeQueryRunners(new TopNQueryRunnerFactory(defaultPool, new TopNQueryQueryToolChest(new TopNQueryConfig()), QueryRunnerTestHelper.NOOP_QUERYWATCHER)), QueryRunnerTestHelper.makeQueryRunners(new TopNQueryRunnerFactory(customPool, new TopNQueryQueryToolChest(new TopNQueryConfig()), QueryRunnerTestHelper.NOOP_QUERYWATCHER))));
}
Also used : TopNQueryConfig(org.apache.druid.query.topn.TopNQueryConfig) TopNQueryRunnerFactory(org.apache.druid.query.topn.TopNQueryRunnerFactory) TopNQueryQueryToolChest(org.apache.druid.query.topn.TopNQueryQueryToolChest) CloseableStupidPool(org.apache.druid.collections.CloseableStupidPool) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TopNQueryConfig (org.apache.druid.query.topn.TopNQueryConfig)21 TopNQueryQueryToolChest (org.apache.druid.query.topn.TopNQueryQueryToolChest)21 TopNQueryBuilder (org.apache.druid.query.topn.TopNQueryBuilder)12 TopNQueryRunnerFactory (org.apache.druid.query.topn.TopNQueryRunnerFactory)12 TopNQuery (org.apache.druid.query.topn.TopNQuery)10 Test (org.junit.Test)9 ByteBuffer (java.nio.ByteBuffer)7 TimeseriesQueryQueryToolChest (org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest)6 CloseableStupidPool (org.apache.druid.collections.CloseableStupidPool)4 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)4 QueryRunner (org.apache.druid.query.QueryRunner)4 QueryToolChest (org.apache.druid.query.QueryToolChest)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3 StupidPool (org.apache.druid.collections.StupidPool)3 Closer (org.apache.druid.java.util.common.io.Closer)3 OffheapBufferGenerator (org.apache.druid.offheap.OffheapBufferGenerator)3 Query (org.apache.druid.query.Query)3 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)3 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)3