2021-10-20 13:04:02 +00:00
|
|
|
#include <Parsers/ParserCreateFunctionQuery.h>
|
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
#include <Parsers/ASTCreateFunctionQuery.h>
|
|
|
|
#include <Parsers/ASTExpressionList.h>
|
|
|
|
#include <Parsers/ASTIdentifier.h>
|
|
|
|
#include <Parsers/CommonParsers.h>
|
|
|
|
#include <Parsers/ExpressionElementParsers.h>
|
|
|
|
#include <Parsers/ExpressionListParsers.h>
|
2021-10-20 13:04:02 +00:00
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-05-10 22:35:22 +00:00
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
bool ParserCreateFunctionQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
|
|
|
ParserKeyword s_create("CREATE");
|
|
|
|
ParserKeyword s_function("FUNCTION");
|
2021-10-20 13:04:02 +00:00
|
|
|
ParserKeyword s_or_replace("OR REPLACE");
|
|
|
|
ParserKeyword s_if_not_exists("IF NOT EXISTS");
|
2021-10-27 08:28:21 +00:00
|
|
|
ParserKeyword s_on("ON");
|
2021-05-09 09:47:29 +00:00
|
|
|
ParserIdentifier function_name_p;
|
|
|
|
ParserKeyword s_as("AS");
|
2022-06-29 22:37:24 +00:00
|
|
|
ParserExpression lambda_p;
|
2021-05-09 09:47:29 +00:00
|
|
|
|
|
|
|
ASTPtr function_name;
|
|
|
|
ASTPtr function_core;
|
|
|
|
|
2021-10-27 08:28:21 +00:00
|
|
|
String cluster_str;
|
2021-10-20 13:04:02 +00:00
|
|
|
bool or_replace = false;
|
|
|
|
bool if_not_exists = false;
|
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
if (!s_create.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
|
2021-10-20 13:04:02 +00:00
|
|
|
if (s_or_replace.ignore(pos, expected))
|
|
|
|
or_replace = true;
|
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
if (!s_function.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
|
2021-10-20 13:04:02 +00:00
|
|
|
if (!or_replace && s_if_not_exists.ignore(pos, expected))
|
|
|
|
if_not_exists = true;
|
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
if (!function_name_p.parse(pos, function_name, expected))
|
|
|
|
return false;
|
|
|
|
|
2021-10-27 08:28:21 +00:00
|
|
|
if (s_on.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
if (!s_as.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!lambda_p.parse(pos, function_core, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto create_function_query = std::make_shared<ASTCreateFunctionQuery>();
|
|
|
|
node = create_function_query;
|
|
|
|
|
2022-01-20 08:23:52 +00:00
|
|
|
create_function_query->function_name = function_name;
|
|
|
|
create_function_query->children.push_back(function_name);
|
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
create_function_query->function_core = function_core;
|
2022-01-20 08:23:52 +00:00
|
|
|
create_function_query->children.push_back(function_core);
|
|
|
|
|
2021-10-20 13:04:02 +00:00
|
|
|
create_function_query->or_replace = or_replace;
|
|
|
|
create_function_query->if_not_exists = if_not_exists;
|
2021-10-27 08:28:21 +00:00
|
|
|
create_function_query->cluster = std::move(cluster_str);
|
2021-05-09 09:47:29 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|