| 274 | } |
| 275 | |
| 276 | static void incrementProfileEventsBlock(Block & dst, const Block & src) |
| 277 | { |
| 278 | if (dst.empty()) |
| 279 | { |
| 280 | dst = src.cloneEmpty(); |
| 281 | } |
| 282 | |
| 283 | assertBlocksHaveEqualStructure(src, dst, "ProfileEvents"); |
| 284 | |
| 285 | std::unordered_map<String, size_t> name_pos; |
| 286 | for (size_t i = 0; i < dst.columns(); ++i) |
| 287 | name_pos[dst.getByPosition(i).name] = i; |
| 288 | |
| 289 | size_t dst_rows = dst.rows(); |
| 290 | MutableColumns mutable_columns = dst.mutateColumns(); |
| 291 | |
| 292 | auto & dst_column_host_name = typeid_cast<ColumnString &>(*mutable_columns[name_pos["host_name"]]); |
| 293 | auto & dst_array_current_time = typeid_cast<ColumnUInt32 &>(*mutable_columns[name_pos["current_time"]]).getData(); |
| 294 | auto & dst_array_type = typeid_cast<ColumnInt8 &>(*mutable_columns[name_pos["type"]]).getData(); |
| 295 | auto & dst_column_name = typeid_cast<ColumnString &>(*mutable_columns[name_pos["name"]]); |
| 296 | auto & dst_array_value = typeid_cast<ColumnInt64 &>(*mutable_columns[name_pos["value"]]).getData(); |
| 297 | |
| 298 | const auto & src_column_host_name = typeid_cast<const ColumnString &>(*src.getByName("host_name").column); |
| 299 | const auto & src_array_current_time = typeid_cast<const ColumnUInt32 &>(*src.getByName("current_time").column).getData(); |
| 300 | const auto & src_array_thread_id = typeid_cast<const ColumnUInt64 &>(*src.getByName("thread_id").column).getData(); |
| 301 | const auto & src_column_name = typeid_cast<const ColumnString &>(*src.getByName("name").column); |
| 302 | const auto & src_array_value = typeid_cast<const ColumnInt64 &>(*src.getByName("value").column).getData(); |
| 303 | |
| 304 | struct Id |
| 305 | { |
| 306 | std::string_view name; |
| 307 | std::string_view host_name; |
| 308 | |
| 309 | bool operator<(const Id & rhs) const |
| 310 | { |
| 311 | return std::tie(name, host_name) |
| 312 | < std::tie(rhs.name, rhs.host_name); |
| 313 | } |
| 314 | }; |
| 315 | std::map<Id, UInt64> rows_by_name; |
| 316 | |
| 317 | for (size_t src_row = 0; src_row < src.rows(); ++src_row) |
| 318 | { |
| 319 | /// Filter out threads stats, use stats from thread group |
| 320 | /// Exactly stats from thread group is stored to the table system.query_log |
| 321 | /// The stats from threads are less useful. |
| 322 | /// They take more records, they need to be combined, |
| 323 | /// there even could be several records from one thread. |
| 324 | /// Server doesn't send it any more to the clients, so this code left for compatible |
| 325 | auto thread_id = src_array_thread_id[src_row]; |
| 326 | if (thread_id != THREAD_GROUP_ID) |
| 327 | continue; |
| 328 | |
| 329 | Id id{ |
| 330 | src_column_name.getDataAt(src_row), |
| 331 | src_column_host_name.getDataAt(src_row), |
| 332 | }; |
| 333 | rows_by_name[id] = src_row; |
no test coverage detected