grouping sets: add tests, fix bug

This commit is contained in:
MaxTheHuman 2021-05-27 22:50:35 +03:00 committed by Dmitry Novik
parent 5978233695
commit 233471de5c
3 changed files with 33 additions and 0 deletions

View File

@ -969,6 +969,9 @@ void InterpreterSelectQuery::executeImpl(QueryPlan & query_plan, std::optional<P
options.to_stage > QueryProcessingStage::WithMergeableState &&
!query.group_by_with_totals && !query.group_by_with_rollup && !query.group_by_with_cube;
if (query.group_by_with_grouping_sets && query.group_by_with_totals)
throw Exception("WITH TOTALS and GROUPING SETS are not supported together", ErrorCodes::NOT_IMPLEMENTED);
if (query_info.projection && query_info.projection->desc->type == ProjectionDescription::Type::Aggregate)
{
query_info.projection->aggregate_overflow_row = aggregate_overflow_row;

View File

@ -0,0 +1,8 @@
1 40 4
2 80 4
a 0 70 4
b 0 50 4
1 40 4
2 80 4
a 0 70 4
b 0 50 4

View File

@ -0,0 +1,22 @@
DROP TABLE IF EXISTS grouping_sets;
CREATE TABLE grouping_sets(a String, b Int32, s Int32) ENGINE = Memory;
INSERT INTO grouping_sets VALUES ('a', 1, 10), ('a', 1, 15), ('a', 2, 20);
INSERT INTO grouping_sets VALUES ('a', 2, 25), ('b', 1, 10), ('b', 1, 5);
INSERT INTO grouping_sets VALUES ('b', 2, 20), ('b', 2, 15);
SELECT a, b, sum(s), count() from grouping_sets GROUP BY GROUPING SETS(a, b) ORDER BY a, b;
-- doesn't work now
-- SELECT a, b, sum(s), count() from grouping_sets GROUP BY GROUPING SETS(a, b) WITH TOTALS ORDER BY a, b;
SELECT a, b, sum(s), count() from grouping_sets GROUP BY a, b WITH GROUPING SETS ORDER BY a, b;
-- doesn't work now
-- SELECT a, b, sum(s), count() from grouping_sets GROUP BY a, b WITH GROUPING SETS WITH TOTALS ORDER BY a, b;
-- not sure that always works
-- SET group_by_two_level_threshold = 1;
-- SELECT a, b, sum(s), count() from grouping_sets GROUP BY a, b WITH GROUPING SETS ORDER BY a, b;
DROP TABLE grouping_sets;