From 24aa762c795fd998b706094e0b1edd0ab2173ff7 Mon Sep 17 00:00:00 2001 From: Charles Allen Date: Tue, 25 Aug 2015 20:45:16 -0700 Subject: [PATCH] Add test for #1632 --- .../query/groupby/GroupByQueryRunnerTest.java | 61 ++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java b/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java index 6f03974c96f..8e78b5e02b0 100644 --- a/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java +++ b/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java @@ -91,6 +91,7 @@ import org.junit.runners.Parameterized; import javax.annotation.Nullable; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; @@ -319,7 +320,6 @@ public class GroupByQueryRunnerTest } - @Test public void testGroupByWithSimpleRenameRetainMissingNonInjective() { @@ -492,7 +492,10 @@ public class GroupByQueryRunnerTest .setDimensions( Lists.newArrayList( new ExtractionDimensionSpec( - "quality", "alias", new LookupExtractionFn(new MapLookupExtractor(map), false, "MISSING", true), null + "quality", + "alias", + new LookupExtractionFn(new MapLookupExtractor(map), false, "MISSING", true), + null ) ) ) @@ -2430,6 +2433,60 @@ public class GroupByQueryRunnerTest TestHelper.assertExpectedObjects(expectedResults, results, ""); } + + @Test + public void testDifferentGroupingSubqueryWithFilter() + { + GroupByQuery subquery = GroupByQuery + .builder() + .setDataSource(QueryRunnerTestHelper.dataSource) + .setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird) + .setDimensions(Lists.newArrayList(new DefaultDimensionSpec("quality", "quality"))) + .setAggregatorSpecs( + Arrays.asList( + QueryRunnerTestHelper.rowsCount, + new LongSumAggregatorFactory("idx", "index") + ) + ) + .setGranularity(QueryRunnerTestHelper.dayGran) + .build(); + + GroupByQuery query = GroupByQuery + .builder() + .setDataSource(subquery) + .setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird) + .setAggregatorSpecs( + Arrays.asList( + new DoubleMaxAggregatorFactory("idx", "idx") + ) + ) + .setDimFilter( + new OrDimFilter( + Lists.newArrayList( + new SelectorDimFilter("quality", "automotive"), + new SelectorDimFilter("quality", "premium"), + new SelectorDimFilter("quality", "mezzanine"), + new SelectorDimFilter("quality", "business"), + new SelectorDimFilter("quality", "entertainment"), + new SelectorDimFilter("quality", "health"), + new SelectorDimFilter("quality", "news"), + new SelectorDimFilter("quality", "technology"), + new SelectorDimFilter("quality", "travel") + ) + ) + ) + .setGranularity(QueryRunnerTestHelper.dayGran) + .build(); + + List expectedResults = Arrays.asList( + GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "idx", 2900.0), + GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "idx", 2505.0) + ); + + Iterable results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query); + TestHelper.assertExpectedObjects(expectedResults, results, ""); + } + @Test public void testDifferentIntervalSubquery() {