diff --git a/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java b/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java index fa7bbc0b86e..8482fdd9e73 100644 --- a/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java +++ b/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java @@ -274,7 +274,10 @@ public class GroupByQueryQueryToolChest extends QueryToolChestnewArrayList(new DefaultDimensionSpec("tags", "tags"))) + .setAggregatorSpecs( + Arrays.asList( + new AggregatorFactory[] + { + new CountAggregatorFactory("count") + } + ) + ) + .build(); + + Sequence result = mergedRunner.run(query, Maps.newHashMap()); + + List expectedResults = Arrays.asList( + GroupByQueryRunnerTestHelper.createExpectedRow("1970-01-01T00:00:00.000Z", "tags", "t1", "count", 2L), + GroupByQueryRunnerTestHelper.createExpectedRow("1970-01-01T00:00:00.000Z", "tags", "t2", "count", 4L) + ); + + TestHelper.assertExpectedObjects(expectedResults, Sequences.toList(result, new ArrayList()), ""); + } + + private Segment createSegment() throws Exception + { + IncrementalIndex incrementalIndex = new OnheapIncrementalIndex( + 0, + QueryGranularity.NONE, + new AggregatorFactory[]{ + new CountAggregatorFactory("count") + }, + true, + true, + true, + 5000 + ); + + StringInputRowParser parser = new StringInputRowParser( + new CSVParseSpec( + new TimestampSpec("timestamp", "iso", null), + new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("product", "tags")), null, null), + "\t", + ImmutableList.of("timestamp", "product", "tags") + ), + "UTF-8" + ); + + String[] rows = new String[]{ + "2011-01-12T00:00:00.000Z,product_1,t1", + "2011-01-13T00:00:00.000Z,product_2,t2", + "2011-01-14T00:00:00.000Z,product_3,t2", + }; + + for (String row : rows) { + incrementalIndex.add(parser.parse(row)); + } + + closerRule.closeLater(incrementalIndex); + + return new IncrementalIndexSegment(incrementalIndex, "test"); + } + + private GroupByQueryRunnerFactory createFactory() + { + ObjectMapper mapper = new DefaultObjectMapper(); + + Supplier configSupplier = Suppliers.ofInstance(new GroupByQueryConfig()); + StupidPool pool = new StupidPool<>( + new Supplier() + { + @Override + public ByteBuffer get() + { + return ByteBuffer.allocate(1024 * 1024); + } + }); + + QueryWatcher noopQueryWatcher = new QueryWatcher() + { + @Override + public void registerQuery(Query query, ListenableFuture future) + { + + } + }; + + GroupByQueryEngine engine = new GroupByQueryEngine(configSupplier, pool); + GroupByQueryQueryToolChest toolchest = new GroupByQueryQueryToolChest( + configSupplier, mapper, engine, pool, + QueryRunnerTestHelper.NoopIntervalChunkingQueryRunnerDecorator() + ); + return new GroupByQueryRunnerFactory( + engine, + noopQueryWatcher, + configSupplier, + toolchest, + pool + ); + } +}