| 349 | } |
| 350 | |
| 351 | void sortBlock(Block & block, const SortDescription & description, UInt64 limit, IColumn::PermutationSortStability stability) |
| 352 | { |
| 353 | IColumn::Permutation permutation; |
| 354 | |
| 355 | #ifndef NDEBUG |
| 356 | block.checkNumberOfRows(); |
| 357 | #endif |
| 358 | getBlockSortPermutationImpl(block, description, stability, limit, permutation); |
| 359 | |
| 360 | #ifndef NDEBUG |
| 361 | checkSortedWithPermutation(block, description, limit, permutation); |
| 362 | #endif |
| 363 | |
| 364 | if (permutation.empty()) |
| 365 | return; |
| 366 | |
| 367 | bool is_identity_permutation = isIdentityPermutation(permutation, limit); |
| 368 | if (is_identity_permutation && limit == 0) |
| 369 | return; |
| 370 | |
| 371 | size_t output_rows = limit ? std::min(static_cast<size_t>(limit), permutation.size()) : permutation.size(); |
| 372 | Columns columns = block.getColumns(); |
| 373 | transformColumnsWithSharedIndex( |
| 374 | columns, |
| 375 | [&](const ColumnPtr & col) { return is_identity_permutation ? col->cut(0, output_rows) : col->permute(permutation, limit); }); |
| 376 | block.setColumns(columns); |
| 377 | } |
| 378 | |
| 379 | void stableGetPermutation(const Block & block, const SortDescription & description, IColumn::Permutation & out_permutation) |
| 380 | { |
no test coverage detected