1 | #include <Storages/MergeTree/ReplicatedMergeTreeMutationEntry.h> |
---|---|
2 | #include <IO/Operators.h> |
3 | #include <IO/ReadBufferFromString.h> |
4 | #include <IO/WriteBufferFromString.h> |
5 | |
6 | |
7 | namespace DB |
8 | { |
9 | |
10 | void ReplicatedMergeTreeMutationEntry::writeText(WriteBuffer & out) const |
11 | { |
12 | out << "format version: 1\n" |
13 | << "create time: "<< LocalDateTime(create_time ? create_time : time(nullptr)) << "\n" |
14 | << "source replica: "<< source_replica << "\n" |
15 | << "block numbers count: "<< block_numbers.size() << "\n"; |
16 | |
17 | for (const auto & kv : block_numbers) |
18 | { |
19 | const String & partition_id = kv.first; |
20 | Int64 number = kv.second; |
21 | out << partition_id << "\t"<< number << "\n"; |
22 | } |
23 | |
24 | out << "commands: "; |
25 | commands.writeText(out); |
26 | } |
27 | |
28 | void ReplicatedMergeTreeMutationEntry::readText(ReadBuffer & in) |
29 | { |
30 | in >> "format version: 1\n"; |
31 | |
32 | LocalDateTime create_time_dt; |
33 | in >> "create time: ">> create_time_dt >> "\n"; |
34 | create_time = create_time_dt; |
35 | |
36 | in >> "source replica: ">> source_replica >> "\n"; |
37 | |
38 | size_t count; |
39 | in >> "block numbers count: ">> count >> "\n"; |
40 | for (size_t i = 0; i < count; ++i) |
41 | { |
42 | String partition_id; |
43 | Int64 number; |
44 | in >> partition_id >> "\t">> number >> "\n"; |
45 | block_numbers[partition_id] = number; |
46 | } |
47 | |
48 | in >> "commands: "; |
49 | commands.readText(in); |
50 | } |
51 | |
52 | String ReplicatedMergeTreeMutationEntry::toString() const |
53 | { |
54 | WriteBufferFromOwnString out; |
55 | writeText(out); |
56 | return out.str(); |
57 | } |
58 | |
59 | ReplicatedMergeTreeMutationEntry ReplicatedMergeTreeMutationEntry::parse(const String & str, String znode_name) |
60 | { |
61 | ReplicatedMergeTreeMutationEntry res; |
62 | res.znode_name = std::move(znode_name); |
63 | |
64 | ReadBufferFromString in(str); |
65 | res.readText(in); |
66 | assertEOF(in); |
67 | |
68 | return res; |
69 | } |
70 | |
71 | } |
72 |