Search in sources :

Example 6 with DimensionTopNMetricSpec

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

the class CalciteQueryTest method testTopNLimitWrapping.

@Test
public void testTopNLimitWrapping() throws Exception {
    List<Object[]> expected;
    if (NullHandling.replaceWithDefault()) {
        expected = ImmutableList.of(new Object[] { "", 1L }, new Object[] { "def", 1L });
    } else {
        expected = ImmutableList.of(new Object[] { "def", 1L }, new Object[] { "abc", 1L });
    }
    testQuery("SELECT dim1, COUNT(*) FROM druid.foo GROUP BY dim1 ORDER BY dim1 DESC", OUTER_LIMIT_CONTEXT, ImmutableList.of(new TopNQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).dimension(new DefaultDimensionSpec("dim1", "d0", ColumnType.STRING)).threshold(2).aggregators(aggregators(new CountAggregatorFactory("a0"))).metric(new InvertedTopNMetricSpec(new DimensionTopNMetricSpec(null, StringComparators.LEXICOGRAPHIC))).context(OUTER_LIMIT_CONTEXT).build()), expected);
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) InvertedTopNMetricSpec(org.apache.druid.query.topn.InvertedTopNMetricSpec) DimensionTopNMetricSpec(org.apache.druid.query.topn.DimensionTopNMetricSpec) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 7 with DimensionTopNMetricSpec

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

the class CalciteQueryTest method testNullLongTopN.

@Test
public void testNullLongTopN() throws Exception {
    List<Object[]> expected;
    if (useDefault) {
        expected = ImmutableList.of(new Object[] { 325323L, 1L }, new Object[] { 7L, 1L }, new Object[] { 0L, 4L });
    } else {
        expected = ImmutableList.of(new Object[] { null, 3L }, new Object[] { 325323L, 1L }, new Object[] { 7L, 1L }, new Object[] { 0L, 1L });
    }
    testQuery("SELECT l1, COUNT(*) FROM druid.numfoo GROUP BY l1 ORDER BY l1 DESC LIMIT 10", QUERY_CONTEXT_DEFAULT, ImmutableList.of(new TopNQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).dimension(new DefaultDimensionSpec("l1", "_d0", ColumnType.LONG)).threshold(10).aggregators(aggregators(new CountAggregatorFactory("a0"))).metric(new InvertedTopNMetricSpec(new DimensionTopNMetricSpec(null, StringComparators.NUMERIC))).context(QUERY_CONTEXT_DEFAULT).build()), expected);
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) InvertedTopNMetricSpec(org.apache.druid.query.topn.InvertedTopNMetricSpec) DimensionTopNMetricSpec(org.apache.druid.query.topn.DimensionTopNMetricSpec) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 8 with DimensionTopNMetricSpec

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

the class CalciteQueryTest method testNullFloatTopN.

@Test
public void testNullFloatTopN() throws Exception {
    List<Object[]> expected;
    if (useDefault) {
        expected = ImmutableList.of(new Object[] { 1.0f, 1L }, new Object[] { 0.1f, 1L }, new Object[] { 0.0f, 4L });
    } else {
        expected = ImmutableList.of(new Object[] { null, 3L }, new Object[] { 1.0f, 1L }, new Object[] { 0.1f, 1L }, new Object[] { 0.0f, 1L });
    }
    testQuery("SELECT f1, COUNT(*) FROM druid.numfoo GROUP BY f1 ORDER BY f1 DESC LIMIT 10", QUERY_CONTEXT_DEFAULT, ImmutableList.of(new TopNQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).dimension(new DefaultDimensionSpec("f1", "_d0", ColumnType.FLOAT)).threshold(10).aggregators(aggregators(new CountAggregatorFactory("a0"))).metric(new InvertedTopNMetricSpec(new DimensionTopNMetricSpec(null, StringComparators.NUMERIC))).context(QUERY_CONTEXT_DEFAULT).build()), expected);
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) InvertedTopNMetricSpec(org.apache.druid.query.topn.InvertedTopNMetricSpec) DimensionTopNMetricSpec(org.apache.druid.query.topn.DimensionTopNMetricSpec) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 9 with DimensionTopNMetricSpec

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

the class CalciteQueryTest method testExactCountDistinctUsingSubqueryWithWhereToOuterFilter.

