Search in sources :

Example 11 with InvertedTopNMetricSpec

use of org.apache.druid.query.topn.InvertedTopNMetricSpec 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 12 with InvertedTopNMetricSpec

use of org.apache.druid.query.topn.InvertedTopNMetricSpec 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 13 with InvertedTopNMetricSpec

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

the class CalciteQueryTest method testOrderByEarliestDouble.

@Test
public void testOrderByEarliestDouble() throws Exception {
    // Cannot vectorize EARLIEST aggregator.
    skipVectorize();
    List<Object[]> expected;
    if (NullHandling.replaceWithDefault()) {
        expected = ImmutableList.of(new Object[] { "1", 0.0 }, new Object[] { "2", 0.0 }, new Object[] { "abc", 0.0 }, new Object[] { "def", 0.0 }, new Object[] { "", 1.0 }, new Object[] { "10.1", 1.7 });
    } else {
        expected = ImmutableList.of(new Object[] { "1", null }, new Object[] { "abc", null }, new Object[] { "def", null }, new Object[] { "2", 0.0 }, new Object[] { "", 1.0 }, new Object[] { "10.1", 1.7 });
    }
    testQuery("SELECT dim1, EARLIEST(d1) FROM druid.numfoo GROUP BY 1 ORDER BY 2 LIMIT 10", ImmutableList.of(new TopNQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).dimension(new DefaultDimensionSpec("dim1", "_d0")).aggregators(aggregators(new DoubleFirstAggregatorFactory("a0", "d1", null))).metric(new InvertedTopNMetricSpec(new NumericTopNMetricSpec("a0"))).threshold(10).context(QUERY_CONTEXT_DEFAULT).build()), expected);
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) InvertedTopNMetricSpec(org.apache.druid.query.topn.InvertedTopNMetricSpec) DoubleFirstAggregatorFactory(org.apache.druid.query.aggregation.first.DoubleFirstAggregatorFactory) NumericTopNMetricSpec(org.apache.druid.query.topn.NumericTopNMetricSpec) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 14 with InvertedTopNMetricSpec

use of org.apache.druid.query.topn.InvertedTopNMetricSpec 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 15 with InvertedTopNMetricSpec

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

the class CalciteQueryTest method testOrderByAnyLong.

@Test
public void testOrderByAnyLong() throws Exception {
    List<Object[]> expected;
    if (NullHandling.replaceWithDefault()) {
        expected = ImmutableList.of(new Object[] { "1", 0L }, new Object[] { "2", 0L }, new Object[] { "abc", 0L }, new Object[] { "def", 0L }, new Object[] { "", 7L }, new Object[] { "10.1", 325323L });
    } else {
        expected = ImmutableList.of(new Object[] { "2", 0L }, new Object[] { "", 7L }, new Object[] { "10.1", 325323L }, // reversed by TopNNumericResultBuilder.build()
        new Object[] { "1", null }, new Object[] { "abc", null }, new Object[] { "def", null });
    }
    testQuery("SELECT dim1, ANY_VALUE(l1) FROM druid.numfoo GROUP BY 1 ORDER BY 2 LIMIT 10", ImmutableList.of(new TopNQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).dimension(new DefaultDimensionSpec("dim1", "_d0")).aggregators(aggregators(new LongAnyAggregatorFactory("a0", "l1"))).metric(new InvertedTopNMetricSpec(new NumericTopNMetricSpec("a0"))).threshold(10).context(QUERY_CONTEXT_DEFAULT).build()), expected);
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) InvertedTopNMetricSpec(org.apache.druid.query.topn.InvertedTopNMetricSpec) LongAnyAggregatorFactory(org.apache.druid.query.aggregation.any.LongAnyAggregatorFactory) NumericTopNMetricSpec(org.apache.druid.query.topn.NumericTopNMetricSpec) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Aggregations

InvertedTopNMetricSpec (org.apache.druid.query.topn.InvertedTopNMetricSpec)15 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)14 TopNQueryBuilder (org.apache.druid.query.topn.TopNQueryBuilder)14 Test (org.junit.Test)14 NumericTopNMetricSpec (org.apache.druid.query.topn.NumericTopNMetricSpec)10 DimensionTopNMetricSpec (org.apache.druid.query.topn.DimensionTopNMetricSpec)6 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)4 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1 DataSource (org.apache.druid.query.DataSource)1 JoinDataSource (org.apache.druid.query.JoinDataSource)1 QueryDataSource (org.apache.druid.query.QueryDataSource)1 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)1 DoubleAnyAggregatorFactory (org.apache.druid.query.aggregation.any.DoubleAnyAggregatorFactory)1 FloatAnyAggregatorFactory (org.apache.druid.query.aggregation.any.FloatAnyAggregatorFactory)1 LongAnyAggregatorFactory (org.apache.druid.query.aggregation.any.LongAnyAggregatorFactory)1 DoubleFirstAggregatorFactory (org.apache.druid.query.aggregation.first.DoubleFirstAggregatorFactory)1 FloatFirstAggregatorFactory (org.apache.druid.query.aggregation.first.FloatFirstAggregatorFactory)1