#include #include 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(*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); } }