1#pragma once
2
3#include <Parsers/IAST.h>
4#include <Access/Quota.h>
5
6
7namespace DB
8{
9class ASTRoleList;
10
11
12/** CREATE QUOTA [IF NOT EXISTS | OR REPLACE] name
13 * [KEYED BY {'none' | 'user name' | 'ip address' | 'client key' | 'client key or user name' | 'client key or ip address'}]
14 * [FOR [RANDOMIZED] INTERVAL number {SECOND | MINUTE | HOUR | DAY}
15 * {[SET] MAX {{QUERIES | ERRORS | RESULT ROWS | RESULT BYTES | READ ROWS | READ BYTES | EXECUTION TIME} = {number | ANY} } [,...] |
16 * [SET] TRACKING} [,...]]
17 * [TO {role [,...] | ALL | ALL EXCEPT role [,...]}]
18 *
19 * ALTER QUOTA [IF EXISTS] name
20 * [RENAME TO new_name]
21 * [KEYED BY {'none' | 'user name' | 'ip address' | 'client key' | 'client key or user name' | 'client key or ip address'}]
22 * [FOR [RANDOMIZED] INTERVAL number {SECOND | MINUTE | HOUR | DAY}
23 * {[SET] MAX {{QUERIES | ERRORS | RESULT ROWS | RESULT BYTES | READ ROWS | READ BYTES | EXECUTION TIME} = {number | ANY} } [,...] |
24 * [SET] TRACKING |
25 * UNSET TRACKING} [,...]]
26 * [TO {role [,...] | ALL | ALL EXCEPT role [,...]}]
27 */
28class ASTCreateQuotaQuery : public IAST
29{
30public:
31 bool alter = false;
32
33 bool if_exists = false;
34 bool if_not_exists = false;
35 bool or_replace = false;
36
37 String name;
38 String new_name;
39
40 using KeyType = Quota::KeyType;
41 std::optional<KeyType> key_type;
42
43 using ResourceType = Quota::ResourceType;
44 using ResourceAmount = Quota::ResourceAmount;
45 static constexpr size_t MAX_RESOURCE_TYPE = Quota::MAX_RESOURCE_TYPE;
46
47 struct Limits
48 {
49 std::optional<ResourceAmount> max[MAX_RESOURCE_TYPE];
50 bool unset_tracking = false;
51 std::chrono::seconds duration = std::chrono::seconds::zero();
52 bool randomize_interval = false;
53 };
54 std::vector<Limits> all_limits;
55
56 std::shared_ptr<ASTRoleList> roles;
57
58 String getID(char) const override;
59 ASTPtr clone() const override;
60 void formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override;
61};
62}
63