From d9528ffad5261cc61cde760685255e1d8c47dca9 Mon Sep 17 00:00:00 2001 From: robot-clickhouse Date: Wed, 17 Apr 2024 17:06:03 +0000 Subject: [PATCH] Backport #62274 to 24.3: Analyzer: Fix alias to parametrized view resolution --- src/Analyzer/Passes/QueryAnalysisPass.cpp | 4 +++- ...analyzer_parametrized_view_alias.reference | 10 ++++++++++ ...03033_analyzer_parametrized_view_alias.sql | 20 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/03033_analyzer_parametrized_view_alias.reference create mode 100644 tests/queries/0_stateless/03033_analyzer_parametrized_view_alias.sql diff --git a/src/Analyzer/Passes/QueryAnalysisPass.cpp b/src/Analyzer/Passes/QueryAnalysisPass.cpp index 60b6fd37375..2af7c5c1e4a 100644 --- a/src/Analyzer/Passes/QueryAnalysisPass.cpp +++ b/src/Analyzer/Passes/QueryAnalysisPass.cpp @@ -7164,7 +7164,9 @@ void QueryAnalyzer::resolveTableFunction(QueryTreeNodePtr & table_function_node, auto parametrized_view_storage = scope_context->getQueryContext()->buildParametrizedViewStorage(function_ast, database_name, table_name); if (parametrized_view_storage) { - table_function_node = std::make_shared(parametrized_view_storage, scope_context); + auto fake_table_node = std::make_shared(parametrized_view_storage, scope_context); + fake_table_node->setAlias(table_function_node->getAlias()); + table_function_node = fake_table_node; return; } diff --git a/tests/queries/0_stateless/03033_analyzer_parametrized_view_alias.reference b/tests/queries/0_stateless/03033_analyzer_parametrized_view_alias.reference new file mode 100644 index 00000000000..8b1acc12b63 --- /dev/null +++ b/tests/queries/0_stateless/03033_analyzer_parametrized_view_alias.reference @@ -0,0 +1,10 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 diff --git a/tests/queries/0_stateless/03033_analyzer_parametrized_view_alias.sql b/tests/queries/0_stateless/03033_analyzer_parametrized_view_alias.sql new file mode 100644 index 00000000000..5d576796165 --- /dev/null +++ b/tests/queries/0_stateless/03033_analyzer_parametrized_view_alias.sql @@ -0,0 +1,20 @@ +CREATE TABLE raw_data +( + `id` UInt8, + `data` String +) +ENGINE = MergeTree +ORDER BY id; + + +INSERT INTO raw_data SELECT number, number +FROM numbers(10); + +CREATE VIEW raw_data_parametrized AS +SELECT * +FROM raw_data +WHERE (id >= {id_from:UInt8}) AND (id <= {id_to:UInt8}); + +SELECT t1.id +FROM raw_data_parametrized(id_from = 0, id_to = 50000) t1 +ORDER BY t1.id;