mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Fixed code review issues
This commit is contained in:
parent
0ad8c6ef78
commit
0e28d20791
@ -12,3 +12,23 @@ It is possible to reference window functions results from `SELECT` clause in `QU
|
||||
## Limitations
|
||||
|
||||
`QUALIFY` can’t be used if there are no window functions to evaluate. Use `WHERE` instead.
|
||||
|
||||
## Examples
|
||||
|
||||
Example:
|
||||
|
||||
``` sql
|
||||
SELECT number, COUNT() OVER (PARTITION BY number % 3) AS partition_count
|
||||
FROM numbers(10)
|
||||
QUALIFY partition_count = 4
|
||||
ORDER BY number;
|
||||
```
|
||||
|
||||
``` text
|
||||
┌─number─┬─partition_count─┐
|
||||
│ 0 │ 4 │
|
||||
│ 3 │ 4 │
|
||||
│ 6 │ 4 │
|
||||
│ 9 │ 4 │
|
||||
└────────┴─────────────────┘
|
||||
```
|
||||
|
@ -7895,6 +7895,9 @@ void QueryAnalyzer::resolveQuery(const QueryTreeNodePtr & query_node, Identifier
|
||||
if (query_node_typed.hasHaving() && query_node_typed.isGroupByWithTotals() && is_rollup_or_cube)
|
||||
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "WITH TOTALS and WITH ROLLUP or CUBE are not supported together in presence of HAVING");
|
||||
|
||||
if (query_node_typed.hasQualify() && query_node_typed.isGroupByWithTotals() && is_rollup_or_cube)
|
||||
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "WITH TOTALS and WITH ROLLUP or CUBE are not supported together in presence of QUALIFY");
|
||||
|
||||
/// Initialize aliases in query node scope
|
||||
QueryExpressionsAliasVisitor visitor(scope);
|
||||
|
||||
|
@ -16,3 +16,59 @@
|
||||
0 5
|
||||
--
|
||||
0 5
|
||||
--
|
||||
0 4
|
||||
3 4
|
||||
6 4
|
||||
9 4
|
||||
--
|
||||
Expression (Project names)
|
||||
Header: number UInt64
|
||||
partition_count UInt64
|
||||
Actions: INPUT : 0 -> __table1.number UInt64 : 0
|
||||
INPUT : 1 -> count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)) UInt64 : 1
|
||||
ALIAS __table1.number :: 0 -> number UInt64 : 2
|
||||
ALIAS count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)) :: 1 -> partition_count UInt64 : 0
|
||||
Positions: 2 0
|
||||
Sorting (Sorting for ORDER BY)
|
||||
Header: __table1.number UInt64
|
||||
count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)) UInt64
|
||||
Sort description: __table1.number ASC
|
||||
Expression ((Before ORDER BY + Projection))
|
||||
Header: __table1.number UInt64
|
||||
count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)) UInt64
|
||||
Actions: INPUT :: 0 -> __table1.number UInt64 : 0
|
||||
INPUT :: 1 -> count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)) UInt64 : 1
|
||||
Positions: 0 1
|
||||
Filter (QUALIFY)
|
||||
Header: __table1.number UInt64
|
||||
count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)) UInt64
|
||||
Filter column: equals(count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)), 4_UInt8) (removed)
|
||||
Actions: INPUT :: 0 -> __table1.number UInt64 : 0
|
||||
INPUT :: 1 -> count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)) UInt64 : 1
|
||||
INPUT : 2 -> count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)) UInt64 : 2
|
||||
COLUMN Const(UInt8) -> 4_UInt8 UInt8 : 3
|
||||
FUNCTION equals(count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)) :: 2, 4_UInt8 :: 3) -> equals(count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)), 4_UInt8) UInt8 : 4
|
||||
Positions: 4 0 1
|
||||
Window (Window step for window \'PARTITION BY modulo(__table1.number, 3_UInt8)\')
|
||||
Header: modulo(__table1.number, 3_UInt8) UInt8
|
||||
__table1.number UInt64
|
||||
count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)) UInt64
|
||||
count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8)) UInt64
|
||||
Window: (PARTITION BY modulo(__table1.number, 3_UInt8))
|
||||
Functions: count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8))
|
||||
count() OVER (PARTITION BY modulo(__table1.number, 3_UInt8))
|
||||
Sorting (Sorting for window \'PARTITION BY modulo(__table1.number, 3_UInt8)\')
|
||||
Header: modulo(__table1.number, 3_UInt8) UInt8
|
||||
__table1.number UInt64
|
||||
Sort description: modulo(__table1.number, 3_UInt8) ASC
|
||||
Expression ((Before WINDOW + Change column names to column identifiers))
|
||||
Header: modulo(__table1.number, 3_UInt8) UInt8
|
||||
__table1.number UInt64
|
||||
Actions: INPUT : 0 -> number UInt64 : 0
|
||||
COLUMN Const(UInt8) -> 3_UInt8 UInt8 : 1
|
||||
ALIAS number :: 0 -> __table1.number UInt64 : 2
|
||||
FUNCTION modulo(__table1.number : 2, 3_UInt8 :: 1) -> modulo(__table1.number, 3_UInt8) UInt8 : 0
|
||||
Positions: 0 2
|
||||
ReadFromSystemNumbers
|
||||
Header: number UInt64
|
||||
|
@ -17,3 +17,20 @@ SELECT (number % 2) AS key, count() FROM numbers(10) GROUP BY key HAVING key = 0
|
||||
SELECT '--';
|
||||
|
||||
SELECT (number % 2) AS key, count() FROM numbers(10) GROUP BY key QUALIFY key == 0;
|
||||
|
||||
SELECT '--';
|
||||
|
||||
SELECT number, COUNT() OVER (PARTITION BY number % 3) AS partition_count FROM numbers(10) QUALIFY COUNT() OVER (PARTITION BY number % 3) = 4 ORDER BY number;
|
||||
|
||||
SELECT '--';
|
||||
|
||||
EXPLAIN header = 1, actions = 1
|
||||
SELECT number, COUNT() OVER (PARTITION BY number % 3) AS partition_count FROM numbers(10) QUALIFY COUNT() OVER (PARTITION BY number % 3) = 4 ORDER BY number;
|
||||
|
||||
SELECT number % toUInt256(2) AS key, count() FROM numbers(10) GROUP BY key WITH CUBE WITH TOTALS QUALIFY key = toNullable(toNullable(0)); -- { serverError 48 }
|
||||
|
||||
SELECT number % 2 AS key, count(materialize(5)) IGNORE NULLS FROM numbers(10) WHERE toLowCardinality(toLowCardinality(materialize(2))) GROUP BY key WITH CUBE WITH TOTALS QUALIFY key = 0; -- { serverError 48 }
|
||||
|
||||
SELECT 4, count(4) IGNORE NULLS, number % 2 AS key FROM numbers(10) GROUP BY key WITH ROLLUP WITH TOTALS QUALIFY key = materialize(0); -- { serverError 48 }
|
||||
|
||||
SELECT 3, number % toLowCardinality(2) AS key, count() IGNORE NULLS FROM numbers(10) GROUP BY key WITH ROLLUP WITH TOTALS QUALIFY key = 0; -- { serverError 48 }
|
||||
|
Loading…
Reference in New Issue
Block a user