| 1 | #pragma once | 
|---|
| 2 |  | 
|---|
| 3 | #include <Core/Block.h> | 
|---|
| 4 | #include <Core/SortDescription.h> | 
|---|
| 5 |  | 
|---|
| 6 |  | 
|---|
| 7 | namespace DB | 
|---|
| 8 | { | 
|---|
| 9 |  | 
|---|
| 10 | /// Sort one block by `description`. If limit != 0, then the partial sort of the first `limit` rows is produced. | 
|---|
| 11 | void sortBlock(Block & block, const SortDescription & description, UInt64 limit = 0); | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 | /** Used only in StorageMergeTree to sort the data with INSERT. | 
|---|
| 15 | * Sorting is stable. This is important for keeping the order of rows in the CollapsingMergeTree engine | 
|---|
| 16 | *  - because based on the order of rows it is determined whether to delete or leave groups of rows when collapsing. | 
|---|
| 17 | * Collations are not supported. Partial sorting is not supported. | 
|---|
| 18 | */ | 
|---|
| 19 | void stableSortBlock(Block & block, const SortDescription & description); | 
|---|
| 20 |  | 
|---|
| 21 | /** Same as stableSortBlock, but do not sort the block, but only calculate the permutation of the values, | 
|---|
| 22 | *  so that you can rearrange the column values yourself. | 
|---|
| 23 | */ | 
|---|
| 24 | void stableGetPermutation(const Block & block, const SortDescription & description, IColumn::Permutation & out_permutation); | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 | /** Quickly check whether the block is already sorted. If the block is not sorted - returns false as fast as possible. | 
|---|
| 28 | * Collations are not supported. | 
|---|
| 29 | */ | 
|---|
| 30 | bool isAlreadySorted(const Block & block, const SortDescription & description); | 
|---|
| 31 |  | 
|---|
| 32 | /// Column with description for sort | 
|---|
| 33 | struct ColumnWithSortDescription | 
|---|
| 34 | { | 
|---|
| 35 | const IColumn * column; | 
|---|
| 36 | SortColumnDescription description; | 
|---|
| 37 |  | 
|---|
| 38 | /// It means, that this column is ColumnConst | 
|---|
| 39 | bool column_const = false; | 
|---|
| 40 | }; | 
|---|
| 41 |  | 
|---|
| 42 | using ColumnsWithSortDescriptions = std::vector<ColumnWithSortDescription>; | 
|---|
| 43 |  | 
|---|
| 44 | ColumnsWithSortDescriptions getColumnsWithSortDescription(const Block & block, const SortDescription & description); | 
|---|
| 45 |  | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|