From a2ba5b618399804586cb57e3872b28ed81910166 Mon Sep 17 00:00:00 2001 From: vkavuluri Date: Wed, 15 Apr 2015 06:31:10 -0700 Subject: [PATCH] Unit test to surface bug with limit-spec order by over specific query intervals --- .../query/groupby/GroupByQueryRunnerTest.java | 60 +++++++++++++++++-- 1 file changed, 55 insertions(+), 5 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 da31afa0dde..770c2d9de3b 100644 --- a/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java +++ b/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java @@ -89,11 +89,7 @@ import org.junit.runners.Parameterized; import javax.annotation.Nullable; import java.io.IOException; import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -1206,6 +1202,60 @@ public class GroupByQueryRunnerTest TestHelper.assertExpectedObjects(expectedResults, results, "order-limit"); } + @Test + public void testGroupByWithOrderLimit5() + { + GroupByQuery query = new GroupByQuery.Builder() + .setDataSource(QueryRunnerTestHelper.dataSource) + .setGranularity(QueryRunnerTestHelper.dayGran) + .setDimensions( + Arrays.asList( + new DefaultDimensionSpec( + QueryRunnerTestHelper.marketDimension, + QueryRunnerTestHelper.marketDimension + ) + ) + ) + .setInterval(QueryRunnerTestHelper.firstToThird) + .setLimitSpec( + new DefaultLimitSpec( + Lists.newArrayList( + new OrderByColumnSpec( + "rows", + OrderByColumnSpec.Direction.DESCENDING + ) + ), 2 + ) + ) + .setAggregatorSpecs( + Lists.newArrayList( + QueryRunnerTestHelper.rowsCount + ) + ) + .build(); + + List expectedResults = Arrays.asList( + GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01T00:00:00.000Z", "market", "spot", "rows", 9L), + GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02T00:00:00.000Z", "market", "spot", "rows", 9L) + ); + + Iterable results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query); + Iterator resultsIter = results.iterator(); + Iterator expectedResultsIter = expectedResults.iterator(); + + final Object next1 = resultsIter.next(); + Object expectedNext1 = expectedResultsIter.next(); + Assert.assertEquals("order-limit", expectedNext1, next1); + + final Object next2 = resultsIter.next(); + Object expectedNext2 = expectedResultsIter.next(); + Assert.assertNotEquals("order-limit", expectedNext2, next2); + + Row incorrectResultRow = GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01T00:00:00.000Z", "market", "upfront", "rows", 2L); + Assert.assertEquals("order-limit", incorrectResultRow, next2); + + } + @Test public void testPostAggMergedHavingSpec() {