| 127 | } |
| 128 | |
| 129 | void writeDbStats(ContextPtr context, const String & db_name, const String & path) |
| 130 | { |
| 131 | DbStats db_stats; |
| 132 | db_stats.set_db_name(db_name); |
| 133 | db_stats.set_version(PROTO_VERSION); |
| 134 | auto catalog = createCatalogAdaptor(context); |
| 135 | auto tables = catalog->getAllTablesID(db_name); |
| 136 | for (auto & table : tables) |
| 137 | { |
| 138 | StatisticsCollector collector(context, catalog, table); |
| 139 | collector.readAllFromCatalog(); |
| 140 | auto table_collection = collector.getTableStats().writeToCollection(); |
| 141 | if (table_collection.empty()) |
| 142 | { |
| 143 | continue; |
| 144 | } |
| 145 | |
| 146 | auto table_pb = db_stats.add_tables(); |
| 147 | table_pb->set_table_name(table.getTableName()); |
| 148 | for (auto & [k, v] : table_collection) |
| 149 | { |
| 150 | table_pb->mutable_blobs()->operator[](static_cast<int64_t>(k)) = v->serialize(); |
| 151 | } |
| 152 | for (auto & [col_name, col_stats] : collector.getColumnsStats()) |
| 153 | { |
| 154 | auto column_pb = table_pb->add_columns(); |
| 155 | auto column_collection = col_stats.writeToCollection(); |
| 156 | if (column_collection.empty()) |
| 157 | { |
| 158 | continue; |
| 159 | } |
| 160 | column_pb->set_column_name(col_name); |
| 161 | for (auto & [k, v] : column_collection) |
| 162 | { |
| 163 | column_pb->mutable_blobs()->operator[](static_cast<int64_t>(k)) = v->serialize(); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | std::ofstream fout(path, std::ios::binary); |
| 168 | db_stats.SerializeToOstream(&fout); |
| 169 | } |
| 170 | void writeDbStatsToJson(ContextPtr context, const String & db_name, const String & folder) |
| 171 | { |
| 172 | DDLDumper ddl_dumper(folder); |
no test coverage detected