should be it
This commit is contained in:
190
external/duckdb/test/sql/aggregate/grouping_sets/cube.test
vendored
Normal file
190
external/duckdb/test/sql/aggregate/grouping_sets/cube.test
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
# name: test/sql/aggregate/grouping_sets/cube.test
|
||||
# description: Test CUBE
|
||||
# group: [grouping_sets]
|
||||
|
||||
statement ok
|
||||
SET default_null_order='nulls_first';
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
create table students (course VARCHAR, type VARCHAR, highest_grade INTEGER);
|
||||
|
||||
statement ok
|
||||
insert into students
|
||||
(course, type, highest_grade)
|
||||
values
|
||||
('CS', 'Bachelor', 8),
|
||||
('CS', 'Bachelor', 8),
|
||||
('CS', 'PhD', 10),
|
||||
('Math', 'Masters', NULL),
|
||||
('CS', NULL, 7),
|
||||
('CS', NULL, 7),
|
||||
('Math', NULL, 8);
|
||||
|
||||
query II
|
||||
select course, count(*) from students group by cube (course) order by 1, 2;
|
||||
----
|
||||
NULL 7
|
||||
CS 5
|
||||
Math 2
|
||||
|
||||
query III
|
||||
select course, type, count(*) from students group by cube (course, type) order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 3
|
||||
NULL NULL 7
|
||||
NULL Bachelor 2
|
||||
NULL Masters 1
|
||||
NULL PhD 1
|
||||
CS NULL 2
|
||||
CS NULL 5
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math NULL 2
|
||||
Math Masters 1
|
||||
|
||||
# if we have brackets in a CUBE group, it counts as one unit within the CUBE statement
|
||||
# i.e. in this case (course, type) are not cubed up
|
||||
query III
|
||||
select course, type, count(*) from students group by cube ((course, type)) order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 7
|
||||
CS NULL 2
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math Masters 1
|
||||
|
||||
# duplicate group expressions in cube
|
||||
query III
|
||||
select course, type, count(*) from students group by cube (course, type, course) order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 3
|
||||
NULL NULL 7
|
||||
NULL Bachelor 2
|
||||
NULL Masters 1
|
||||
NULL PhD 1
|
||||
CS NULL 2
|
||||
CS NULL 2
|
||||
CS NULL 2
|
||||
CS NULL 5
|
||||
CS NULL 5
|
||||
CS NULL 5
|
||||
CS Bachelor 2
|
||||
CS Bachelor 2
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
CS PhD 1
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math NULL 1
|
||||
Math NULL 1
|
||||
Math NULL 2
|
||||
Math NULL 2
|
||||
Math NULL 2
|
||||
Math Masters 1
|
||||
Math Masters 1
|
||||
Math Masters 1
|
||||
|
||||
query IIII
|
||||
select course, type, highest_grade, count(*) from students group by cube (course, type, highest_grade) order by 1, 2, 3, 4;
|
||||
----
|
||||
NULL NULL NULL 1
|
||||
NULL NULL NULL 3
|
||||
NULL NULL NULL 7
|
||||
NULL NULL 7 2
|
||||
NULL NULL 7 2
|
||||
NULL NULL 8 1
|
||||
NULL NULL 8 3
|
||||
NULL NULL 10 1
|
||||
NULL Bachelor NULL 2
|
||||
NULL Bachelor 8 2
|
||||
NULL Masters NULL 1
|
||||
NULL Masters NULL 1
|
||||
NULL PhD NULL 1
|
||||
NULL PhD 10 1
|
||||
CS NULL NULL 2
|
||||
CS NULL NULL 5
|
||||
CS NULL 7 2
|
||||
CS NULL 7 2
|
||||
CS NULL 8 2
|
||||
CS NULL 10 1
|
||||
CS Bachelor NULL 2
|
||||
CS Bachelor 8 2
|
||||
CS PhD NULL 1
|
||||
CS PhD 10 1
|
||||
Math NULL NULL 1
|
||||
Math NULL NULL 1
|
||||
Math NULL NULL 2
|
||||
Math NULL 8 1
|
||||
Math NULL 8 1
|
||||
Math Masters NULL 1
|
||||
Math Masters NULL 1
|
||||
|
||||
# multiple cubes ups causes a cross product of them
|
||||
query III
|
||||
select course, type, count(*) from students group by cube (course), cube (type) order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 3
|
||||
NULL NULL 7
|
||||
NULL Bachelor 2
|
||||
NULL Masters 1
|
||||
NULL PhD 1
|
||||
CS NULL 2
|
||||
CS NULL 5
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math NULL 2
|
||||
Math Masters 1
|
||||
|
||||
query III
|
||||
select course as crs, type, count(*) from students group by cube (crs), (), type order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 3
|
||||
NULL Bachelor 2
|
||||
NULL Masters 1
|
||||
NULL PhD 1
|
||||
CS NULL 2
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math Masters 1
|
||||
|
||||
# we can also use cube within a grouping set
|
||||
query III
|
||||
select course as crs, type as tp, count(*) from students group by grouping sets (cube (crs)), (), tp order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 3
|
||||
NULL Bachelor 2
|
||||
NULL Masters 1
|
||||
NULL PhD 1
|
||||
CS NULL 2
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math Masters 1
|
||||
|
||||
statement error
|
||||
select course, count(*) from students group by cube () order by 1, 2;
|
||||
----
|
||||
|
||||
statement error
|
||||
select course, count(*) from students group by cube (cube (course)) order by 1, 2;
|
||||
----
|
||||
|
||||
statement error
|
||||
select course, count(*) from students group by cube (grouping_sets (course)) order by 1, 2;
|
||||
----
|
||||
|
||||
# cube exceeds maximum grouping set
|
||||
statement error
|
||||
select course, type, count(*) from students group by cube (course, type, course, type, course, type, course, type, course, type, course, type, (course, type), (course, type), course, type) order by 1, 2, 3;
|
||||
----
|
||||
|
||||
statement error
|
||||
select course, type, count(*) from students group by cube (course, type, course, type, course), cube(type, course, type, course), cube(type, course, type, (course, type), (course, type), course, type) order by 1, 2, 3;
|
||||
----
|
||||
225
external/duckdb/test/sql/aggregate/grouping_sets/grouping.test
vendored
Normal file
225
external/duckdb/test/sql/aggregate/grouping_sets/grouping.test
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
# name: test/sql/aggregate/grouping_sets/grouping.test
|
||||
# description: Test GROUPING statement
|
||||
# group: [grouping_sets]
|
||||
|
||||
statement ok
|
||||
SET default_null_order='nulls_first';
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
create table students (course VARCHAR, type VARCHAR);
|
||||
|
||||
statement ok
|
||||
insert into students
|
||||
(course, type)
|
||||
values
|
||||
('CS', 'Bachelor'),
|
||||
('CS', 'Bachelor'),
|
||||
('CS', 'PhD'),
|
||||
('Math', 'Masters'),
|
||||
('CS', NULL),
|
||||
('CS', NULL),
|
||||
('Math', NULL);
|
||||
|
||||
query III
|
||||
SELECT GROUPING(course), course, COUNT(*) FROM students GROUP BY course ORDER BY 1, 2, 3;
|
||||
----
|
||||
0 CS 5
|
||||
0 Math 2
|
||||
|
||||
query III
|
||||
SELECT GROUPING_ID(course), course, COUNT(*) FROM students GROUP BY course ORDER BY 1, 2, 3;
|
||||
----
|
||||
0 CS 5
|
||||
0 Math 2
|
||||
|
||||
query IIIII
|
||||
SELECT GROUPING(course), GROUPING(type), course, type, COUNT(*) FROM students GROUP BY course, type ORDER BY 1, 2, 3, 4, 5;
|
||||
----
|
||||
0 0 CS NULL 2
|
||||
0 0 CS Bachelor 2
|
||||
0 0 CS PhD 1
|
||||
0 0 Math NULL 1
|
||||
0 0 Math Masters 1
|
||||
|
||||
query IIIII
|
||||
SELECT GROUPING(course), GROUPING(type), course, type, COUNT(*) FROM students GROUP BY CUBE(course, type) ORDER BY 1, 2, 3, 4, 5;
|
||||
----
|
||||
0 0 CS NULL 2
|
||||
0 0 CS Bachelor 2
|
||||
0 0 CS PhD 1
|
||||
0 0 Math NULL 1
|
||||
0 0 Math Masters 1
|
||||
0 1 CS NULL 5
|
||||
0 1 Math NULL 2
|
||||
1 0 NULL NULL 3
|
||||
1 0 NULL Bachelor 2
|
||||
1 0 NULL Masters 1
|
||||
1 0 NULL PhD 1
|
||||
1 1 NULL NULL 7
|
||||
|
||||
query IIII
|
||||
SELECT GROUPING(course, type), course, type, COUNT(*) FROM students GROUP BY CUBE(course, type) ORDER BY 1, 2, 3, 4;
|
||||
----
|
||||
0 CS NULL 2
|
||||
0 CS Bachelor 2
|
||||
0 CS PhD 1
|
||||
0 Math NULL 1
|
||||
0 Math Masters 1
|
||||
1 CS NULL 5
|
||||
1 Math NULL 2
|
||||
2 NULL NULL 3
|
||||
2 NULL Bachelor 2
|
||||
2 NULL Masters 1
|
||||
2 NULL PhD 1
|
||||
3 NULL NULL 7
|
||||
|
||||
query IIIIII
|
||||
SELECT GROUPING(course), GROUPING(type), GROUPING(course)+GROUPING(type), course, type, COUNT(*) FROM students GROUP BY CUBE(course, type) ORDER BY 1, 2, 3, 4, 5;
|
||||
----
|
||||
0 0 0 CS NULL 2
|
||||
0 0 0 CS Bachelor 2
|
||||
0 0 0 CS PhD 1
|
||||
0 0 0 Math NULL 1
|
||||
0 0 0 Math Masters 1
|
||||
0 1 1 CS NULL 5
|
||||
0 1 1 Math NULL 2
|
||||
1 0 1 NULL NULL 3
|
||||
1 0 1 NULL Bachelor 2
|
||||
1 0 1 NULL Masters 1
|
||||
1 0 1 NULL PhD 1
|
||||
1 1 2 NULL NULL 7
|
||||
|
||||
# many repeated groupings
|
||||
query IIII
|
||||
SELECT GROUPING(course, type, course, course, type, type, course), course, type, COUNT(*) FROM students GROUP BY CUBE(course, type) ORDER BY 1, 2, 3, 4;
|
||||
----
|
||||
0 CS NULL 2
|
||||
0 CS Bachelor 2
|
||||
0 CS PhD 1
|
||||
0 Math NULL 1
|
||||
0 Math Masters 1
|
||||
38 CS NULL 5
|
||||
38 Math NULL 2
|
||||
89 NULL NULL 3
|
||||
89 NULL Bachelor 2
|
||||
89 NULL Masters 1
|
||||
89 NULL PhD 1
|
||||
127 NULL NULL 7
|
||||
|
||||
# GROUPING with different table qualifications
|
||||
query IIIIII
|
||||
SELECT GROUPING(students.course), GROUPING(students.type), GROUPING(course)+GROUPING(type), course, type, COUNT(*) FROM students GROUP BY CUBE(course, type) ORDER BY 1, 2, 3, 4, 5;
|
||||
----
|
||||
0 0 0 CS NULL 2
|
||||
0 0 0 CS Bachelor 2
|
||||
0 0 0 CS PhD 1
|
||||
0 0 0 Math NULL 1
|
||||
0 0 0 Math Masters 1
|
||||
0 1 1 CS NULL 5
|
||||
0 1 1 Math NULL 2
|
||||
1 0 1 NULL NULL 3
|
||||
1 0 1 NULL Bachelor 2
|
||||
1 0 1 NULL Masters 1
|
||||
1 0 1 NULL PhD 1
|
||||
1 1 2 NULL NULL 7
|
||||
|
||||
query IIIIII
|
||||
SELECT GROUPING(course), GROUPING(type), GROUPING(course)+GROUPING(type), course, type, COUNT(*) FROM students GROUP BY CUBE(students.course, students.type) ORDER BY 1, 2, 3, 4, 5;
|
||||
----
|
||||
0 0 0 CS NULL 2
|
||||
0 0 0 CS Bachelor 2
|
||||
0 0 0 CS PhD 1
|
||||
0 0 0 Math NULL 1
|
||||
0 0 0 Math Masters 1
|
||||
0 1 1 CS NULL 5
|
||||
0 1 1 Math NULL 2
|
||||
1 0 1 NULL NULL 3
|
||||
1 0 1 NULL Bachelor 2
|
||||
1 0 1 NULL Masters 1
|
||||
1 0 1 NULL PhD 1
|
||||
1 1 2 NULL NULL 7
|
||||
|
||||
# GROUPING in HAVING clause
|
||||
query IIIII
|
||||
SELECT GROUPING(course), GROUPING(type), course, type, COUNT(*) FROM students GROUP BY CUBE(course, type) HAVING GROUPING(course)=0 ORDER BY 1, 2, 3, 4, 5;
|
||||
----
|
||||
0 0 CS NULL 2
|
||||
0 0 CS Bachelor 2
|
||||
0 0 CS PhD 1
|
||||
0 0 Math NULL 1
|
||||
0 0 Math Masters 1
|
||||
0 1 CS NULL 5
|
||||
0 1 Math NULL 2
|
||||
|
||||
query IIIII
|
||||
SELECT GROUPING(course), GROUPING(type), course, type, COUNT(*) FROM students GROUP BY CUBE(course, type) HAVING GROUPING(students.course)=0 ORDER BY 1, 2, 3, 4, 5;
|
||||
----
|
||||
0 0 CS NULL 2
|
||||
0 0 CS Bachelor 2
|
||||
0 0 CS PhD 1
|
||||
0 0 Math NULL 1
|
||||
0 0 Math Masters 1
|
||||
0 1 CS NULL 5
|
||||
0 1 Math NULL 2
|
||||
|
||||
# GROUPING in ORDER BY clause
|
||||
query III
|
||||
SELECT course, type, COUNT(*) FROM students GROUP BY CUBE(course, type) ORDER BY GROUPING(course), GROUPING(type), 1, 2, 3;
|
||||
----
|
||||
CS NULL 2
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math Masters 1
|
||||
CS NULL 5
|
||||
Math NULL 2
|
||||
NULL NULL 3
|
||||
NULL Bachelor 2
|
||||
NULL Masters 1
|
||||
NULL PhD 1
|
||||
NULL NULL 7
|
||||
|
||||
# test incorrect grouping usage
|
||||
statement error
|
||||
SELECT GROUPING();
|
||||
----
|
||||
Parser Error: syntax error at or near ")"
|
||||
|
||||
statement error
|
||||
SELECT GROUPING() FROM students;
|
||||
----
|
||||
Parser Error: syntax error at or near ")"
|
||||
|
||||
statement error
|
||||
SELECT GROUPING(NULL) FROM students;
|
||||
----
|
||||
<REGEX>:.*Binder Error.*statement cannot be used.*
|
||||
|
||||
statement error
|
||||
SELECT GROUPING(course) FROM students;
|
||||
----
|
||||
<REGEX>:.*Binder Error.*statement cannot be used.*
|
||||
|
||||
statement error
|
||||
SELECT GROUPING(course) FROM students GROUP BY ();
|
||||
----
|
||||
<REGEX>:.*Binder Error.*statement cannot be used.*
|
||||
|
||||
statement error
|
||||
SELECT GROUPING(type) FROM students GROUP BY course;
|
||||
----
|
||||
<REGEX>:.*Binder Error.*must be a grouping column.*
|
||||
|
||||
statement error
|
||||
SELECT GROUPING(course) FROM students WHERE GROUPING(course)=0 GROUP BY course;
|
||||
----
|
||||
<REGEX>:.*Binder Error.*not supported.*
|
||||
|
||||
# we have a limit on how many children the grouping clause can contain
|
||||
statement error
|
||||
SELECT GROUPING(course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course, course), course, type, COUNT(*) FROM students GROUP BY CUBE(course, type) ORDER BY 1, 2, 3, 4;
|
||||
----
|
||||
<REGEX>:.*Binder Error.*statement cannot have more.*
|
||||
278
external/duckdb/test/sql/aggregate/grouping_sets/grouping_sets.test
vendored
Normal file
278
external/duckdb/test/sql/aggregate/grouping_sets/grouping_sets.test
vendored
Normal file
@@ -0,0 +1,278 @@
|
||||
# name: test/sql/aggregate/grouping_sets/grouping_sets.test
|
||||
# description: Test basic grouping sets
|
||||
# group: [grouping_sets]
|
||||
|
||||
statement ok
|
||||
SET default_null_order='nulls_first';
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
create table students (course VARCHAR, type VARCHAR);
|
||||
|
||||
statement ok
|
||||
insert into students
|
||||
(course, type)
|
||||
values
|
||||
('CS', 'Bachelor'),
|
||||
('CS', 'Bachelor'),
|
||||
('CS', 'PhD'),
|
||||
('Math', 'Masters'),
|
||||
('CS', NULL),
|
||||
('CS', NULL),
|
||||
('Math', NULL);
|
||||
|
||||
query I
|
||||
select 1 from students group by ();
|
||||
----
|
||||
1
|
||||
|
||||
query I
|
||||
select count(*) from students group by ();
|
||||
----
|
||||
7
|
||||
|
||||
query III
|
||||
select course, type, count(*) from students group by course, type order by 1, 2, 3;
|
||||
----
|
||||
CS NULL 2
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math Masters 1
|
||||
|
||||
query III
|
||||
select course, type, count(*) from students group by (course, type) order by 1, 2, 3;
|
||||
----
|
||||
CS NULL 2
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math Masters 1
|
||||
|
||||
query II
|
||||
select course, count(*) from students group by (), course, () ORDER BY 1;
|
||||
----
|
||||
CS 5
|
||||
Math 2
|
||||
|
||||
# multiple grouping sets
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by grouping sets ((course), (type))
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 NULL Masters
|
||||
1 NULL PhD
|
||||
2 NULL Bachelor
|
||||
2 Math NULL
|
||||
3 NULL NULL
|
||||
5 CS NULL
|
||||
|
||||
# multiple grouping sets
|
||||
# these are combined as if they are regular GROUP BY expressions
|
||||
# i.e. the result is just GROUP BY course, type
|
||||
|
||||
# If multiple grouping items are specified in a single GROUP BY clause,
|
||||
# then the final list of grouping sets is the cross product of the individual items.
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by grouping sets (course), grouping sets(type)
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 CS PhD
|
||||
1 Math NULL
|
||||
1 Math Masters
|
||||
2 CS NULL
|
||||
2 CS Bachelor
|
||||
|
||||
# combining grouping sets with non-grouping sets
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by course, grouping sets(type)
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 CS PhD
|
||||
1 Math NULL
|
||||
1 Math Masters
|
||||
2 CS NULL
|
||||
2 CS Bachelor
|
||||
|
||||
# with multiple grouping sets...
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by course, grouping sets(type, ())
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 CS PhD
|
||||
1 Math NULL
|
||||
1 Math Masters
|
||||
2 CS NULL
|
||||
2 CS Bachelor
|
||||
2 Math NULL
|
||||
5 CS NULL
|
||||
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by grouping sets((course, type), (course))
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 CS PhD
|
||||
1 Math NULL
|
||||
1 Math Masters
|
||||
2 CS NULL
|
||||
2 CS Bachelor
|
||||
2 Math NULL
|
||||
5 CS NULL
|
||||
|
||||
# nested grouping sets
|
||||
# If one GROUPING SETS clause is nested inside another,
|
||||
# the effect is the same as if all the elements of the inner clause had been written directly in the outer clause.
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by grouping sets (grouping sets(course), grouping sets(type))
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 NULL Masters
|
||||
1 NULL PhD
|
||||
2 NULL Bachelor
|
||||
2 Math NULL
|
||||
3 NULL NULL
|
||||
5 CS NULL
|
||||
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by grouping sets (grouping sets(course, ()), grouping sets(type))
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 NULL Masters
|
||||
1 NULL PhD
|
||||
2 NULL Bachelor
|
||||
2 Math NULL
|
||||
3 NULL NULL
|
||||
5 CS NULL
|
||||
7 NULL NULL
|
||||
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by grouping sets ((course), (), (type))
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 NULL Masters
|
||||
1 NULL PhD
|
||||
2 NULL Bachelor
|
||||
2 Math NULL
|
||||
3 NULL NULL
|
||||
5 CS NULL
|
||||
7 NULL NULL
|
||||
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by grouping sets(course, ()), grouping sets(type)
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 NULL Masters
|
||||
1 NULL PhD
|
||||
1 CS PhD
|
||||
1 Math NULL
|
||||
1 Math Masters
|
||||
2 NULL Bachelor
|
||||
2 CS NULL
|
||||
2 CS Bachelor
|
||||
3 NULL NULL
|
||||
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by grouping sets(course, ()), type
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 NULL Masters
|
||||
1 NULL PhD
|
||||
1 CS PhD
|
||||
1 Math NULL
|
||||
1 Math Masters
|
||||
2 NULL Bachelor
|
||||
2 CS NULL
|
||||
2 CS Bachelor
|
||||
3 NULL NULL
|
||||
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by grouping sets((course, type), (type))
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 NULL Masters
|
||||
1 NULL PhD
|
||||
1 CS PhD
|
||||
1 Math NULL
|
||||
1 Math Masters
|
||||
2 NULL Bachelor
|
||||
2 CS NULL
|
||||
2 CS Bachelor
|
||||
3 NULL NULL
|
||||
|
||||
# references to group ids by index
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by grouping sets((2, 3), (3))
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 NULL Masters
|
||||
1 NULL PhD
|
||||
1 CS PhD
|
||||
1 Math NULL
|
||||
1 Math Masters
|
||||
2 NULL Bachelor
|
||||
2 CS NULL
|
||||
2 CS Bachelor
|
||||
3 NULL NULL
|
||||
|
||||
query III
|
||||
select count(*), course AS crs, type AS tp
|
||||
from students
|
||||
group by grouping sets((crs, tp), (tp))
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 NULL Masters
|
||||
1 NULL PhD
|
||||
1 CS PhD
|
||||
1 Math NULL
|
||||
1 Math Masters
|
||||
2 NULL Bachelor
|
||||
2 CS NULL
|
||||
2 CS Bachelor
|
||||
3 NULL NULL
|
||||
|
||||
query III
|
||||
select count(*), course, type
|
||||
from students
|
||||
group by grouping sets (grouping sets(course, ()), grouping sets(type, ()))
|
||||
order by 1, 2, 3;
|
||||
----
|
||||
1 NULL Masters
|
||||
1 NULL PhD
|
||||
2 NULL Bachelor
|
||||
2 Math NULL
|
||||
3 NULL NULL
|
||||
5 CS NULL
|
||||
7 NULL NULL
|
||||
7 NULL NULL
|
||||
|
||||
# course is not a group or aggregate column
|
||||
statement error
|
||||
select course from students group by ();
|
||||
----
|
||||
Binder Error: column "course" must appear in the GROUP BY
|
||||
49
external/duckdb/test/sql/aggregate/grouping_sets/grouping_sets_filter.test
vendored
Normal file
49
external/duckdb/test/sql/aggregate/grouping_sets/grouping_sets_filter.test
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
# name: test/sql/aggregate/grouping_sets/grouping_sets_filter.test
|
||||
# description: Test grouping sets with filter pushdown
|
||||
# group: [grouping_sets]
|
||||
|
||||
statement ok
|
||||
SET default_null_order='nulls_first';
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
create table students (course VARCHAR, type VARCHAR);
|
||||
|
||||
statement ok
|
||||
insert into students
|
||||
(course, type)
|
||||
values
|
||||
('CS', 'Bachelor'),
|
||||
('CS', 'Bachelor'),
|
||||
('CS', 'PhD'),
|
||||
('Math', 'Masters'),
|
||||
('CS', NULL),
|
||||
('CS', NULL),
|
||||
('Math', NULL);
|
||||
|
||||
query II
|
||||
SELECT course, COUNT(*) FROM students GROUP BY GROUPING SETS ((), (course)) HAVING course LIKE 'C%' ORDER BY 1, 2;
|
||||
----
|
||||
CS 5
|
||||
|
||||
query II
|
||||
SELECT course, COUNT(*) FROM students GROUP BY GROUPING SETS ((), (course)) HAVING course LIKE 'C%' OR course NOT LIKE 'C%' OR course IS NULL ORDER BY 1, 2;
|
||||
----
|
||||
NULL 7
|
||||
CS 5
|
||||
Math 2
|
||||
|
||||
# always true: random generates values between 0 and 1
|
||||
query II
|
||||
SELECT course, COUNT(*) FROM students GROUP BY GROUPING SETS ((), (course)) HAVING random()<1000 ORDER BY ALL;
|
||||
----
|
||||
NULL 7
|
||||
CS 5
|
||||
Math 2
|
||||
|
||||
# always false: random generates values between 0 and 1
|
||||
query II
|
||||
SELECT course, COUNT(*) FROM students GROUP BY GROUPING SETS ((), (course)) HAVING random()>1000;
|
||||
----
|
||||
47
external/duckdb/test/sql/aggregate/grouping_sets/issue_3730.test
vendored
Normal file
47
external/duckdb/test/sql/aggregate/grouping_sets/issue_3730.test
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
# name: test/sql/aggregate/grouping_sets/issue_3730.test
|
||||
# description: Issue #3730: Segmentation fault on GROUP BY when using ROLLUP/CUBE + COUNT DISTINCT on Parquet
|
||||
# group: [grouping_sets]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
CREATE TABLE response(
|
||||
id BIGINT,
|
||||
response VARCHAR
|
||||
);
|
||||
|
||||
statement ok
|
||||
INSERT INTO response VALUES
|
||||
(1,'yes'),
|
||||
(1,'no'),
|
||||
(1,'yes'),
|
||||
(2,'no'),
|
||||
(2,'no');
|
||||
|
||||
statement ok
|
||||
CREATE TABLE user_pq(
|
||||
id BIGINT,
|
||||
"name" VARCHAR
|
||||
);
|
||||
|
||||
statement ok
|
||||
INSERT INTO user_pq VALUES
|
||||
(1,'alice'),
|
||||
(2,'bob');
|
||||
|
||||
query III
|
||||
SELECT id, response, COUNT(DISTINCT id)
|
||||
FROM user_pq
|
||||
JOIN response USING (id)
|
||||
GROUP BY CUBE (id, response)
|
||||
ORDER BY 1 NULLS LAST, 2 NULLS LAST, 3 NULLS LAST
|
||||
----
|
||||
1 no 1
|
||||
1 yes 1
|
||||
1 NULL 1
|
||||
2 no 1
|
||||
2 NULL 1
|
||||
NULL no 2
|
||||
NULL yes 1
|
||||
NULL NULL 2
|
||||
16
external/duckdb/test/sql/aggregate/grouping_sets/large_grouping_sets.test_slow
vendored
Normal file
16
external/duckdb/test/sql/aggregate/grouping_sets/large_grouping_sets.test_slow
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# name: test/sql/aggregate/grouping_sets/large_grouping_sets.test_slow
|
||||
# description: Test GROUPING sets with many groups to trigger radix partitioning
|
||||
# group: [grouping_sets]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE integers AS SELECT i, i::VARCHAR j FROM generate_series(0, 1000000, 1) tbl(i);
|
||||
|
||||
query I
|
||||
SELECT COUNT(*) FROM (SELECT * FROM integers GROUP BY CUBE (i, j)) tbl;
|
||||
----
|
||||
3000004
|
||||
|
||||
query I
|
||||
SELECT COUNT(*) FROM (SELECT * FROM integers GROUP BY ROLLUP (i, j)) tbl;
|
||||
----
|
||||
2000003
|
||||
13
external/duckdb/test/sql/aggregate/grouping_sets/multiple_empty_grouping_sets.test
vendored
Normal file
13
external/duckdb/test/sql/aggregate/grouping_sets/multiple_empty_grouping_sets.test
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# name: test/sql/aggregate/grouping_sets/multiple_empty_grouping_sets.test
|
||||
# description: Issue #7219 - Wrong GROUPING SETS implementation when using 2 empty grouping sets
|
||||
# group: [grouping_sets]
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
query I
|
||||
select count(*)
|
||||
group by grouping sets ((), ())
|
||||
----
|
||||
1
|
||||
1
|
||||
144
external/duckdb/test/sql/aggregate/grouping_sets/rollup.test
vendored
Normal file
144
external/duckdb/test/sql/aggregate/grouping_sets/rollup.test
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
# name: test/sql/aggregate/grouping_sets/rollup.test
|
||||
# description: Test ROLLUP
|
||||
# group: [grouping_sets]
|
||||
|
||||
statement ok
|
||||
SET default_null_order='nulls_first';
|
||||
|
||||
statement ok
|
||||
PRAGMA enable_verification
|
||||
|
||||
statement ok
|
||||
create table students (course VARCHAR, type VARCHAR);
|
||||
|
||||
statement ok
|
||||
insert into students
|
||||
(course, type)
|
||||
values
|
||||
('CS', 'Bachelor'),
|
||||
('CS', 'Bachelor'),
|
||||
('CS', 'PhD'),
|
||||
('Math', 'Masters'),
|
||||
('CS', NULL),
|
||||
('CS', NULL),
|
||||
('Math', NULL);
|
||||
|
||||
query II
|
||||
select course, count(*) from students group by rollup (course) order by 1, 2;
|
||||
----
|
||||
NULL 7
|
||||
CS 5
|
||||
Math 2
|
||||
|
||||
query III
|
||||
select course, type, count(*) from students group by rollup (course, type) order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 7
|
||||
CS NULL 2
|
||||
CS NULL 5
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math NULL 2
|
||||
Math Masters 1
|
||||
|
||||
# if we have brackets in a ROLLUP group, it counts as one unit within the ROLLUP statement
|
||||
# i.e. in this case (course, type) are not individually rolled up
|
||||
query III
|
||||
select course, type, count(*) from students group by rollup ((course, type)) order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 7
|
||||
CS NULL 2
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math Masters 1
|
||||
|
||||
# duplicate group expressions in rollup
|
||||
query III
|
||||
select course, type, count(*) from students group by rollup (course, type, course) order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 7
|
||||
CS NULL 2
|
||||
CS NULL 2
|
||||
CS NULL 5
|
||||
CS Bachelor 2
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math NULL 1
|
||||
Math NULL 2
|
||||
Math Masters 1
|
||||
Math Masters 1
|
||||
|
||||
query III
|
||||
select course, type, count(*) from students group by grouping sets ((course, type), (course), ()) order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 7
|
||||
CS NULL 2
|
||||
CS NULL 5
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math NULL 2
|
||||
Math Masters 1
|
||||
|
||||
# multiple roll ups causes a cross product of them
|
||||
query III
|
||||
select course, type, count(*) from students group by rollup (course), rollup (type) order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 3
|
||||
NULL NULL 7
|
||||
NULL Bachelor 2
|
||||
NULL Masters 1
|
||||
NULL PhD 1
|
||||
CS NULL 2
|
||||
CS NULL 5
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math NULL 2
|
||||
Math Masters 1
|
||||
|
||||
query III
|
||||
select course as crs, type, count(*) from students group by rollup (crs), (), type order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 3
|
||||
NULL Bachelor 2
|
||||
NULL Masters 1
|
||||
NULL PhD 1
|
||||
CS NULL 2
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math Masters 1
|
||||
|
||||
# we can also use rollup within a grouping set
|
||||
query III
|
||||
select course as crs, type as tp, count(*) from students group by grouping sets (rollup (crs)), (), tp order by 1, 2, 3;
|
||||
----
|
||||
NULL NULL 3
|
||||
NULL Bachelor 2
|
||||
NULL Masters 1
|
||||
NULL PhD 1
|
||||
CS NULL 2
|
||||
CS Bachelor 2
|
||||
CS PhD 1
|
||||
Math NULL 1
|
||||
Math Masters 1
|
||||
|
||||
statement error
|
||||
select course, count(*) from students group by rollup () order by 1, 2;
|
||||
----
|
||||
Parser Error: syntax error at or near ")"
|
||||
|
||||
statement error
|
||||
select course, count(*) from students group by rollup (rollup (course)) order by 1, 2;
|
||||
----
|
||||
Catalog Error: Scalar Function with name rollup does not exist
|
||||
|
||||
statement error
|
||||
select course, count(*) from students group by rollup (grouping_sets (course)) order by 1, 2;
|
||||
----
|
||||
Catalog Error: Scalar Function with name grouping_sets does not exist
|
||||
Reference in New Issue
Block a user