2020-02-17 02:59:56 +00:00
|
|
|
#include <Parsers/ParserSetRoleQuery.h>
|
|
|
|
#include <Parsers/ASTSetRoleQuery.h>
|
|
|
|
#include <Parsers/CommonParsers.h>
|
2020-03-07 17:37:38 +00:00
|
|
|
#include <Parsers/ASTExtendedRoleSet.h>
|
|
|
|
#include <Parsers/ParserExtendedRoleSet.h>
|
2020-02-17 02:59:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2020-03-07 17:37:38 +00:00
|
|
|
bool parseRoles(IParserBase::Pos & pos, Expected & expected, std::shared_ptr<ASTExtendedRoleSet> & roles)
|
2020-02-17 02:59:56 +00:00
|
|
|
{
|
|
|
|
return IParserBase::wrapParseImpl(pos, [&]
|
|
|
|
{
|
|
|
|
ASTPtr ast;
|
2020-03-07 17:37:38 +00:00
|
|
|
if (!ParserExtendedRoleSet{}.enableCurrentUserKeyword(false).parse(pos, ast, expected))
|
2020-02-17 02:59:56 +00:00
|
|
|
return false;
|
|
|
|
|
2020-03-07 17:37:38 +00:00
|
|
|
roles = typeid_cast<std::shared_ptr<ASTExtendedRoleSet>>(ast);
|
2020-02-17 02:59:56 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-07 17:37:38 +00:00
|
|
|
bool parseToUsers(IParserBase::Pos & pos, Expected & expected, std::shared_ptr<ASTExtendedRoleSet> & to_users)
|
2020-02-17 02:59:56 +00:00
|
|
|
{
|
|
|
|
return IParserBase::wrapParseImpl(pos, [&]
|
|
|
|
{
|
|
|
|
if (!ParserKeyword{"TO"}.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ASTPtr ast;
|
2020-03-07 17:37:38 +00:00
|
|
|
if (!ParserExtendedRoleSet{}.enableAllKeyword(false).parse(pos, ast, expected))
|
2020-02-17 02:59:56 +00:00
|
|
|
return false;
|
|
|
|
|
2020-03-07 17:37:38 +00:00
|
|
|
to_users = typeid_cast<std::shared_ptr<ASTExtendedRoleSet>>(ast);
|
2020-02-17 02:59:56 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ParserSetRoleQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
|
|
|
using Kind = ASTSetRoleQuery::Kind;
|
|
|
|
Kind kind;
|
|
|
|
if (ParserKeyword{"SET ROLE DEFAULT"}.ignore(pos, expected))
|
|
|
|
kind = Kind::SET_ROLE_DEFAULT;
|
|
|
|
else if (ParserKeyword{"SET ROLE"}.ignore(pos, expected))
|
|
|
|
kind = Kind::SET_ROLE;
|
|
|
|
else if (ParserKeyword{"SET DEFAULT ROLE"}.ignore(pos, expected))
|
|
|
|
kind = Kind::SET_DEFAULT_ROLE;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
2020-03-07 17:37:38 +00:00
|
|
|
std::shared_ptr<ASTExtendedRoleSet> roles;
|
|
|
|
std::shared_ptr<ASTExtendedRoleSet> to_users;
|
2020-02-17 02:59:56 +00:00
|
|
|
|
|
|
|
if ((kind == Kind::SET_ROLE) || (kind == Kind::SET_DEFAULT_ROLE))
|
|
|
|
{
|
|
|
|
if (!parseRoles(pos, expected, roles))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (kind == Kind::SET_DEFAULT_ROLE)
|
|
|
|
{
|
|
|
|
if (!parseToUsers(pos, expected, to_users))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto query = std::make_shared<ASTSetRoleQuery>();
|
|
|
|
node = query;
|
|
|
|
|
|
|
|
query->kind = kind;
|
|
|
|
query->roles = std::move(roles);
|
|
|
|
query->to_users = std::move(to_users);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|