1 | #include "Progress.h" |
2 | |
3 | #include <IO/ReadBuffer.h> |
4 | #include <IO/WriteBuffer.h> |
5 | #include <IO/ReadHelpers.h> |
6 | #include <IO/WriteHelpers.h> |
7 | |
8 | |
9 | namespace DB |
10 | { |
11 | void ProgressValues::read(ReadBuffer & in, UInt64 server_revision) |
12 | { |
13 | size_t new_read_rows = 0; |
14 | size_t new_read_bytes = 0; |
15 | size_t new_total_rows_to_read = 0; |
16 | size_t new_written_rows = 0; |
17 | size_t new_written_bytes = 0; |
18 | |
19 | readVarUInt(new_read_rows, in); |
20 | readVarUInt(new_read_bytes, in); |
21 | readVarUInt(new_total_rows_to_read, in); |
22 | if (server_revision >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO) |
23 | { |
24 | readVarUInt(new_written_rows, in); |
25 | readVarUInt(new_written_bytes, in); |
26 | } |
27 | |
28 | this->read_rows = new_read_rows; |
29 | this->read_bytes = new_read_bytes; |
30 | this->total_rows_to_read = new_total_rows_to_read; |
31 | this->written_rows = new_written_rows; |
32 | this->written_bytes = new_written_bytes; |
33 | } |
34 | |
35 | |
36 | void ProgressValues::write(WriteBuffer & out, UInt64 client_revision) const |
37 | { |
38 | writeVarUInt(this->read_rows, out); |
39 | writeVarUInt(this->read_bytes, out); |
40 | writeVarUInt(this->total_rows_to_read, out); |
41 | if (client_revision >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO) |
42 | { |
43 | writeVarUInt(this->written_rows, out); |
44 | writeVarUInt(this->written_bytes, out); |
45 | } |
46 | } |
47 | |
48 | void ProgressValues::writeJSON(WriteBuffer & out) const |
49 | { |
50 | /// Numbers are written in double quotes (as strings) to avoid loss of precision |
51 | /// of 64-bit integers after interpretation by JavaScript. |
52 | |
53 | writeCString("{\"read_rows\":\"" , out); |
54 | writeText(this->read_rows, out); |
55 | writeCString("\",\"read_bytes\":\"" , out); |
56 | writeText(this->read_bytes, out); |
57 | writeCString("\",\"written_rows\":\"" , out); |
58 | writeText(this->written_rows, out); |
59 | writeCString("\",\"written_bytes\":\"" , out); |
60 | writeText(this->written_bytes, out); |
61 | writeCString("\",\"total_rows_to_read\":\"" , out); |
62 | writeText(this->total_rows_to_read, out); |
63 | writeCString("\"}" , out); |
64 | } |
65 | |
66 | void Progress::read(ReadBuffer & in, UInt64 server_revision) |
67 | { |
68 | ProgressValues values; |
69 | values.read(in, server_revision); |
70 | |
71 | read_rows.store(values.read_rows, std::memory_order_relaxed); |
72 | read_bytes.store(values.read_bytes, std::memory_order_relaxed); |
73 | total_rows_to_read.store(values.total_rows_to_read, std::memory_order_relaxed); |
74 | written_rows.store(values.written_rows, std::memory_order_relaxed); |
75 | written_bytes.store(values.written_bytes, std::memory_order_relaxed); |
76 | } |
77 | |
78 | void Progress::write(WriteBuffer & out, UInt64 client_revision) const |
79 | { |
80 | getValues().write(out, client_revision); |
81 | } |
82 | |
83 | void Progress::writeJSON(WriteBuffer & out) const |
84 | { |
85 | getValues().writeJSON(out); |
86 | } |
87 | |
88 | } |
89 | |