| 48 | } |
| 49 | |
| 50 | void PartitionedBlockOutputStream::write(const Block & block) |
| 51 | { |
| 52 | const auto & columns_with_type_and_name = block.getColumnsWithTypeAndName(); |
| 53 | const auto & columns = block.getColumns(); |
| 54 | |
| 55 | Block block_with_partition_by_expr = sample_block.cloneWithoutColumns(); |
| 56 | block_with_partition_by_expr.setColumns(columns); |
| 57 | partition_by_expr->execute(block_with_partition_by_expr); |
| 58 | |
| 59 | const auto * partition_by_result_column = block_with_partition_by_expr.getByName(partition_by_column_name).column.get(); |
| 60 | |
| 61 | size_t rows_size = block.rows(); |
| 62 | block_row_index_to_partition_index.resize(rows_size); |
| 63 | |
| 64 | partition_id_to_block_index.clear(); |
| 65 | |
| 66 | for (size_t row = 0; row < rows_size; ++row) |
| 67 | { |
| 68 | auto partition_key = partition_by_result_column->getDataAt(row); |
| 69 | auto [it, inserted] = partition_id_to_block_index.insert(makePairNoInit(partition_key, partition_id_to_block_index.size())); |
| 70 | if (inserted) |
| 71 | it->value.first = copyStringInArena(partition_keys_arena, partition_key); |
| 72 | |
| 73 | block_row_index_to_partition_index[row] = it->getMapped(); |
| 74 | } |
| 75 | |
| 76 | size_t columns_size = columns.size(); |
| 77 | size_t partitions_size = partition_id_to_block_index.size(); |
| 78 | |
| 79 | Blocks partition_index_to_block; |
| 80 | partition_index_to_block.reserve(partitions_size); |
| 81 | |
| 82 | for (size_t column_index = 0; column_index < columns_size; ++column_index) |
| 83 | { |
| 84 | MutableColumns partition_index_to_column_split |
| 85 | = columns[column_index]->scatter(partitions_size, block_row_index_to_partition_index); |
| 86 | |
| 87 | /// add empty block into partition_index_to_block in first loop |
| 88 | if (column_index == 0) |
| 89 | { |
| 90 | size_t size = 0; |
| 91 | while (size++ < partitions_size) |
| 92 | { |
| 93 | partition_index_to_block.emplace_back(Block()); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | auto type = columns_with_type_and_name[column_index].type; |
| 98 | auto name = columns_with_type_and_name[column_index].name; |
| 99 | for (size_t partition_index = 0; partition_index < partitions_size; ++partition_index) |
| 100 | { |
| 101 | ColumnWithTypeAndName column_with_type_and_name(std::move(partition_index_to_column_split[partition_index]), type, name); |
| 102 | partition_index_to_block[partition_index].insert(std::move(column_with_type_and_name)); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | for (const auto & partition : partition_id_to_block_index) |
| 107 | { |
nothing calls this directly
no test coverage detected