Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FINAL modifier is not respected in CTE with analyzer #62811

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.test, final: 1
1 first 2024-04-19 01:01:01
22 changes: 22 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,22 @@
CREATE OR REPLACE TABLE test
(
`key` Int64,
`someCol` String,
`eventTime` DateTime
)
ENGINE = ReplacingMergeTree(eventTime)
ORDER BY key;

INSERT INTO test Values (1, 'first', '2024-04-19 01:01:01');
INSERT INTO test Values (1, 'first', '2024-04-19 01:01:01');

EXPLAIN QUERY TREE passes=1
WITH merged_test AS(
SELECT * FROM test Final
)
SELECT * FROM merged_test;

WITH merged_test AS(
SELECT * FROM test Final
)
SELECT * FROM merged_test;