1 | #include "StorageSystemPartsColumns.h" |
2 | |
3 | #include <Common/escapeForFileName.h> |
4 | #include <Columns/ColumnString.h> |
5 | #include <DataTypes/DataTypeString.h> |
6 | #include <DataTypes/DataTypesNumber.h> |
7 | #include <DataTypes/DataTypeDateTime.h> |
8 | #include <DataTypes/DataTypeDate.h> |
9 | #include <DataStreams/OneBlockInputStream.h> |
10 | #include <Storages/VirtualColumnUtils.h> |
11 | #include <Databases/IDatabase.h> |
12 | #include <Parsers/queryToString.h> |
13 | |
14 | namespace DB |
15 | { |
16 | |
17 | |
18 | StorageSystemPartsColumns::StorageSystemPartsColumns(const std::string & name_) |
19 | : StorageSystemPartsBase(name_, |
20 | { |
21 | {"partition" , std::make_shared<DataTypeString>()}, |
22 | {"name" , std::make_shared<DataTypeString>()}, |
23 | {"active" , std::make_shared<DataTypeUInt8>()}, |
24 | {"marks" , std::make_shared<DataTypeUInt64>()}, |
25 | {"rows" , std::make_shared<DataTypeUInt64>()}, |
26 | {"bytes_on_disk" , std::make_shared<DataTypeUInt64>()}, |
27 | {"data_compressed_bytes" , std::make_shared<DataTypeUInt64>()}, |
28 | {"data_uncompressed_bytes" , std::make_shared<DataTypeUInt64>()}, |
29 | {"marks_bytes" , std::make_shared<DataTypeUInt64>()}, |
30 | {"modification_time" , std::make_shared<DataTypeDateTime>()}, |
31 | {"remove_time" , std::make_shared<DataTypeDateTime>()}, |
32 | {"refcount" , std::make_shared<DataTypeUInt32>()}, |
33 | {"min_date" , std::make_shared<DataTypeDate>()}, |
34 | {"max_date" , std::make_shared<DataTypeDate>()}, |
35 | {"partition_id" , std::make_shared<DataTypeString>()}, |
36 | {"min_block_number" , std::make_shared<DataTypeInt64>()}, |
37 | {"max_block_number" , std::make_shared<DataTypeInt64>()}, |
38 | {"level" , std::make_shared<DataTypeUInt32>()}, |
39 | {"data_version" , std::make_shared<DataTypeUInt64>()}, |
40 | {"primary_key_bytes_in_memory" , std::make_shared<DataTypeUInt64>()}, |
41 | {"primary_key_bytes_in_memory_allocated" , std::make_shared<DataTypeUInt64>()}, |
42 | |
43 | {"database" , std::make_shared<DataTypeString>()}, |
44 | {"table" , std::make_shared<DataTypeString>()}, |
45 | {"engine" , std::make_shared<DataTypeString>()}, |
46 | {"disk_name" , std::make_shared<DataTypeString>()}, |
47 | {"path" , std::make_shared<DataTypeString>()}, |
48 | |
49 | {"column" , std::make_shared<DataTypeString>()}, |
50 | {"type" , std::make_shared<DataTypeString>()}, |
51 | {"default_kind" , std::make_shared<DataTypeString>()}, |
52 | {"default_expression" , std::make_shared<DataTypeString>()}, |
53 | {"column_bytes_on_disk" , std::make_shared<DataTypeUInt64>()}, |
54 | {"column_data_compressed_bytes" , std::make_shared<DataTypeUInt64>()}, |
55 | {"column_data_uncompressed_bytes" , std::make_shared<DataTypeUInt64>()}, |
56 | {"column_marks_bytes" , std::make_shared<DataTypeUInt64>()} |
57 | } |
58 | ) |
59 | { |
60 | } |
61 | |
62 | void StorageSystemPartsColumns::processNextStorage(MutableColumns & columns_, const StoragesInfo & info, bool has_state_column) |
63 | { |
64 | /// Prepare information about columns in storage. |
65 | struct ColumnInfo |
66 | { |
67 | String default_kind; |
68 | String default_expression; |
69 | }; |
70 | |
71 | std::unordered_map<String, ColumnInfo> columns_info; |
72 | for (const auto & column : info.storage->getColumns()) |
73 | { |
74 | ColumnInfo column_info; |
75 | if (column.default_desc.expression) |
76 | { |
77 | column_info.default_kind = toString(column.default_desc.kind); |
78 | column_info.default_expression = queryToString(column.default_desc.expression); |
79 | } |
80 | |
81 | columns_info[column.name] = column_info; |
82 | } |
83 | |
84 | /// Go through the list of parts. |
85 | MergeTreeData::DataPartStateVector all_parts_state; |
86 | MergeTreeData::DataPartsVector all_parts; |
87 | all_parts = info.getParts(all_parts_state, has_state_column); |
88 | for (size_t part_number = 0; part_number < all_parts.size(); ++part_number) |
89 | { |
90 | const auto & part = all_parts[part_number]; |
91 | auto part_state = all_parts_state[part_number]; |
92 | auto columns_size = part->getTotalColumnsSize(); |
93 | |
94 | /// For convenience, in returned refcount, don't add references that was due to local variables in this method: all_parts, active_parts. |
95 | auto use_count = part.use_count() - 1; |
96 | auto min_date = part->getMinDate(); |
97 | auto max_date = part->getMaxDate(); |
98 | auto index_size_in_bytes = part->getIndexSizeInBytes(); |
99 | auto index_size_in_allocated_bytes = part->getIndexSizeInAllocatedBytes(); |
100 | |
101 | using State = MergeTreeDataPart::State; |
102 | |
103 | for (const auto & column : part->columns) |
104 | |
105 | { |
106 | size_t j = 0; |
107 | { |
108 | WriteBufferFromOwnString out; |
109 | part->partition.serializeText(*info.data, out, format_settings); |
110 | columns_[j++]->insert(out.str()); |
111 | } |
112 | columns_[j++]->insert(part->name); |
113 | columns_[j++]->insert(part_state == State::Committed); |
114 | columns_[j++]->insert(part->getMarksCount()); |
115 | |
116 | columns_[j++]->insert(part->rows_count); |
117 | columns_[j++]->insert(part->bytes_on_disk.load(std::memory_order_relaxed)); |
118 | columns_[j++]->insert(columns_size.data_compressed); |
119 | columns_[j++]->insert(columns_size.data_uncompressed); |
120 | columns_[j++]->insert(columns_size.marks); |
121 | columns_[j++]->insert(UInt64(part->modification_time)); |
122 | columns_[j++]->insert(UInt64(part->remove_time.load(std::memory_order_relaxed))); |
123 | |
124 | columns_[j++]->insert(UInt64(use_count)); |
125 | |
126 | columns_[j++]->insert(min_date); |
127 | columns_[j++]->insert(max_date); |
128 | columns_[j++]->insert(part->info.partition_id); |
129 | columns_[j++]->insert(part->info.min_block); |
130 | columns_[j++]->insert(part->info.max_block); |
131 | columns_[j++]->insert(part->info.level); |
132 | columns_[j++]->insert(UInt64(part->info.getDataVersion())); |
133 | columns_[j++]->insert(index_size_in_bytes); |
134 | columns_[j++]->insert(index_size_in_allocated_bytes); |
135 | |
136 | columns_[j++]->insert(info.database); |
137 | columns_[j++]->insert(info.table); |
138 | columns_[j++]->insert(info.engine); |
139 | columns_[j++]->insert(part->disk->getName()); |
140 | columns_[j++]->insert(part->getFullPath()); |
141 | |
142 | columns_[j++]->insert(column.name); |
143 | columns_[j++]->insert(column.type->getName()); |
144 | |
145 | auto column_info_it = columns_info.find(column.name); |
146 | if (column_info_it != columns_info.end()) |
147 | { |
148 | columns_[j++]->insert(column_info_it->second.default_kind); |
149 | columns_[j++]->insert(column_info_it->second.default_expression); |
150 | } |
151 | else |
152 | { |
153 | columns_[j++]->insertDefault(); |
154 | columns_[j++]->insertDefault(); |
155 | } |
156 | |
157 | ColumnSize column_size = part->getColumnSize(column.name, *column.type); |
158 | columns_[j++]->insert(column_size.data_compressed + column_size.marks); |
159 | columns_[j++]->insert(column_size.data_compressed); |
160 | columns_[j++]->insert(column_size.data_uncompressed); |
161 | columns_[j++]->insert(column_size.marks); |
162 | |
163 | if (has_state_column) |
164 | columns_[j++]->insert(part->stateString()); |
165 | } |
166 | } |
167 | } |
168 | |
169 | } |
170 | |