| 308 | } |
| 309 | |
| 310 | void MergeTreeDataPartWriterWide::write(const Block & block, const IColumnPermutation * permutation, Block * permuted_columns_cache) |
| 311 | { |
| 312 | Block block_to_write = block; |
| 313 | |
| 314 | /// For some columns the set of streams may depend on the actual column data. |
| 315 | /// For example: dynamic structure and statistics for JSON, Dynamic and Map (with adaptive number of buckets). |
| 316 | /// We must ensure that all blocks will be written in the same set of streams, so we have to make some |
| 317 | /// preparations to achieve it. |
| 318 | prepareBlockForWriting(block_to_write); |
| 319 | |
| 320 | initStreamsIfNeeded(); |
| 321 | initColumnsSubstreamsIfNeeded(); |
| 322 | |
| 323 | /// Fill index granularity for this block |
| 324 | /// if it's unknown (in case of insert data or horizontal merge, |
| 325 | /// but not in case of vertical part of vertical merge) |
| 326 | if (compute_granularity) |
| 327 | { |
| 328 | size_t index_granularity_for_block = 0; |
| 329 | if (auto constant_granularity = index_granularity->getConstantGranularity()) |
| 330 | index_granularity_for_block = *constant_granularity; |
| 331 | else |
| 332 | index_granularity_for_block = computeIndexGranularity(block_to_write); |
| 333 | |
| 334 | if (rows_written_in_last_mark > 0) |
| 335 | { |
| 336 | size_t rows_left_in_last_mark = index_granularity->getMarkRows(getCurrentMark()) - rows_written_in_last_mark; |
| 337 | /// Previous granularity was much bigger than our new block's |
| 338 | /// granularity let's adjust it, because we want add new |
| 339 | /// heavy-weight blocks into small old granule. |
| 340 | if (rows_left_in_last_mark > index_granularity_for_block) |
| 341 | { |
| 342 | /// We have already written more rows than granularity of our block. |
| 343 | /// adjust last mark rows and flush to disk. |
| 344 | if (rows_written_in_last_mark >= index_granularity_for_block) |
| 345 | adjustLastMarkIfNeedAndFlushToDisk(rows_written_in_last_mark); |
| 346 | else /// We still can write some rows from new block into previous granule. So the granule size will be block granularity size. |
| 347 | adjustLastMarkIfNeedAndFlushToDisk(index_granularity_for_block); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | fillIndexGranularity(index_granularity_for_block, block_to_write.rows()); |
| 352 | } |
| 353 | |
| 354 | auto granules_to_write = getGranulesToWrite(*index_granularity, block_to_write.rows(), getCurrentMark(), rows_written_in_last_mark); |
| 355 | |
| 356 | WrittenOffsetSubstreams offset_substreams = written_offset_substreams ? *written_offset_substreams : WrittenOffsetSubstreams{}; |
| 357 | |
| 358 | Block primary_key_block; |
| 359 | if (settings.rewrite_primary_key) |
| 360 | primary_key_block = getIndexBlockAndPermute(block, metadata_snapshot->getPrimaryKeyColumns(), permutation, permuted_columns_cache); |
| 361 | |
| 362 | Block skip_indexes_block = getIndexBlockAndPermute(block, getSkipIndicesColumns(), permutation, permuted_columns_cache); |
| 363 | |
| 364 | auto it = columns_list.begin(); |
| 365 | for (size_t i = 0; i < columns_list.size(); ++i, ++it) |
| 366 | { |
| 367 | auto & column = block_to_write.getByName(it->name); |
nothing calls this directly
no test coverage detected