Merge pull request #62993 from ClickHouse/backport/24.3/62811

Backport #62811 to 24.3: Fix FINAL modifier is not respected in CTE with analyzer
This commit is contained in:
Raúl Marín 2024-04-26 00:36:09 +02:00 committed by GitHub
commit 44d1d9d21b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 55 additions and 1 deletions

View File

@ -56,7 +56,9 @@ void IdentifierNode::updateTreeHashImpl(HashState & state, CompareOptions) const
QueryTreeNodePtr IdentifierNode::cloneImpl() const
{
return std::make_shared<IdentifierNode>(identifier);
auto clone_identifier_node = std::make_shared<IdentifierNode>(identifier);
clone_identifier_node->table_expression_modifiers = table_expression_modifiers;
return clone_identifier_node;
}
ASTPtr IdentifierNode::toASTImpl(const ConvertToASTOptions & /* options */) const

View File

@ -0,0 +1,24 @@
QUERY id: 0
PROJECTION COLUMNS
key Int64
someCol String
eventTime DateTime
PROJECTION
LIST id: 1, nodes: 3
COLUMN id: 2, column_name: key, result_type: Int64, source_id: 3
COLUMN id: 4, column_name: someCol, result_type: String, source_id: 3
COLUMN id: 5, column_name: eventTime, result_type: DateTime, source_id: 3
JOIN TREE
QUERY id: 3, alias: __table1, is_subquery: 1, is_cte: 1, cte_name: merged_test
PROJECTION COLUMNS
key Int64
someCol String
eventTime DateTime
PROJECTION
LIST id: 6, nodes: 3
COLUMN id: 7, column_name: key, result_type: Int64, source_id: 8
COLUMN id: 9, column_name: someCol, result_type: String, source_id: 8
COLUMN id: 10, column_name: eventTime, result_type: DateTime, source_id: 8
JOIN TREE
TABLE id: 8, alias: __table2, table_name: default.t, final: 1
1 first 2024-04-19 01:01:01

View File

@ -0,0 +1,28 @@
DROP TABLE IF EXISTS t;
CREATE TABLE t
(
`key` Int64,
`someCol` String,
`eventTime` DateTime
)
ENGINE = ReplacingMergeTree(eventTime)
ORDER BY key;
INSERT INTO t Values (1, 'first', '2024-04-19 01:01:01');
INSERT INTO t Values (1, 'first', '2024-04-19 01:01:01');
SET allow_experimental_analyzer = 1;
EXPLAIN QUERY TREE passes=1
WITH merged_test AS(
SELECT * FROM t Final
)
SELECT * FROM merged_test;
WITH merged_test AS(
SELECT * FROM t Final
)
SELECT * FROM merged_test;
DROP TABLE t;