ClickHouse/dbms/Parsers/ASTShowCreateAccessEntityQuery.cpp
Ivan 97f2a2213e
Move all folders inside /dbms one level up (#9974)
* Move some code outside dbms/src folder
* Fix paths
2020-04-02 02:51:21 +03:00

68 lines
2.0 KiB
C++

#include <Parsers/ASTShowCreateAccessEntityQuery.h>
#include <Common/quoteString.h>
namespace DB
{
namespace
{
using Kind = ASTShowCreateAccessEntityQuery::Kind;
const char * getKeyword(Kind kind)
{
switch (kind)
{
case Kind::USER: return "USER";
case Kind::ROLE: return "ROLE";
case Kind::QUOTA: return "QUOTA";
case Kind::ROW_POLICY: return "ROW POLICY";
case Kind::SETTINGS_PROFILE: return "SETTINGS PROFILE";
}
__builtin_unreachable();
}
}
ASTShowCreateAccessEntityQuery::ASTShowCreateAccessEntityQuery(Kind kind_)
: kind(kind_)
{
}
String ASTShowCreateAccessEntityQuery::getID(char) const
{
return String("SHOW CREATE ") + getKeyword(kind) + " query";
}
ASTPtr ASTShowCreateAccessEntityQuery::clone() const
{
return std::make_shared<ASTShowCreateAccessEntityQuery>(*this);
}
void ASTShowCreateAccessEntityQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
{
settings.ostr << (settings.hilite ? hilite_keyword : "")
<< "SHOW CREATE " << getKeyword(kind)
<< (settings.hilite ? hilite_none : "");
if (current_user)
{
}
else if (current_quota)
settings.ostr << (settings.hilite ? hilite_keyword : "") << " CURRENT" << (settings.hilite ? hilite_none : "");
else if (kind == Kind::ROW_POLICY)
{
const String & database = row_policy_name.database;
const String & table_name = row_policy_name.table_name;
const String & policy_name = row_policy_name.policy_name;
settings.ostr << ' ' << backQuoteIfNeed(policy_name) << (settings.hilite ? hilite_keyword : "") << " ON "
<< (settings.hilite ? hilite_none : "") << (database.empty() ? String{} : backQuoteIfNeed(database) + ".")
<< backQuoteIfNeed(table_name);
}
else
settings.ostr << " " << backQuoteIfNeed(name);
}
}