use of org.apache.druid.query.topn.TopNQuery in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testTopNOnArraysUnknownStrings.
@Test
public void testTopNOnArraysUnknownStrings() {
final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(ARRAY_UNKNOWN).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("as")).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 testTopNOnArraysUnknownLongs.
@Test
public void testTopNOnArraysUnknownLongs() {
final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(ARRAY_UNKNOWN).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);
// '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", 6L }, new Object[] { 946684800000L, "8", 4L }, new Object[] { 946684800000L, "2", 3L }, new Object[] { 946684800000L, "3", 3L }, new Object[] { 946684800000L, "6", 3L }, new Object[] { 946684800000L, "1", 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 testTopNScanMultiValue.
@Test
public void testTopNScanMultiValue() {
ScanQuery subquery = new Druids.ScanQueryBuilder().dataSource(MULTI).columns("s", "n").intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.ETERNITY))).legacy(false).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).build();
final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(new QueryDataSource(subquery)).granularity(Granularities.ALL).intervals(Intervals.ONLY_ETERNITY).dimension(DefaultDimensionSpec.of("s")).metric("sum_n").threshold(100).aggregators(new LongSumAggregatorFactory("sum_n", "n")).build().withId(DUMMY_QUERY_ID);
testQuery(query, // GroupBy handles its own subqueries; only the inner one will go to the cluster.
ImmutableList.of(ExpectedQuery.cluster(subquery.withId(DUMMY_QUERY_ID).withSubQueryId("1.1")), ExpectedQuery.local(query.withDataSource(InlineDataSource.fromIterable(ImmutableList.of(new Object[] { ImmutableList.of("a", "b"), 1 }, new Object[] { ImmutableList.of("a", "c"), 2 }, new Object[] { ImmutableList.of("b"), 3 }, new Object[] { ImmutableList.of("c"), 4 }), RowSignature.builder().add("s", null).add("n", null).build())))), ImmutableList.of(new Object[] { Intervals.ETERNITY.getStartMillis(), "c", 6L }, new Object[] { Intervals.ETERNITY.getStartMillis(), "b", 4L }, new Object[] { Intervals.ETERNITY.getStartMillis(), "a", 3L }));
Assert.assertEquals(2, scheduler.getTotalRun().get());
Assert.assertEquals(1, scheduler.getTotalPrioritizedAndLaned().get());
Assert.assertEquals(2, scheduler.getTotalAcquired().get());
Assert.assertEquals(2, scheduler.getTotalReleased().get());
}
use of org.apache.druid.query.topn.TopNQuery in project druid by druid-io.
the class DummyStringVirtualColumnTest method testTopN.
private void testTopN(List<Segment> segments, boolean enableRowBasedMethods, boolean enableColumnBasedMethods) {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(Granularities.ALL).dimension(VSTRING_DIM).metric(COUNT).threshold(1).aggregators(new CountAggregatorFactory(COUNT)).virtualColumns(new DummyStringVirtualColumn(QueryRunnerTestHelper.MARKET_DIMENSION, VSTRING_DIM, enableRowBasedMethods, enableColumnBasedMethods, false, true)).intervals("2000/2030").build();
List rows = topNTestHelper.runQueryOnSegmentsObjs(segments, query).toList();
List<Result<TopNResultValue>> expectedRows = Collections.singletonList(new Result<>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Collections.<Map<String, Object>>singletonList(ImmutableMap.<String, Object>builder().put(COUNT, 1674L).put(VSTRING_DIM, "spot").build()))));
TestHelper.assertExpectedResults(expectedRows, (List<Result<TopNResultValue>>) rows, "failed");
}
use of org.apache.druid.query.topn.TopNQuery in project druid by druid-io.
the class QuerySchedulerTest method testHiLoReleaseLaneWhenSequenceExplodes.
@Test
public void testHiLoReleaseLaneWhenSequenceExplodes() throws Exception {
expected.expectMessage("exploded");
expected.expect(ExecutionException.class);
TopNQuery interactive = makeInteractiveQuery();
ListenableFuture<?> future = executorService.submit(() -> {
try {
Query<?> scheduled = scheduler.prioritizeAndLaneQuery(QueryPlus.wrap(interactive), ImmutableSet.of());
Assert.assertNotNull(scheduled);
Sequence<Integer> underlyingSequence = makeExplodingSequence(10);
underlyingSequence = Sequences.wrap(underlyingSequence, new SequenceWrapper() {
@Override
public void before() {
Assert.assertEquals(4, scheduler.getTotalAvailableCapacity());
}
});
Sequence<Integer> results = scheduler.run(scheduled, underlyingSequence);
consumeAndCloseSequence(results);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
future.get();
}
Aggregations