diff --git a/processing/src/main/java/io/druid/query/topn/BaseTopNAlgorithm.java b/processing/src/main/java/io/druid/query/topn/BaseTopNAlgorithm.java index 47093cea8a5..0c32d8db676 100644 --- a/processing/src/main/java/io/druid/query/topn/BaseTopNAlgorithm.java +++ b/processing/src/main/java/io/druid/query/topn/BaseTopNAlgorithm.java @@ -78,8 +78,6 @@ public abstract class BaseTopNAlgorithmof("billy", "hi") + ) + ); + index.add( + new MapBasedInputRow( + t.minus(1).getMillis(), + Lists.newArrayList("sally"), + ImmutableMap.of("sally", "bo") + ) + ); + + IncrementalIndexStorageAdapter adapter = new IncrementalIndexStorageAdapter(index); + Iterable cursorIterable = adapter.makeCursors(new SelectorFilter("sally", "bo"), + interval, + QueryGranularity.NONE); + Cursor cursor = cursorIterable.iterator().next(); + DimensionSelector dimSelector; + + dimSelector = cursor.makeDimensionSelector("sally"); + Assert.assertEquals("bo", dimSelector.lookupName(dimSelector.getRow().get(0))); + + index.add( + new MapBasedInputRow( + t.minus(1).getMillis(), + Lists.newArrayList("sally"), + ImmutableMap.of("sally", "ah") + ) + ); + + // Cursor reset should not be affected by out of order values + cursor.reset(); + + dimSelector = cursor.makeDimensionSelector("sally"); + Assert.assertEquals("bo", dimSelector.lookupName(dimSelector.getRow().get(0))); + } + + @Test + public void testSingleValueTopN() + { + IncrementalIndex index = new IncrementalIndex( + 0, QueryGranularity.MINUTE, new AggregatorFactory[]{new CountAggregatorFactory("cnt")} + ); + + DateTime t = DateTime.now(); + index.add( + new MapBasedInputRow( + t.minus(1).getMillis(), + Lists.newArrayList("sally"), + ImmutableMap.of("sally", "bo") + ) + ); + + TopNQueryEngine engine = new TopNQueryEngine( + new StupidPool( + new Supplier() + { + @Override + public ByteBuffer get() + { + return ByteBuffer.allocate(50000); + } + } + ) + ); + + final Iterable> results = engine.query( + new TopNQueryBuilder().dataSource("test") + .granularity(QueryGranularity.ALL) + .intervals(Lists.newArrayList(new Interval(0, new DateTime().getMillis()))) + .dimension("sally") + .metric("cnt") + .threshold(10) + .aggregators( + Lists.newArrayList( + new LongSumAggregatorFactory( + "cnt", + "cnt" + ) + ) + ) + .build(), + new IncrementalIndexStorageAdapter(index) + ); + + Assert.assertEquals(1, Iterables.size(results)); + Assert.assertEquals(1, results.iterator().next().getValue().getValue().size()); + } + + @Test + public void testFilterByNull() throws Exception + { + IncrementalIndex index = new IncrementalIndex( 0, QueryGranularity.MINUTE, new AggregatorFactory[]{new CountAggregatorFactory("cnt")} );