Search in sources :

Example 31 with TopNQuery

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

the class QuerySchedulerTest method testHiLoLo.

@Test
public void testHiLoLo() throws ExecutionException, InterruptedException {
    TopNQuery report = makeReportQuery();
    ListenableFuture<?> future = executorService.submit(() -> {
        try {
            Query<?> scheduledReport = scheduler.prioritizeAndLaneQuery(QueryPlus.wrap(report), ImmutableSet.of());
            Assert.assertNotNull(scheduledReport);
            Assert.assertEquals(HiLoQueryLaningStrategy.LOW, QueryContexts.getLane(scheduledReport));
            Sequence<Integer> underlyingSequence = makeSequence(10);
            underlyingSequence = Sequences.wrap(underlyingSequence, new SequenceWrapper() {

                @Override
                public void before() {
                    Assert.assertEquals(4, scheduler.getTotalAvailableCapacity());
                    Assert.assertEquals(1, scheduler.getLaneAvailableCapacity(HiLoQueryLaningStrategy.LOW));
                }
            });
            Sequence<Integer> results = scheduler.run(scheduledReport, underlyingSequence);
            int rowCount = consumeAndCloseSequence(results);
            Assert.assertEquals(10, rowCount);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    });
    future.get();
    assertHiLoHasAllCapacity(TEST_HI_CAPACITY, TEST_LO_CAPACITY);
    Assert.assertEquals(QueryScheduler.UNAVAILABLE, scheduler.getLaneAvailableCapacity("non-existent"));
}
Also used : SequenceWrapper(org.apache.druid.java.util.common.guava.SequenceWrapper) TopNQuery(org.apache.druid.query.topn.TopNQuery) IOException(java.io.IOException) Test(org.junit.Test)

Example 32 with TopNQuery

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

the class QuerySchedulerTest method testHiLoHi.

@Test
public void testHiLoHi() throws ExecutionException, InterruptedException {
    TopNQuery interactive = makeInteractiveQuery();
    ListenableFuture<?> future = executorService.submit(() -> {
        try {
            Query<?> scheduled = scheduler.prioritizeAndLaneQuery(QueryPlus.wrap(interactive), ImmutableSet.of());
            Assert.assertNotNull(scheduled);
            Sequence<Integer> underlyingSequence = makeSequence(10);
            underlyingSequence = Sequences.wrap(underlyingSequence, new SequenceWrapper() {

                @Override
                public void before() {
                    Assert.assertEquals(4, scheduler.getTotalAvailableCapacity());
                    Assert.assertEquals(2, scheduler.getLaneAvailableCapacity(HiLoQueryLaningStrategy.LOW));
                }
            });
            Sequence<Integer> results = scheduler.run(scheduled, underlyingSequence);
            int rowCount = consumeAndCloseSequence(results);
            Assert.assertEquals(10, rowCount);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    });
    future.get();
    Assert.assertEquals(TEST_HI_CAPACITY, scheduler.getTotalAvailableCapacity());
    Assert.assertEquals(QueryScheduler.UNAVAILABLE, scheduler.getLaneAvailableCapacity("non-existent"));
}
Also used : SequenceWrapper(org.apache.druid.java.util.common.guava.SequenceWrapper) TopNQuery(org.apache.druid.query.topn.TopNQuery) IOException(java.io.IOException) Test(org.junit.Test)

Example 33 with TopNQuery

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

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

use of org.apache.druid.query.topn.TopNQuery 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)

Aggregations

TopNQuery (org.apache.druid.query.topn.TopNQuery)38 Test (org.junit.Test)28 TopNQueryBuilder (org.apache.druid.query.topn.TopNQueryBuilder)25 Result (org.apache.druid.query.Result)10 TopNResultValue (org.apache.druid.query.topn.TopNResultValue)10 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)9 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)9 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)8 QueryRunner (org.apache.druid.query.QueryRunner)6 DoubleMaxAggregatorFactory (org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory)6 DoubleMinAggregatorFactory (org.apache.druid.query.aggregation.DoubleMinAggregatorFactory)6 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)6 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)6 TopNQueryConfig (org.apache.druid.query.topn.TopNQueryConfig)6 TopNQueryQueryToolChest (org.apache.druid.query.topn.TopNQueryQueryToolChest)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)5 TableDataSource (org.apache.druid.query.TableDataSource)5 ImmutableMap (com.google.common.collect.ImmutableMap)4