If we receive a block with slightly different column types, or with excessive columns, * we will adapt it to expected structure. */
| 346 | * we will adapt it to expected structure. |
| 347 | */ |
| 348 | static Block adaptBlockStructure(const Block & block, const Block & header) |
| 349 | { |
| 350 | /// Special case when reader doesn't care about result structure. Deprecated and used only in Benchmark, PerformanceTest. |
| 351 | if (header.empty()) |
| 352 | return block; |
| 353 | |
| 354 | Block res; |
| 355 | res.info = block.info; |
| 356 | |
| 357 | for (const auto & elem : header) |
| 358 | { |
| 359 | ColumnPtr column; |
| 360 | |
| 361 | if (elem.column && isColumnConst(*elem.column)) |
| 362 | { |
| 363 | /// We expect constant column in block. |
| 364 | /// If block is not empty, then get value for constant from it, |
| 365 | /// because it may be different for remote server for functions like version(), uptime(), ... |
| 366 | if (block.rows() > 0 && block.has(elem.name)) |
| 367 | { |
| 368 | /// Const column is passed as materialized. Get first value from it. |
| 369 | /// |
| 370 | /// TODO: check that column contains the same value. |
| 371 | /// TODO: serialize const columns. |
| 372 | auto col = block.getByName(elem.name); |
| 373 | if (const auto * blob = typeid_cast<const ColumnBLOB *>(col.column.get())) |
| 374 | col.column = blob->convertFrom(); |
| 375 | col.column = col.column->cut(0, 1); |
| 376 | |
| 377 | column = castColumn(col, elem.type); |
| 378 | |
| 379 | if (!isColumnConst(*column)) |
| 380 | column = ColumnConst::create(column, block.rows()); |
| 381 | else |
| 382 | /// It is not possible now. Just in case we support const columns serialization. |
| 383 | column = column->cloneResized(block.rows()); |
| 384 | } |
| 385 | else |
| 386 | column = elem.column->cloneResized(block.rows()); |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | const auto & col = block.getByName(elem.name); |
| 391 | if (auto * blob = typeid_cast<ColumnBLOB *>(col.column->assumeMutable().get())) |
| 392 | { |
| 393 | blob->addCast(col.type, elem.type); |
| 394 | column = col.column; |
| 395 | } |
| 396 | else |
| 397 | column = castColumn(col, elem.type); |
| 398 | } |
| 399 | |
| 400 | res.insert({column, elem.type, elem.name}); |
| 401 | } |
| 402 | return res; |
| 403 | } |
| 404 | |
| 405 | void RemoteQueryExecutor::sendQuery(ClientInfo::QueryKind query_kind, AsyncCallback async_callback) |
no test coverage detected