Search in sources :

Example 11 with DimensionTopNMetricSpec

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

the class CalciteJoinQueryTest method testExactTopNOnInnerJoinWithLimit.

@Test
public void testExactTopNOnInnerJoinWithLimit() throws Exception {
    // Adjust topN threshold, so that the topN engine keeps only 1 slot for aggregates, which should be enough
    // to compute the query with limit 1.
    minTopNThreshold = 1;
    Map<String, Object> context = new HashMap<>(QUERY_CONTEXT_DEFAULT);
    context.put(PlannerConfig.CTX_KEY_USE_APPROXIMATE_TOPN, false);
    testQuery("select f1.\"dim4\", sum(\"m1\") from numfoo f1 inner join (\n" + "  select \"dim4\" from numfoo where dim4 <> 'a' group by 1\n" + ") f2 on f1.\"dim4\" = f2.\"dim4\" group by 1 limit 1", // turn on exact topN
    context, ImmutableList.of(new TopNQueryBuilder().intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).dimension(new DefaultDimensionSpec("dim4", "_d0")).aggregators(new DoubleSumAggregatorFactory("a0", "m1")).metric(new DimensionTopNMetricSpec(null, StringComparators.LEXICOGRAPHIC)).threshold(1).dataSource(JoinDataSource.create(new TableDataSource("numfoo"), new QueryDataSource(GroupByQuery.builder().setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(new NotDimFilter(new SelectorDimFilter("dim4", "a", null))).setDataSource(new TableDataSource("numfoo")).setDimensions(new DefaultDimensionSpec("dim4", "_d0")).setContext(context).build()), "j0.", "(\"dim4\" == \"j0._d0\")", JoinType.INNER, null, ExprMacroTable.nil())).context(context).build()), ImmutableList.of(new Object[] { "b", 15.0 }));
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) DimensionTopNMetricSpec(org.apache.druid.query.topn.DimensionTopNMetricSpec) NotDimFilter(org.apache.druid.query.filter.NotDimFilter) DoubleSumAggregatorFactory(org.apache.druid.query.aggregation.DoubleSumAggregatorFactory) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) HashMap(java.util.HashMap) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Aggregations

DimensionTopNMetricSpec (org.apache.druid.query.topn.DimensionTopNMetricSpec)11 TopNQueryBuilder (org.apache.druid.query.topn.TopNQueryBuilder)9 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)8 Test (org.junit.Test)8 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)6 InvertedTopNMetricSpec (org.apache.druid.query.topn.InvertedTopNMetricSpec)6 ArrayList (java.util.ArrayList)3 QueryDataSource (org.apache.druid.query.QueryDataSource)3 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)3 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TableDataSource (org.apache.druid.query.TableDataSource)2 DoubleMinAggregatorFactory (org.apache.druid.query.aggregation.DoubleMinAggregatorFactory)2 LongMaxAggregatorFactory (org.apache.druid.query.aggregation.LongMaxAggregatorFactory)2 HyperUniquesAggregatorFactory (org.apache.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFactory)2 NotDimFilter (org.apache.druid.query.filter.NotDimFilter)2 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)2 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)2