mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Ensure ROLLUP and CUBE respect HAVING (no change to TOTALS)
This commit is contained in:
parent
af31ff24b9
commit
fcde47b45e
@ -606,6 +606,8 @@ void InterpreterSelectQuery::executeImpl(Pipeline & pipeline, const BlockInputSt
|
||||
executeRollupOrCube(pipeline, Modificator::ROLLUP);
|
||||
else if (query.group_by_with_cube)
|
||||
executeRollupOrCube(pipeline, Modificator::CUBE);
|
||||
if ((query.group_by_with_rollup || query.group_by_with_cube) && expressions.has_having)
|
||||
executeHaving(pipeline, expressions.before_having);
|
||||
}
|
||||
else if (expressions.has_having)
|
||||
executeHaving(pipeline, expressions.before_having);
|
||||
@ -625,10 +627,15 @@ void InterpreterSelectQuery::executeImpl(Pipeline & pipeline, const BlockInputSt
|
||||
executeTotalsAndHaving(pipeline, expressions.has_having, expressions.before_having, aggregate_overflow_row, final);
|
||||
}
|
||||
|
||||
if (query.group_by_with_rollup && !aggregate_final)
|
||||
executeRollupOrCube(pipeline, Modificator::ROLLUP);
|
||||
else if (query.group_by_with_cube && !aggregate_final)
|
||||
executeRollupOrCube(pipeline, Modificator::CUBE);
|
||||
if ((query.group_by_with_rollup || query.group_by_with_cube) && !aggregate_final)
|
||||
{
|
||||
if (query.group_by_with_rollup)
|
||||
executeRollupOrCube(pipeline, Modificator::ROLLUP);
|
||||
else if (query.group_by_with_cube)
|
||||
executeRollupOrCube(pipeline, Modificator::CUBE);
|
||||
if (expressions.has_having)
|
||||
executeHaving(pipeline, expressions.before_having);
|
||||
}
|
||||
}
|
||||
|
||||
if (expressions.has_order_by)
|
||||
@ -1483,3 +1490,4 @@ void InterpreterSelectQuery::initSettings()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
a \N 1
|
||||
a b 1
|
||||
a \N 2
|
||||
a b 1
|
||||
a \N 1
|
||||
a b 1
|
||||
a \N 2
|
||||
\N \N 2
|
||||
|
||||
\N \N 2
|
||||
a b 1
|
||||
a \N 1
|
||||
\N \N 1
|
||||
|
||||
\N \N 1
|
15
dbms/tests/queries/0_stateless/00804_rollup_with_having.sql
Normal file
15
dbms/tests/queries/0_stateless/00804_rollup_with_having.sql
Normal file
@ -0,0 +1,15 @@
|
||||
DROP TABLE IF EXISTS test.rollup_having;
|
||||
CREATE TABLE test.rollup_having (
|
||||
a Nullable(String),
|
||||
b Nullable(String)
|
||||
) ENGINE = Memory;
|
||||
|
||||
INSERT INTO test.rollup_having VALUES (NULL, NULL);
|
||||
INSERT INTO test.rollup_having VALUES ('a', NULL);
|
||||
INSERT INTO test.rollup_having VALUES ('a', 'b');
|
||||
|
||||
SELECT a, b, count(*) FROM test.rollup_having GROUP BY a, b WITH ROLLUP HAVING a IS NOT NULL;
|
||||
SELECT a, b, count(*) FROM test.rollup_having GROUP BY a, b WITH ROLLUP HAVING a IS NOT NULL and b IS NOT NULL;
|
||||
|
||||
SELECT a, b, count(*) FROM test.rollup_having GROUP BY a, b WITH ROLLUP WITH TOTALS HAVING a IS NOT NULL;
|
||||
SELECT a, b, count(*) FROM test.rollup_having GROUP BY a, b WITH ROLLUP WITH TOTALS HAVING a IS NOT NULL and b IS NOT NULL;
|
Loading…
Reference in New Issue
Block a user