From bbeb3f61e5879efabac5879e284f5b11963dffc1 Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:04:04 +0100 Subject: [PATCH 01/11] init --- src/Interpreters/QueryAliasesVisitor.cpp | 20 ++++++++++++++++++-- src/Interpreters/QueryAliasesVisitor.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Interpreters/QueryAliasesVisitor.cpp b/src/Interpreters/QueryAliasesVisitor.cpp index 8f96044abec..9c3492587ec 100644 --- a/src/Interpreters/QueryAliasesVisitor.cpp +++ b/src/Interpreters/QueryAliasesVisitor.cpp @@ -114,17 +114,33 @@ void QueryAliasesMatcher::visit(const ASTSubquery & const_subquery, const AST subquery.prefer_alias_to_column_name = true; } +template +bool QueryAliasesMatcher::checkIfNamesAreSame(Data & data, const ASTPtr & ast) +{ + String name = ast->getColumnName(); + for (const auto & obj : data) + { + if (obj.second->getColumnName() == name) + return true; + } + return false; +} + template void QueryAliasesMatcher::visitOther(const ASTPtr & ast, Data & data) { auto & aliases = data; String alias = ast->tryGetAlias(); + if (!alias.empty()) { if (aliases.contains(alias) && ast->getTreeHash(/*ignore_aliases=*/ true) != aliases[alias]->getTreeHash(/*ignore_aliases=*/ true)) - throw Exception(wrongAliasMessage(ast, aliases[alias], alias), ErrorCodes::MULTIPLE_EXPRESSIONS_FOR_ALIAS); + { + if (checkIfNamesAreSame(aliases, ast)) + throw Exception(wrongAliasMessage(ast, aliases[alias], alias), ErrorCodes::MULTIPLE_EXPRESSIONS_FOR_ALIAS); + } - aliases[alias] = ast; + aliases[ast->getColumnNameWithoutAlias()] = ast; } /** QueryAliasesVisitor is executed before ExecuteScalarSubqueriesVisitor. diff --git a/src/Interpreters/QueryAliasesVisitor.h b/src/Interpreters/QueryAliasesVisitor.h index 6e79cfc77be..3cee3b2fc64 100644 --- a/src/Interpreters/QueryAliasesVisitor.h +++ b/src/Interpreters/QueryAliasesVisitor.h @@ -38,6 +38,7 @@ private: static void visit(const ASTSubquery & subquery, const ASTPtr & ast, Data & data); static void visit(const ASTArrayJoin &, const ASTPtr & ast, Data & data); static void visitOther(const ASTPtr & ast, Data & data); + static bool checkIfNamesAreSame(Data & data, const ASTPtr & ast); }; /// Visits AST nodes and collect their aliases in one map (with links to source nodes). From e0fb20f6d41c8fa0f3ecacbd77121b58cd38ae56 Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:45:23 +0100 Subject: [PATCH 02/11] Fix. --- src/Interpreters/QueryAliasesVisitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Interpreters/QueryAliasesVisitor.cpp b/src/Interpreters/QueryAliasesVisitor.cpp index 9c3492587ec..23c81db9af0 100644 --- a/src/Interpreters/QueryAliasesVisitor.cpp +++ b/src/Interpreters/QueryAliasesVisitor.cpp @@ -140,7 +140,7 @@ void QueryAliasesMatcher::visitOther(const ASTPtr & ast, Data & data) throw Exception(wrongAliasMessage(ast, aliases[alias], alias), ErrorCodes::MULTIPLE_EXPRESSIONS_FOR_ALIAS); } - aliases[ast->getColumnNameWithoutAlias()] = ast; + aliases[alias] = ast; } /** QueryAliasesVisitor is executed before ExecuteScalarSubqueriesVisitor. From 7a30ea2e48ac49620968cb3cf8dc5d39e539ace2 Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:48:10 +0100 Subject: [PATCH 03/11] Normalize the query before parsing aliases. --- .../Resolve/QueryExpressionsAliasVisitor.h | 2 +- .../UserDefinedSQLFunctionVisitor.cpp | 29 ++++++++++++++----- .../UserDefinedSQLFunctionVisitor.h | 8 ++--- src/Interpreters/InterpreterAlterQuery.cpp | 2 +- src/Interpreters/InterpreterCreateQuery.cpp | 2 +- src/Interpreters/QueryAliasesVisitor.h | 1 - src/Interpreters/TreeRewriter.cpp | 2 +- 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/Analyzer/Resolve/QueryExpressionsAliasVisitor.h b/src/Analyzer/Resolve/QueryExpressionsAliasVisitor.h index 9824f4a2570..b4c47b306ae 100644 --- a/src/Analyzer/Resolve/QueryExpressionsAliasVisitor.h +++ b/src/Analyzer/Resolve/QueryExpressionsAliasVisitor.h @@ -96,7 +96,7 @@ private: auto [_, inserted] = aliases.alias_name_to_lambda_node.insert(std::make_pair(alias, node)); if (!inserted) - addDuplicatingAlias(node); + addDuplicatingAlias(node); return; } diff --git a/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.cpp b/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.cpp index a04b8d7b998..2ec62b9ce8f 100644 --- a/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.cpp +++ b/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.cpp @@ -11,7 +11,9 @@ #include #include #include -#include "Parsers/ASTColumnDeclaration.h" +#include +#include +#include namespace DB @@ -22,14 +24,14 @@ namespace ErrorCodes extern const int UNSUPPORTED_METHOD; } -void UserDefinedSQLFunctionVisitor::visit(ASTPtr & ast) +void UserDefinedSQLFunctionVisitor::visit(ASTPtr & ast, ContextPtr context_) { chassert(ast); if (const auto * function = ast->template as()) { std::unordered_set udf_in_replace_process; - auto replace_result = tryToReplaceFunction(*function, udf_in_replace_process); + auto replace_result = tryToReplaceFunction(*function, udf_in_replace_process, context_); if (replace_result) ast = replace_result; } @@ -40,7 +42,7 @@ void UserDefinedSQLFunctionVisitor::visit(ASTPtr & ast) return; auto * old_ptr = child.get(); - visit(child); + visit(child, context_); auto * new_ptr = child.get(); /// Some AST classes have naked pointers to children elements as members. @@ -50,16 +52,16 @@ void UserDefinedSQLFunctionVisitor::visit(ASTPtr & ast) } } -void UserDefinedSQLFunctionVisitor::visit(IAST * ast) +void UserDefinedSQLFunctionVisitor::visit(IAST * ast, ContextPtr context_) { if (!ast) return; for (auto & child : ast->children) - visit(child); + visit(child, context_); } -ASTPtr UserDefinedSQLFunctionVisitor::tryToReplaceFunction(const ASTFunction & function, std::unordered_set & udf_in_replace_process) +ASTPtr UserDefinedSQLFunctionVisitor::tryToReplaceFunction(const ASTFunction & function, std::unordered_set & udf_in_replace_process, ContextPtr context_) { if (udf_in_replace_process.find(function.name) != udf_in_replace_process.end()) throw Exception(ErrorCodes::UNSUPPORTED_METHOD, @@ -101,6 +103,17 @@ ASTPtr UserDefinedSQLFunctionVisitor::tryToReplaceFunction(const ASTFunction & f auto function_body_to_update = function_core_expression->children.at(1)->clone(); + Aliases aliases; + QueryAliasesVisitor(aliases).visit(function_body_to_update); + + /// Mark table ASTIdentifiers with not a column marker + MarkTableIdentifiersVisitor::Data identifiers_data{aliases}; + MarkTableIdentifiersVisitor(identifiers_data).visit(function_body_to_update); + + /// Common subexpression elimination. Rewrite rules. + QueryNormalizer::Data normalizer_data(aliases, {}, true, context_->getSettingsRef(), true, false); + QueryNormalizer(normalizer_data).visit(function_body_to_update); + auto expression_list = std::make_shared(); expression_list->children.emplace_back(std::move(function_body_to_update)); @@ -116,7 +129,7 @@ ASTPtr UserDefinedSQLFunctionVisitor::tryToReplaceFunction(const ASTFunction & f { if (auto * inner_function = child->as()) { - auto replace_result = tryToReplaceFunction(*inner_function, udf_in_replace_process); + auto replace_result = tryToReplaceFunction(*inner_function, udf_in_replace_process, context_); if (replace_result) child = replace_result; } diff --git a/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.h b/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.h index c8cbf396707..36bdfc1499d 100644 --- a/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.h +++ b/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.h @@ -19,13 +19,13 @@ class ASTFunction; * After applying visitor: * SELECT number + 1 FROM system.numbers LIMIT 10; */ -class UserDefinedSQLFunctionVisitor +class UserDefinedSQLFunctionVisitor : WithContext { public: - static void visit(ASTPtr & ast); + static void visit(ASTPtr & ast, ContextPtr context_); private: - static void visit(IAST *); - static ASTPtr tryToReplaceFunction(const ASTFunction & function, std::unordered_set & udf_in_replace_process); + static void visit(IAST *, ContextPtr context_); + static ASTPtr tryToReplaceFunction(const ASTFunction & function, std::unordered_set & udf_in_replace_process, ContextPtr context_); }; diff --git a/src/Interpreters/InterpreterAlterQuery.cpp b/src/Interpreters/InterpreterAlterQuery.cpp index 907026c73a3..1bf62387307 100644 --- a/src/Interpreters/InterpreterAlterQuery.cpp +++ b/src/Interpreters/InterpreterAlterQuery.cpp @@ -99,7 +99,7 @@ BlockIO InterpreterAlterQuery::executeToTable(const ASTAlterQuery & alter) BlockIO res; if (!UserDefinedSQLFunctionFactory::instance().empty()) - UserDefinedSQLFunctionVisitor::visit(query_ptr); + UserDefinedSQLFunctionVisitor::visit(query_ptr, getContext()); auto table_id = getContext()->tryResolveStorageID(alter); StoragePtr table; diff --git a/src/Interpreters/InterpreterCreateQuery.cpp b/src/Interpreters/InterpreterCreateQuery.cpp index ff0e1d7f5a8..bf2c33f6020 100644 --- a/src/Interpreters/InterpreterCreateQuery.cpp +++ b/src/Interpreters/InterpreterCreateQuery.cpp @@ -1599,7 +1599,7 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create) // substitute possible UDFs with their definitions if (!UserDefinedSQLFunctionFactory::instance().empty()) - UserDefinedSQLFunctionVisitor::visit(query_ptr); + UserDefinedSQLFunctionVisitor::visit(query_ptr, getContext()); /// Set and retrieve list of columns, indices and constraints. Set table engine if needed. Rewrite query in canonical way. TableProperties properties = getTablePropertiesAndNormalizeCreateQuery(create, mode); diff --git a/src/Interpreters/QueryAliasesVisitor.h b/src/Interpreters/QueryAliasesVisitor.h index 3cee3b2fc64..6e79cfc77be 100644 --- a/src/Interpreters/QueryAliasesVisitor.h +++ b/src/Interpreters/QueryAliasesVisitor.h @@ -38,7 +38,6 @@ private: static void visit(const ASTSubquery & subquery, const ASTPtr & ast, Data & data); static void visit(const ASTArrayJoin &, const ASTPtr & ast, Data & data); static void visitOther(const ASTPtr & ast, Data & data); - static bool checkIfNamesAreSame(Data & data, const ASTPtr & ast); }; /// Visits AST nodes and collect their aliases in one map (with links to source nodes). diff --git a/src/Interpreters/TreeRewriter.cpp b/src/Interpreters/TreeRewriter.cpp index 16b0e7ef199..7f2b766e712 100644 --- a/src/Interpreters/TreeRewriter.cpp +++ b/src/Interpreters/TreeRewriter.cpp @@ -1571,7 +1571,7 @@ void TreeRewriter::normalize( ASTPtr & query, Aliases & aliases, const NameSet & source_columns_set, bool ignore_alias, const Settings & settings, bool allow_self_aliases, ContextPtr context_, bool is_create_parameterized_view) { if (!UserDefinedSQLFunctionFactory::instance().empty()) - UserDefinedSQLFunctionVisitor::visit(query); + UserDefinedSQLFunctionVisitor::visit(query, context_); CustomizeCountDistinctVisitor::Data data_count_distinct{settings[Setting::count_distinct_implementation]}; CustomizeCountDistinctVisitor(data_count_distinct).visit(query); From ec9366e4e44f3e8eadca3237137b3972c77ad330 Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:55:06 +0100 Subject: [PATCH 04/11] Add tests. --- .../03274_aliases_in_udf.reference | 5 +++ .../0_stateless/03274_aliases_in_udf.sql | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/queries/0_stateless/03274_aliases_in_udf.reference create mode 100644 tests/queries/0_stateless/03274_aliases_in_udf.sql diff --git a/tests/queries/0_stateless/03274_aliases_in_udf.reference b/tests/queries/0_stateless/03274_aliases_in_udf.reference new file mode 100644 index 00000000000..eb17ca9feba --- /dev/null +++ b/tests/queries/0_stateless/03274_aliases_in_udf.reference @@ -0,0 +1,5 @@ +FIX ISSUE #69143 +a +b +EXPAIN SYNTAX OF UDF +SELECT ((4 + 2) + 1, ((4 + 2) + 1) + 2) \ No newline at end of file diff --git a/tests/queries/0_stateless/03274_aliases_in_udf.sql b/tests/queries/0_stateless/03274_aliases_in_udf.sql new file mode 100644 index 00000000000..cf53ec4b6cb --- /dev/null +++ b/tests/queries/0_stateless/03274_aliases_in_udf.sql @@ -0,0 +1,32 @@ +SELECT "FIX ISSUE #69143" + +CREATE OR REPLACE FUNCTION test_function AS ( input_column_name ) -> (( + '1' AS a, + input_column_name AS input_column_name + ).2); + +CREATE TABLE test_table +( + `metadata_a` String, + `metadata_b` String +) +ENGINE = MergeTree() +ORDER BY tuple(); + + +ALTER TABLE test_table ADD COLUMN mat_a String MATERIALIZED test_function(metadata_a); +ALTER TABLE test_table MATERIALIZE COLUMN `mat_a`; + +ALTER TABLE test_table ADD COLUMN mat_b String MATERIALIZED test_function(metadata_b); +ALTER TABLE test_table MATERIALIZE COLUMN `mat_b`; + +INSERT INTO test_table SELECT 'a', 'b'; + +SELECT mat_a FROM test_table; +SELECT mat_b FROM test_table; + +SELECT "EXPAIN SYNTAX OF UDF"; + +CREATE OR REPLACE FUNCTION test_03274 AS ( x ) -> ((x + 1 as y, y + 2)); + +EXPAIN SYNTAX SELECT test_03274(4 + 2); From a7c3acd90cd119fc37954cad8b19c7bf40d9c96f Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:57:15 +0100 Subject: [PATCH 05/11] Minor clarification. --- src/Interpreters/QueryNormalizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Interpreters/QueryNormalizer.cpp b/src/Interpreters/QueryNormalizer.cpp index bba30fb5194..8f85ee22682 100644 --- a/src/Interpreters/QueryNormalizer.cpp +++ b/src/Interpreters/QueryNormalizer.cpp @@ -85,10 +85,10 @@ void QueryNormalizer::visit(ASTIdentifier & node, ASTPtr & ast, Data & data) } /// If it is an alias, but not a parent alias (for constructs like "SELECT column + 1 AS column"). - auto it_alias = data.aliases.find(node.name()); if (!data.allow_self_aliases && current_alias == node.name()) throw Exception(ErrorCodes::CYCLIC_ALIASES, "Self referencing of {} to {}. Cyclic alias", backQuote(current_alias), backQuote(node.name())); + auto it_alias = data.aliases.find(node.name()); if (it_alias != data.aliases.end() && current_alias != node.name()) { From e81c5171b78a659726ac6380a6c5f5e70acfbe1d Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:10:04 +0100 Subject: [PATCH 06/11] Small fixup. --- src/Interpreters/QueryAliasesVisitor.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/Interpreters/QueryAliasesVisitor.cpp b/src/Interpreters/QueryAliasesVisitor.cpp index 23c81db9af0..85335c609e5 100644 --- a/src/Interpreters/QueryAliasesVisitor.cpp +++ b/src/Interpreters/QueryAliasesVisitor.cpp @@ -114,31 +114,15 @@ void QueryAliasesMatcher::visit(const ASTSubquery & const_subquery, const AST subquery.prefer_alias_to_column_name = true; } -template -bool QueryAliasesMatcher::checkIfNamesAreSame(Data & data, const ASTPtr & ast) -{ - String name = ast->getColumnName(); - for (const auto & obj : data) - { - if (obj.second->getColumnName() == name) - return true; - } - return false; -} - template void QueryAliasesMatcher::visitOther(const ASTPtr & ast, Data & data) { auto & aliases = data; String alias = ast->tryGetAlias(); - if (!alias.empty()) { if (aliases.contains(alias) && ast->getTreeHash(/*ignore_aliases=*/ true) != aliases[alias]->getTreeHash(/*ignore_aliases=*/ true)) - { - if (checkIfNamesAreSame(aliases, ast)) throw Exception(wrongAliasMessage(ast, aliases[alias], alias), ErrorCodes::MULTIPLE_EXPRESSIONS_FOR_ALIAS); - } aliases[alias] = ast; } From fedbdaa29c56c23e6ecb8290a7dc04da8e1f3420 Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:22:36 +0100 Subject: [PATCH 07/11] Fix build --- src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.h b/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.h index 36bdfc1499d..633f68db348 100644 --- a/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.h +++ b/src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.h @@ -19,7 +19,7 @@ class ASTFunction; * After applying visitor: * SELECT number + 1 FROM system.numbers LIMIT 10; */ -class UserDefinedSQLFunctionVisitor : WithContext +class UserDefinedSQLFunctionVisitor { public: static void visit(ASTPtr & ast, ContextPtr context_); From c738edf8bbb269b72c6ca308b78bc20ee7dc48b5 Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Wed, 20 Nov 2024 20:45:58 +0100 Subject: [PATCH 08/11] Add a semicolon. --- tests/queries/0_stateless/03274_aliases_in_udf.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/queries/0_stateless/03274_aliases_in_udf.sql b/tests/queries/0_stateless/03274_aliases_in_udf.sql index cf53ec4b6cb..92fa8492177 100644 --- a/tests/queries/0_stateless/03274_aliases_in_udf.sql +++ b/tests/queries/0_stateless/03274_aliases_in_udf.sql @@ -1,4 +1,4 @@ -SELECT "FIX ISSUE #69143" +SELECT "FIX ISSUE #69143"; CREATE OR REPLACE FUNCTION test_function AS ( input_column_name ) -> (( '1' AS a, From ed285f47dc2b47fada0343ed69b7c3d91f7a2915 Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Wed, 20 Nov 2024 23:14:19 +0100 Subject: [PATCH 09/11] Update 03274_aliases_in_udf.sql --- tests/queries/0_stateless/03274_aliases_in_udf.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/queries/0_stateless/03274_aliases_in_udf.sql b/tests/queries/0_stateless/03274_aliases_in_udf.sql index 92fa8492177..c909990d7ce 100644 --- a/tests/queries/0_stateless/03274_aliases_in_udf.sql +++ b/tests/queries/0_stateless/03274_aliases_in_udf.sql @@ -1,4 +1,4 @@ -SELECT "FIX ISSUE #69143"; +SELECT 'FIX ISSUE #69143'; CREATE OR REPLACE FUNCTION test_function AS ( input_column_name ) -> (( '1' AS a, @@ -25,7 +25,7 @@ INSERT INTO test_table SELECT 'a', 'b'; SELECT mat_a FROM test_table; SELECT mat_b FROM test_table; -SELECT "EXPAIN SYNTAX OF UDF"; +SELECT 'EXPAIN SYNTAX OF UDF'; CREATE OR REPLACE FUNCTION test_03274 AS ( x ) -> ((x + 1 as y, y + 2)); From 9cfee9cddbf90ca2cc2ed15803a150abe2e7ca87 Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Thu, 21 Nov 2024 00:55:26 +0100 Subject: [PATCH 10/11] Update 03274_aliases_in_udf.reference --- tests/queries/0_stateless/03274_aliases_in_udf.reference | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/queries/0_stateless/03274_aliases_in_udf.reference b/tests/queries/0_stateless/03274_aliases_in_udf.reference index eb17ca9feba..2d51e7becae 100644 --- a/tests/queries/0_stateless/03274_aliases_in_udf.reference +++ b/tests/queries/0_stateless/03274_aliases_in_udf.reference @@ -2,4 +2,4 @@ FIX ISSUE #69143 a b EXPAIN SYNTAX OF UDF -SELECT ((4 + 2) + 1, ((4 + 2) + 1) + 2) \ No newline at end of file +SELECT ((4 + 2) + 1, ((4 + 2) + 1) + 2) From 7dcaacab9daa7dd491dde5fcaf698d2d85a21d85 Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Thu, 21 Nov 2024 01:00:37 +0100 Subject: [PATCH 11/11] Update 03274_aliases_in_udf.sql --- tests/queries/0_stateless/03274_aliases_in_udf.sql | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/queries/0_stateless/03274_aliases_in_udf.sql b/tests/queries/0_stateless/03274_aliases_in_udf.sql index c909990d7ce..a6154b81907 100644 --- a/tests/queries/0_stateless/03274_aliases_in_udf.sql +++ b/tests/queries/0_stateless/03274_aliases_in_udf.sql @@ -1,11 +1,15 @@ SELECT 'FIX ISSUE #69143'; +DROP FUNCTION IF EXISTS test_function; +DROP FUNCTION IF EXISTS test_03274; +DROP TABLE IF EXISTS test_table; + CREATE OR REPLACE FUNCTION test_function AS ( input_column_name ) -> (( '1' AS a, input_column_name AS input_column_name ).2); -CREATE TABLE test_table +CREATE TABLE IF NOT EXISTS test_table ( `metadata_a` String, `metadata_b` String @@ -30,3 +34,7 @@ SELECT 'EXPAIN SYNTAX OF UDF'; CREATE OR REPLACE FUNCTION test_03274 AS ( x ) -> ((x + 1 as y, y + 2)); EXPAIN SYNTAX SELECT test_03274(4 + 2); + +DROP FUNCTION IF EXISTS test_function; +DROP FUNCTION IF EXISTS test_03274; +DROP TABLE IF EXISTS test_table;