Skip to content

Commit

Permalink
Merge pull request #62993 from ClickHouse/backport/24.3/62811
Browse files Browse the repository at this point in the history
Backport #62811 to 24.3: Fix FINAL modifier is not respected in CTE with analyzer
  • Loading branch information
Algunenano committed Apr 25, 2024
2 parents e1e505c + 76a1797 commit 44d1d9d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Analyzer/IdentifierNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/queries/0_stateless/03129_cte_with_final.reference
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions tests/queries/0_stateless/03129_cte_with_final.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 44d1d9d

Please sign in to comment.