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"));
}
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"));
}
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());
}
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());
}
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());
}
Aggregations