1 | #include <Core/Types.h> |
2 | #include <Common/Exception.h> |
3 | #include <IO/ReadBuffer.h> |
4 | #include <IO/WriteBuffer.h> |
5 | #include <IO/VarInt.h> |
6 | #include <IO/ReadHelpers.h> |
7 | #include <IO/WriteHelpers.h> |
8 | #include <Core/BlockInfo.h> |
9 | |
10 | |
11 | namespace DB |
12 | { |
13 | |
14 | namespace ErrorCodes |
15 | { |
16 | extern const int UNKNOWN_BLOCK_INFO_FIELD; |
17 | } |
18 | |
19 | |
20 | /// Write values in binary form. NOTE: You could use protobuf, but it would be overkill for this case. |
21 | void BlockInfo::write(WriteBuffer & out) const |
22 | { |
23 | /// Set of pairs `FIELD_NUM`, value in binary form. Then 0. |
24 | #define WRITE_FIELD(TYPE, NAME, DEFAULT, FIELD_NUM) \ |
25 | writeVarUInt(FIELD_NUM, out); \ |
26 | writeBinary(NAME, out); |
27 | |
28 | APPLY_FOR_BLOCK_INFO_FIELDS(WRITE_FIELD) |
29 | |
30 | #undef WRITE_FIELD |
31 | writeVarUInt(0, out); |
32 | } |
33 | |
34 | /// Read values in binary form. |
35 | void BlockInfo::read(ReadBuffer & in) |
36 | { |
37 | UInt64 field_num = 0; |
38 | |
39 | while (true) |
40 | { |
41 | readVarUInt(field_num, in); |
42 | if (field_num == 0) |
43 | break; |
44 | |
45 | switch (field_num) |
46 | { |
47 | #define READ_FIELD(TYPE, NAME, DEFAULT, FIELD_NUM) \ |
48 | case FIELD_NUM: \ |
49 | readBinary(NAME, in); \ |
50 | break; |
51 | |
52 | APPLY_FOR_BLOCK_INFO_FIELDS(READ_FIELD) |
53 | |
54 | #undef READ_FIELD |
55 | default: |
56 | throw Exception("Unknown BlockInfo field number: " + toString(field_num), ErrorCodes::UNKNOWN_BLOCK_INFO_FIELD); |
57 | } |
58 | } |
59 | } |
60 | |
61 | void BlockMissingValues::setBit(size_t column_idx, size_t row_idx) |
62 | { |
63 | RowsBitMask & mask = rows_mask_by_column_id[column_idx]; |
64 | mask.resize(row_idx + 1); |
65 | mask[row_idx] = true; |
66 | } |
67 | |
68 | const BlockMissingValues::RowsBitMask & BlockMissingValues::getDefaultsBitmask(size_t column_idx) const |
69 | { |
70 | static RowsBitMask none; |
71 | auto it = rows_mask_by_column_id.find(column_idx); |
72 | if (it != rows_mask_by_column_id.end()) |
73 | return it->second; |
74 | return none; |
75 | } |
76 | |
77 | } |
78 | |