Search in sources :

Example 41 with TopNQueryBuilder

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

the class ClientQuerySegmentWalkerTest method testTopNOnArraysUnknownDoubles.

@Test
public void testTopNOnArraysUnknownDoubles() {
    final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(ARRAY_UNKNOWN).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("ad")).metric("sum_n").threshold(1000).aggregators(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
    // 'unknown' is treated as ColumnType.STRING. this might not always be the case, so this is a test case of wacky
    // behavior of sorts
    testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of(new Object[] { 946684800000L, "4.0", 6L }, new Object[] { 946684800000L, "8.0", 4L }, new Object[] { 946684800000L, "2.0", 3L }, new Object[] { 946684800000L, "3.0", 3L }, new Object[] { 946684800000L, "6.0", 3L }, new Object[] { 946684800000L, "1.0", 1L }));
    Assert.assertEquals(1, scheduler.getTotalRun().get());
    Assert.assertEquals(1, scheduler.getTotalPrioritizedAndLaned().get());
    Assert.assertEquals(1, scheduler.getTotalAcquired().get());
    Assert.assertEquals(1, scheduler.getTotalReleased().get());
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) TopNQuery(org.apache.druid.query.topn.TopNQuery) Test(org.junit.Test)

Example 42 with TopNQueryBuilder

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

the class ClientQuerySegmentWalkerTest method testTopNOnArraysLongs.

@Test
public void testTopNOnArraysLongs() {
    final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(ARRAY).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("al")).metric("sum_n").threshold(1000).aggregators(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
    // group by cannot handle true array types, expect this, RuntimeExeception with IAE in stack trace
    expectedException.expect(RuntimeException.class);
    expectedException.expectMessage("Cannot create query type helper from invalid type [ARRAY<LONG>]");
    testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of());
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) TopNQuery(org.apache.druid.query.topn.TopNQuery) Test(org.junit.Test)

Example 43 with TopNQueryBuilder

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

the class ClientQuerySegmentWalkerTest method testTopNArraysDoubles.

@Test
public void testTopNArraysDoubles() {
    final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(ARRAY).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("ad")).metric("sum_n").threshold(1000).aggregators(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
    // group by cannot handle true array types, expect this, RuntimeExeception with IAE in stack trace
    expectedException.expect(RuntimeException.class);
    expectedException.expectMessage("Cannot create query type helper from invalid type [ARRAY<DOUBLE>]");
    testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of());
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) TopNQuery(org.apache.druid.query.topn.TopNQuery) Test(org.junit.Test)

Example 44 with TopNQueryBuilder

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

the class CalciteQueryTest method testNullDoubleTopN.

@Test
public void testNullDoubleTopN() throws Exception {
    List<Object[]> expected;
    if (useDefault) {
        expected = ImmutableList.of(new Object[] { 1.7, 1L }, new Object[] { 1.0, 1L }, new Object[] { 0.0, 4L });
    } else {
        expected = ImmutableList.of(new Object[] { null, 3L }, new Object[] { 1.7, 1L }, new Object[] { 1.0, 1L }, new Object[] { 0.0, 1L });
    }
    testQuery("SELECT d1, COUNT(*) FROM druid.numfoo GROUP BY d1 ORDER BY d1 DESC LIMIT 10", QUERY_CONTEXT_DEFAULT, ImmutableList.of(new TopNQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).dimension(new DefaultDimensionSpec("d1", "_d0", ColumnType.DOUBLE)).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 45 with TopNQueryBuilder

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

the class CalciteQueryTest method testOrderByAnyFloat.

@Test
public void testOrderByAnyFloat() throws Exception {
    List<Object[]> expected;
    if (NullHandling.replaceWithDefault()) {
        expected = ImmutableList.of(new Object[] { "1", 0.0f }, new Object[] { "2", 0.0f }, new Object[] { "abc", 0.0f }, new Object[] { "def", 0.0f }, new Object[] { "10.1", 0.1f }, new Object[] { "", 1.0f });
    } else {
        expected = ImmutableList.of(new Object[] { "2", 0.0f }, new Object[] { "10.1", 0.1f }, new Object[] { "", 1.0f }, // reversed by TopNNumericResultBuilder.build()
        new Object[] { "1", null }, new Object[] { "abc", null }, new Object[] { "def", null });
    }
    testQuery("SELECT dim1, ANY_VALUE(f1) 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 FloatAnyAggregatorFactory("a0", "f1"))).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) FloatAnyAggregatorFactory(org.apache.druid.query.aggregation.any.FloatAnyAggregatorFactory) NumericTopNMetricSpec(org.apache.druid.query.topn.NumericTopNMetricSpec) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Aggregations

TopNQueryBuilder (org.apache.druid.query.topn.TopNQueryBuilder)55 Test (org.junit.Test)44 TopNQuery (org.apache.druid.query.topn.TopNQuery)25 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)22 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)16 InvertedTopNMetricSpec (org.apache.druid.query.topn.InvertedTopNMetricSpec)14 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)13 TopNQueryQueryToolChest (org.apache.druid.query.topn.TopNQueryQueryToolChest)13 Result (org.apache.druid.query.Result)12 TopNQueryConfig (org.apache.druid.query.topn.TopNQueryConfig)12 TopNResultValue (org.apache.druid.query.topn.TopNResultValue)11 DoubleMinAggregatorFactory (org.apache.druid.query.aggregation.DoubleMinAggregatorFactory)9 DimensionTopNMetricSpec (org.apache.druid.query.topn.DimensionTopNMetricSpec)9 NumericTopNMetricSpec (org.apache.druid.query.topn.NumericTopNMetricSpec)9 DoubleMaxAggregatorFactory (org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory)7 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)7 ByteBuffer (java.nio.ByteBuffer)5 QueryRunner (org.apache.druid.query.QueryRunner)5 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)5 HashMap (java.util.HashMap)4