use of org.apache.druid.query.topn.TopNQueryBuilder in project druid by druid-io.
the class CachingQueryRunnerTest method testNullStrategy.
@Test
public void testNullStrategy() {
Query query = new TopNQueryBuilder().dataSource("ds").dimension("top_dim").metric("imps").threshold(3).intervals("2011-01-05/2011-01-10").aggregators(AGGS).granularity(Granularities.ALL).build();
QueryToolChest toolchest = EasyMock.mock(QueryToolChest.class);
Cache cache = EasyMock.mock(Cache.class);
EasyMock.expect(toolchest.getCacheStrategy(query)).andReturn(null);
EasyMock.replay(cache, toolchest);
CachingQueryRunner queryRunner = makeCachingQueryRunner(new byte[0], cache, toolchest, Sequences.empty());
Assert.assertFalse(queryRunner.canPopulateCache(query, null));
Assert.assertFalse(queryRunner.canUseCache(query, null));
queryRunner.run(QueryPlus.wrap(query));
EasyMock.verifyUnexpectedCalls(cache);
}
use of org.apache.druid.query.topn.TopNQueryBuilder in project druid by druid-io.
the class IncrementalIndexStorageAdapterTest method testSingleValueTopN.
@Test
public void testSingleValueTopN() throws IOException {
IncrementalIndex index = indexCreator.createIndex();
DateTime t = DateTimes.nowUtc();
index.add(new MapBasedInputRow(t.minus(1).getMillis(), Collections.singletonList("sally"), ImmutableMap.of("sally", "bo")));
try (CloseableStupidPool<ByteBuffer> pool = new CloseableStupidPool<>("TopNQueryEngine-bufferPool", () -> ByteBuffer.allocate(50000))) {
TopNQueryEngine engine = new TopNQueryEngine(pool);
final Iterable<Result<TopNResultValue>> results = engine.query(new TopNQueryBuilder().dataSource("test").granularity(Granularities.ALL).intervals(Collections.singletonList(new Interval(DateTimes.EPOCH, DateTimes.nowUtc()))).dimension("sally").metric("cnt").threshold(10).aggregators(new LongSumAggregatorFactory("cnt", "cnt")).build(), new IncrementalIndexStorageAdapter(index), null).toList();
Assert.assertEquals(1, Iterables.size(results));
Assert.assertEquals(1, results.iterator().next().getValue().getValue().size());
}
}
use of org.apache.druid.query.topn.TopNQueryBuilder in project druid by druid-io.
the class ClientQuerySegmentWalkerTest method testTopNOnArraysStrings.
@Test
public void testTopNOnArraysStrings() {
final TopNQuery query = (TopNQuery) new TopNQueryBuilder().dataSource(ARRAY).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);
// 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<STRING>]");
testQuery(query, ImmutableList.of(ExpectedQuery.cluster(query)), ImmutableList.of());
}
use of org.apache.druid.query.topn.TopNQueryBuilder 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.TopNQueryBuilder 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());
}
Aggregations