1#include <Parsers/ASTShowCreateAccessEntityQuery.h>
2#include <Common/quoteString.h>
3
4
5namespace DB
6{
7namespace
8{
9 using Kind = ASTShowCreateAccessEntityQuery::Kind;
10
11 const char * kindToKeyword(Kind kind)
12 {
13 switch (kind)
14 {
15 case Kind::QUOTA: return "QUOTA";
16 case Kind::ROW_POLICY: return "POLICY";
17 }
18 __builtin_unreachable();
19 }
20}
21
22
23ASTShowCreateAccessEntityQuery::ASTShowCreateAccessEntityQuery(Kind kind_)
24 : kind(kind_), keyword(kindToKeyword(kind_))
25{
26}
27
28
29String ASTShowCreateAccessEntityQuery::getID(char) const
30{
31 return String("SHOW CREATE ") + keyword + " query";
32}
33
34
35ASTPtr ASTShowCreateAccessEntityQuery::clone() const
36{
37 return std::make_shared<ASTShowCreateAccessEntityQuery>(*this);
38}
39
40
41void ASTShowCreateAccessEntityQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
42{
43 settings.ostr << (settings.hilite ? hilite_keyword : "")
44 << "SHOW CREATE " << keyword
45 << (settings.hilite ? hilite_none : "");
46
47 if (kind == Kind::ROW_POLICY)
48 {
49 const String & database = row_policy_name.database;
50 const String & table_name = row_policy_name.table_name;
51 const String & policy_name = row_policy_name.policy_name;
52 settings.ostr << ' ' << backQuoteIfNeed(policy_name) << (settings.hilite ? hilite_keyword : "") << " ON "
53 << (settings.hilite ? hilite_none : "") << (database.empty() ? String{} : backQuoteIfNeed(database) + ".")
54 << backQuoteIfNeed(table_name);
55 }
56 else if ((kind == Kind::QUOTA) && current_quota)
57 settings.ostr << (settings.hilite ? hilite_keyword : "") << " CURRENT" << (settings.hilite ? hilite_none : "");
58 else
59 settings.ostr << " " << backQuoteIfNeed(name);
60}
61}
62