Fix for GroupBy with Having+Limit+Orderspec

* Inverted function arguments to compose postProcFn for GroupBy queries
    with havingspec + limitspec.
  * Replaced query.getLimitSpec() with null in GroupByQueryToolChest's
    mergeGroupByResults
  * Added unittest to verify functionality
This commit is contained in:
Maarten Rijke 2015-05-13 11:02:49 +02:00
parent ad286cc02e
commit 82da479464
3 changed files with 88 additions and 3 deletions

View File

@ -104,6 +104,7 @@ public class GroupByQuery extends BaseQuery<Row>
if (havingSpec != null) { if (havingSpec != null) {
postProcFn = Functions.compose( postProcFn = Functions.compose(
postProcFn,
new Function<Sequence<Row>, Sequence<Row>>() new Function<Sequence<Row>, Sequence<Row>>()
{ {
@Override @Override
@ -121,8 +122,7 @@ public class GroupByQuery extends BaseQuery<Row>
} }
); );
} }
}, }
postProcFn
); );
} }

View File

@ -189,7 +189,7 @@ public class GroupByQueryQueryToolChest extends QueryToolChest<Row, GroupByQuery
ImmutableList.<PostAggregator>of(), ImmutableList.<PostAggregator>of(),
// Don't do "having" clause until the end of this method. // Don't do "having" clause until the end of this method.
null, null,
query.getLimitSpec(), null,
query.getContext() query.getContext()
).withOverriddenContext( ).withOverriddenContext(
ImmutableMap.<String, Object>of( ImmutableMap.<String, Object>of(

View File

@ -1406,6 +1406,91 @@ public class GroupByQueryRunnerTest
TestHelper.assertExpectedObjects(expectedResults, mergedRunner.run(fullQuery, context), "merged"); TestHelper.assertExpectedObjects(expectedResults, mergedRunner.run(fullQuery, context), "merged");
} }
@Test
public void testGroupByWithOrderLimitHavingSpec()
{
GroupByQuery.Builder builder = GroupByQuery
.builder()
.setDataSource(QueryRunnerTestHelper.dataSource)
.setInterval("2011-01-25/2011-01-28")
.setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("quality", "alias")))
.setAggregatorSpecs(
Arrays.asList(
QueryRunnerTestHelper.rowsCount,
new DoubleSumAggregatorFactory("index", "index")
)
)
.setGranularity(QueryGranularity.ALL)
.setHavingSpec(new GreaterThanHavingSpec("index", 310L))
.setLimitSpec(
new DefaultLimitSpec(
Lists.newArrayList(
new OrderByColumnSpec(
"index",
OrderByColumnSpec.Direction.ASCENDING
)
),
5
)
);
List<Row> expectedResults = Arrays.asList(
GroupByQueryRunnerTestHelper.createExpectedRow(
"2011-01-25",
"alias",
"business",
"rows",
3L,
"index",
312.38165283203125
),
GroupByQueryRunnerTestHelper.createExpectedRow(
"2011-01-25",
"alias",
"news",
"rows",
3L,
"index",
312.7834167480469
),
GroupByQueryRunnerTestHelper.createExpectedRow(
"2011-01-25",
"alias",
"technology",
"rows",
3L,
"index",
324.6412353515625
),
GroupByQueryRunnerTestHelper.createExpectedRow(
"2011-01-25",
"alias",
"travel",
"rows",
3L,
"index",
393.36322021484375
),
GroupByQueryRunnerTestHelper.createExpectedRow(
"2011-01-25",
"alias",
"health",
"rows",
3L,
"index",
511.2996826171875
)
);
GroupByQuery fullQuery = builder.build();
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, fullQuery);
TestHelper.assertExpectedObjects(
expectedResults,
results,
""
);
}
@Test @Test
public void testPostAggHavingSpec() public void testPostAggHavingSpec()
{ {