mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 09:02:00 +00:00
Merge pull request #33819 from bigo-sg/optimize_explain_create_function
Support explain create function query
This commit is contained in:
commit
41ee114abb
@ -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;
|
||||
|
@ -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());
|
||||
|
||||
|
@ -10,7 +10,15 @@ namespace DB
|
||||
|
||||
ASTPtr ASTCreateFunctionQuery::clone() const
|
||||
{
|
||||
return std::make_shared<ASTCreateFunctionQuery>(*this);
|
||||
auto res = std::make_shared<ASTCreateFunctionQuery>(*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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<ASTCreateFunctionQuery>(clone()); }
|
||||
|
||||
String getFunctionName() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -59,8 +59,12 @@ bool ParserCreateFunctionQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Exp
|
||||
auto create_function_query = std::make_shared<ASTCreateFunctionQuery>();
|
||||
node = create_function_query;
|
||||
|
||||
create_function_query->function_name = function_name->as<ASTIdentifier &>().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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user