@Test
public void testExactCountDistinctUsingSubqueryWithWhereToOuterFilter() throws Exception {
    // Cannot vectorize topN operator.
    cannotVectorize();
    testQuery("SELECT\n" + "  SUM(cnt),\n" + "  COUNT(*)\n" + "FROM (SELECT dim2, SUM(cnt) AS cnt FROM druid.foo GROUP BY dim2 LIMIT 1)" + "WHERE cnt > 0", ImmutableList.of(GroupByQuery.builder().setDataSource(new QueryDataSource(new TopNQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).dimension(new DefaultDimensionSpec("dim2", "d0")).aggregators(new LongSumAggregatorFactory("a0", "cnt")).metric(new DimensionTopNMetricSpec(null, StringComparators.LEXICOGRAPHIC)).threshold(1).context(QUERY_CONTEXT_DEFAULT).build())).setDimFilter(bound("a0", "0", null, true, false, null, StringComparators.NUMERIC)).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("_a0", "a0"), new CountAggregatorFactory("_a1"))).setContext(QUERY_CONTEXT_DEFAULT).build()), NullHandling.replaceWithDefault() ? ImmutableList.of(new Object[] { 3L, 1L }) : ImmutableList.of(new Object[] { 2L, 1L }));
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) DimensionTopNMetricSpec(org.apache.druid.query.topn.DimensionTopNMetricSpec) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 10 with DimensionTopNMetricSpec

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

the class CalciteArraysQueryTest method testArrayAggGroupByArrayAggFromSubquery.

@Test
public void testArrayAggGroupByArrayAggFromSubquery() throws Exception {
    cannotVectorize();
    testQuery("SELECT dim2, arr, COUNT(*) FROM (SELECT dim2, ARRAY_AGG(DISTINCT dim1) as arr FROM foo WHERE dim1 is not null GROUP BY 1 LIMIT 5) GROUP BY 1,2", QUERY_CONTEXT_NO_STRINGIFY_ARRAY, ImmutableList.of(GroupByQuery.builder().setDataSource(new TopNQuery(new TableDataSource(CalciteTests.DATASOURCE1), null, new DefaultDimensionSpec("dim2", "d0", ColumnType.STRING), new DimensionTopNMetricSpec(null, StringComparators.LEXICOGRAPHIC), 5, querySegmentSpec(Filtration.eternity()), new NotDimFilter(new SelectorDimFilter("dim1", null, null)), Granularities.ALL, aggregators(new ExpressionLambdaAggregatorFactory("a0", ImmutableSet.of("dim1"), "__acc", "ARRAY<STRING>[]", "ARRAY<STRING>[]", true, true, false, "array_set_add(\"__acc\", \"dim1\")", "array_set_add_all(\"__acc\", \"a0\")", null, null, new HumanReadableBytes(1024), ExprMacroTable.nil())), null, QUERY_CONTEXT_NO_STRINGIFY_ARRAY)).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(null).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("d0", "_d0", ColumnType.STRING), new DefaultDimensionSpec("a0", "_d1", ColumnType.STRING_ARRAY))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("_a0"))).setContext(QUERY_CONTEXT_NO_STRINGIFY_ARRAY).build()), useDefault ? ImmutableList.of(new Object[] { "", ImmutableList.of("10.1", "2", "abc"), 1L }, new Object[] { "a", ImmutableList.of("1"), 1L }, new Object[] { "abc", ImmutableList.of("def"), 1L }) : ImmutableList.of(new Object[] { null, ImmutableList.of("10.1", "abc"), 1L }, new Object[] { "", ImmutableList.of("2"), 1L }, new Object[] { "a", ImmutableList.of("", "1"), 1L }, new Object[] { "abc", ImmutableList.of("def"), 1L }));
}
Also used : DimensionTopNMetricSpec(org.apache.druid.query.topn.DimensionTopNMetricSpec) NotDimFilter(org.apache.druid.query.filter.NotDimFilter) ExpressionLambdaAggregatorFactory(org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory) TableDataSource(org.apache.druid.query.TableDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) TopNQuery(org.apache.druid.query.topn.TopNQuery) HumanReadableBytes(org.apache.druid.java.util.common.HumanReadableBytes) 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