diff --git a/src/Interpreters/InterpreterCreateFunctionQuery.cpp b/src/Interpreters/InterpreterCreateFunctionQuery.cpp index 2f345f8b237..20114fa0d75 100644 --- a/src/Interpreters/InterpreterCreateFunctionQuery.cpp +++ b/src/Interpreters/InterpreterCreateFunctionQuery.cpp @@ -41,7 +41,7 @@ BlockIO InterpreterCreateFunctionQuery::execute() auto & user_defined_function_factory = UserDefinedSQLFunctionFactory::instance(); - auto & function_name = create_function_query.function_name; + auto function_name = create_function_query.getFunctionName(); bool if_not_exists = create_function_query.if_not_exists; bool replace = create_function_query.or_replace; diff --git a/src/Interpreters/UserDefinedSQLFunctionVisitor.cpp b/src/Interpreters/UserDefinedSQLFunctionVisitor.cpp index 3e82930af9d..1adb3d5819a 100644 --- a/src/Interpreters/UserDefinedSQLFunctionVisitor.cpp +++ b/src/Interpreters/UserDefinedSQLFunctionVisitor.cpp @@ -59,7 +59,7 @@ ASTPtr UserDefinedSQLFunctionMatcher::tryToReplaceFunction(const ASTFunction & f if (function_arguments.size() != identifiers_raw.size()) throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "Function {} expects {} arguments actual arguments {}", - create_function_query->function_name, + create_function_query->getFunctionName(), identifiers_raw.size(), function_arguments.size()); diff --git a/src/Parsers/ASTCreateFunctionQuery.cpp b/src/Parsers/ASTCreateFunctionQuery.cpp index 9209b1f1869..a12eca3d334 100644 --- a/src/Parsers/ASTCreateFunctionQuery.cpp +++ b/src/Parsers/ASTCreateFunctionQuery.cpp @@ -10,7 +10,15 @@ namespace DB ASTPtr ASTCreateFunctionQuery::clone() const { - return std::make_shared(*this); + auto res = std::make_shared(*this); + res->children.clear(); + + res->function_name = function_name->clone(); + res->children.push_back(res->function_name); + + res->function_core = function_core->clone(); + res->children.push_back(res->function_core); + return res; } void ASTCreateFunctionQuery::formatImpl(const IAST::FormatSettings & settings, IAST::FormatState & state, IAST::FormatStateStacked frame) const @@ -27,7 +35,7 @@ void ASTCreateFunctionQuery::formatImpl(const IAST::FormatSettings & settings, I settings.ostr << (settings.hilite ? hilite_none : ""); - settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(function_name) << (settings.hilite ? hilite_none : ""); + settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(getFunctionName()) << (settings.hilite ? hilite_none : ""); formatOnCluster(settings); @@ -35,4 +43,11 @@ void ASTCreateFunctionQuery::formatImpl(const IAST::FormatSettings & settings, I function_core->formatImpl(settings, state, frame); } +String ASTCreateFunctionQuery::getFunctionName() const +{ + String name; + tryGetIdentifierNameInto(function_name, name); + return name; +} + } diff --git a/src/Parsers/ASTCreateFunctionQuery.h b/src/Parsers/ASTCreateFunctionQuery.h index fccc1837135..b61441da6df 100644 --- a/src/Parsers/ASTCreateFunctionQuery.h +++ b/src/Parsers/ASTCreateFunctionQuery.h @@ -10,19 +10,21 @@ namespace DB class ASTCreateFunctionQuery : public IAST, public ASTQueryWithOnCluster { public: - String function_name; + ASTPtr function_name; ASTPtr function_core; bool or_replace = false; bool if_not_exists = false; - String getID(char) const override { return "CreateFunctionQuery"; } + String getID(char delim) const override { return "CreateFunctionQuery" + (delim + getFunctionName()); } ASTPtr clone() const override; void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override; ASTPtr getRewrittenASTWithoutOnCluster(const std::string &) const override { return removeOnCluster(clone()); } + + String getFunctionName() const; }; } diff --git a/src/Parsers/ParserCreateFunctionQuery.cpp b/src/Parsers/ParserCreateFunctionQuery.cpp index 55e6e2df1d2..08df6d8da7a 100644 --- a/src/Parsers/ParserCreateFunctionQuery.cpp +++ b/src/Parsers/ParserCreateFunctionQuery.cpp @@ -59,8 +59,12 @@ bool ParserCreateFunctionQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Exp auto create_function_query = std::make_shared(); node = create_function_query; - create_function_query->function_name = function_name->as().name(); + create_function_query->function_name = function_name; + create_function_query->children.push_back(function_name); + create_function_query->function_core = function_core; + create_function_query->children.push_back(function_core); + create_function_query->or_replace = or_replace; create_function_query->if_not_exists = if_not_exists; create_function_query->cluster = std::move(cluster_str); diff --git a/tests/queries/0_stateless/01604_explain_ast_of_nonselect_query.reference b/tests/queries/0_stateless/01604_explain_ast_of_nonselect_query.reference index 4cc67aa517c..0bec8aabdb1 100644 --- a/tests/queries/0_stateless/01604_explain_ast_of_nonselect_query.reference +++ b/tests/queries/0_stateless/01604_explain_ast_of_nonselect_query.reference @@ -7,3 +7,14 @@ AlterQuery t1 (children 2) Function today (children 1) ExpressionList Identifier t1 +CreateFunctionQuery double (children 2) + Identifier double + Function lambda (children 1) + ExpressionList (children 2) + Function tuple (children 1) + ExpressionList (children 1) + Identifier n + Function multiply (children 1) + ExpressionList (children 2) + Literal UInt64_2 + Identifier n diff --git a/tests/queries/0_stateless/01604_explain_ast_of_nonselect_query.sql b/tests/queries/0_stateless/01604_explain_ast_of_nonselect_query.sql index 41939123c92..6a4c065fd2c 100644 --- a/tests/queries/0_stateless/01604_explain_ast_of_nonselect_query.sql +++ b/tests/queries/0_stateless/01604_explain_ast_of_nonselect_query.sql @@ -1,2 +1,3 @@ explain ast; -- { clientError 62 } -explain ast alter table t1 delete where date = today() +explain ast alter table t1 delete where date = today(); +explain ast create function double AS (n) -> 2*n;