Fix distributed grouping sets with nulls

This commit is contained in:
Dmitry Novik 2022-07-07 16:40:35 +00:00
parent 614ce26ee7
commit 24243c51be
3 changed files with 218 additions and 2 deletions

View File

@ -786,8 +786,16 @@ Block InterpreterSelectQuery::getSampleBlockImpl()
if (analysis_result.use_grouping_set_key)
res.insert({ nullptr, std::make_shared<DataTypeUInt64>(), "__grouping_set" });
for (const auto & key : query_analyzer->aggregationKeys())
res.insert({nullptr, header.getByName(key.name).type, key.name});
if (context->getSettingsRef().group_by_use_nulls)
{
for (const auto & key : query_analyzer->aggregationKeys())
res.insert({nullptr, makeNullable(header.getByName(key.name).type), key.name});
}
else
{
for (const auto & key : query_analyzer->aggregationKeys())
res.insert({nullptr, header.getByName(key.name).type, key.name});
}
for (const auto & aggregate : query_analyzer->aggregates())
{

View File

@ -0,0 +1,157 @@
-- { echoOn }
SELECT number, number % 2, sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY ROLLUP(number, number % 2)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls=1;
0 0 0
0 \N 0
1 1 2
1 \N 2
2 0 4
2 \N 4
3 1 6
3 \N 6
4 0 8
4 \N 8
5 1 10
5 \N 10
6 0 12
6 \N 12
7 1 14
7 \N 14
8 0 16
8 \N 16
9 1 18
9 \N 18
\N \N 90
SELECT number, number % 2, sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY ROLLUP(number, number % 2)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls=0;
0 0 0
0 0 0
0 0 90
1 0 2
1 1 2
2 0 4
2 0 4
3 0 6
3 1 6
4 0 8
4 0 8
5 0 10
5 1 10
6 0 12
6 0 12
7 0 14
7 1 14
8 0 16
8 0 16
9 0 18
9 1 18
SELECT number, number % 2, sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY CUBE(number, number % 2)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls=1;
0 0 0
0 \N 0
1 1 2
1 \N 2
2 0 4
2 \N 4
3 1 6
3 \N 6
4 0 8
4 \N 8
5 1 10
5 \N 10
6 0 12
6 \N 12
7 1 14
7 \N 14
8 0 16
8 \N 16
9 1 18
9 \N 18
\N 0 40
\N 1 50
\N \N 90
SELECT number, number % 2, sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY CUBE(number, number % 2)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls=0;
0 0 0
0 0 0
0 0 40
0 0 90
0 1 50
1 0 2
1 1 2
2 0 4
2 0 4
3 0 6
3 1 6
4 0 8
4 0 8
5 0 10
5 1 10
6 0 12
6 0 12
7 0 14
7 1 14
8 0 16
8 0 16
9 0 18
9 1 18
SELECT
number,
number % 2,
sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY
GROUPING SETS (
(number),
(number % 2)
)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls = 1;
0 \N 0
1 \N 2
2 \N 4
3 \N 6
4 \N 8
5 \N 10
6 \N 12
7 \N 14
8 \N 16
9 \N 18
\N 0 40
\N 1 50
SELECT
number,
number % 2,
sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY
GROUPING SETS (
(number),
(number % 2)
)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls = 0;
0 0 0
0 0 40
0 1 50
1 0 2
2 0 4
3 0 6
4 0 8
5 0 10
6 0 12
7 0 14
8 0 16
9 0 18

View File

@ -0,0 +1,51 @@
-- { echoOn }
SELECT number, number % 2, sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY ROLLUP(number, number % 2)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls=1;
SELECT number, number % 2, sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY ROLLUP(number, number % 2)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls=0;
SELECT number, number % 2, sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY CUBE(number, number % 2)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls=1;
SELECT number, number % 2, sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY CUBE(number, number % 2)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls=0;
SELECT
number,
number % 2,
sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY
GROUPING SETS (
(number),
(number % 2)
)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls = 1;
SELECT
number,
number % 2,
sum(number) AS val
FROM remote('127.0.0.{2,3}', numbers(10))
GROUP BY
GROUPING SETS (
(number),
(number % 2)
)
ORDER BY (number, number % 2, val)
SETTINGS group_by_use_nulls = 0;