2021-05-09 09:47:29 +00:00
|
|
|
#include <Common/quoteString.h>
|
|
|
|
#include <IO/Operators.h>
|
|
|
|
#include <Parsers/ASTCreateFunctionQuery.h>
|
2021-10-27 08:28:21 +00:00
|
|
|
#include <Parsers/ASTExpressionList.h>
|
|
|
|
#include <Parsers/ASTFunction.h>
|
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
ASTPtr ASTCreateFunctionQuery::clone() const
|
|
|
|
{
|
2022-01-20 08:23:52 +00:00
|
|
|
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;
|
2021-05-09 09:47:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTCreateFunctionQuery::formatImpl(const IAST::FormatSettings & settings, IAST::FormatState & state, IAST::FormatStateStacked frame) const
|
|
|
|
{
|
2021-10-20 13:04:02 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "CREATE ";
|
|
|
|
|
|
|
|
if (or_replace)
|
|
|
|
settings.ostr << "OR REPLACE ";
|
|
|
|
|
|
|
|
settings.ostr << "FUNCTION ";
|
|
|
|
|
|
|
|
if (if_not_exists)
|
|
|
|
settings.ostr << "IF NOT EXISTS ";
|
|
|
|
|
|
|
|
settings.ostr << (settings.hilite ? hilite_none : "");
|
|
|
|
|
2022-01-20 08:23:52 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(getFunctionName()) << (settings.hilite ? hilite_none : "");
|
2021-10-27 08:28:21 +00:00
|
|
|
|
|
|
|
formatOnCluster(settings);
|
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " AS " << (settings.hilite ? hilite_none : "");
|
|
|
|
function_core->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
|
2022-01-20 08:23:52 +00:00
|
|
|
String ASTCreateFunctionQuery::getFunctionName() const
|
|
|
|
{
|
|
|
|
String name;
|
|
|
|
tryGetIdentifierNameInto(function_name, name);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
}
|