1 | #pragma once |
---|---|
2 | |
3 | #include <Parsers/ASTAlterQuery.h> |
4 | #include <Storages/IStorage_fwd.h> |
5 | |
6 | #include <optional> |
7 | #include <unordered_map> |
8 | |
9 | |
10 | namespace DB |
11 | { |
12 | |
13 | class Context; |
14 | class WriteBuffer; |
15 | class ReadBuffer; |
16 | |
17 | /// Represents set of actions which should be applied |
18 | /// to values from set of columns which statisfy predicate. |
19 | struct MutationCommand |
20 | { |
21 | ASTPtr ast; /// The AST of the whole command |
22 | |
23 | enum Type |
24 | { |
25 | EMPTY, /// Not used. |
26 | DELETE, |
27 | UPDATE, |
28 | MATERIALIZE_INDEX |
29 | }; |
30 | |
31 | Type type = EMPTY; |
32 | |
33 | /// WHERE part of mutation |
34 | ASTPtr predicate; |
35 | |
36 | /// Columns with corresponding actions |
37 | std::unordered_map<String, ASTPtr> column_to_update_expression; |
38 | |
39 | /// For MATERIALIZE INDEX |
40 | String index_name; |
41 | ASTPtr partition; |
42 | |
43 | static std::optional<MutationCommand> parse(ASTAlterCommand * command); |
44 | }; |
45 | |
46 | /// Multiple mutation commands, possible from different ALTER queries |
47 | class MutationCommands : public std::vector<MutationCommand> |
48 | { |
49 | public: |
50 | std::shared_ptr<ASTAlterCommandList> ast() const; |
51 | |
52 | void writeText(WriteBuffer & out) const; |
53 | void readText(ReadBuffer & in); |
54 | }; |
55 | |
56 | } |
57 |