| 1 | #include <Parsers/ASTDropAccessEntityQuery.h> | 
|---|---|
| 2 | #include <Common/quoteString.h> | 
| 3 | |
| 4 | |
| 5 | namespace DB | 
| 6 | { | 
| 7 | namespace | 
| 8 | { | 
| 9 | using Kind = ASTDropAccessEntityQuery::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 | |
| 23 | ASTDropAccessEntityQuery::ASTDropAccessEntityQuery(Kind kind_) | 
| 24 | : kind(kind_), keyword(kindToKeyword(kind_)) | 
| 25 | { | 
| 26 | } | 
| 27 | |
| 28 | |
| 29 | String ASTDropAccessEntityQuery::getID(char) const | 
| 30 | { | 
| 31 | return String( "DROP ") + keyword + " query"; | 
| 32 | } | 
| 33 | |
| 34 | |
| 35 | ASTPtr ASTDropAccessEntityQuery::clone() const | 
| 36 | { | 
| 37 | return std::make_shared<ASTDropAccessEntityQuery>(*this); | 
| 38 | } | 
| 39 | |
| 40 | |
| 41 | void ASTDropAccessEntityQuery::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const | 
| 42 | { | 
| 43 | settings.ostr << (settings.hilite ? hilite_keyword : "") | 
| 44 | << "DROP "<< keyword | 
| 45 | << (if_exists ? " IF EXISTS": "") | 
| 46 | << (settings.hilite ? hilite_none : ""); | 
| 47 | |
| 48 | if (kind == Kind::ROW_POLICY) | 
| 49 | { | 
| 50 | bool need_comma = false; | 
| 51 | for (const auto & row_policy_name : row_policies_names) | 
| 52 | { | 
| 53 | if (need_comma) | 
| 54 | settings.ostr << ','; | 
| 55 | need_comma = true; | 
| 56 | const String & database = row_policy_name.database; | 
| 57 | const String & table_name = row_policy_name.table_name; | 
| 58 | const String & policy_name = row_policy_name.policy_name; | 
| 59 | settings.ostr << ' ' << backQuoteIfNeed(policy_name) << (settings.hilite ? hilite_keyword : "") << " ON " | 
| 60 | << (settings.hilite ? hilite_none : "") << (database.empty() ? String{} : backQuoteIfNeed(database) + ".") | 
| 61 | << backQuoteIfNeed(table_name); | 
| 62 | } | 
| 63 | } | 
| 64 | else | 
| 65 | { | 
| 66 | bool need_comma = false; | 
| 67 | for (const auto & name : names) | 
| 68 | { | 
| 69 | if (need_comma) | 
| 70 | settings.ostr << ','; | 
| 71 | need_comma = true; | 
| 72 | settings.ostr << ' ' << backQuoteIfNeed(name); | 
| 73 | } | 
| 74 | } | 
| 75 | } | 
| 76 | } | 
| 77 | 
