2012-07-17 20:06:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Block.h>
|
|
|
|
#include <Core/SortDescription.h>
|
2012-07-17 20:06:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// Sort one block by `description`. If limit != 0, then the partial sort of the first `limit` rows is produced.
|
2019-02-10 15:17:45 +00:00
|
|
|
void sortBlock(Block & block, const SortDescription & description, UInt64 limit = 0);
|
2012-07-17 20:06:38 +00:00
|
|
|
|
2013-11-29 22:10:15 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/** Used only in StorageMergeTree to sort the data with INSERT.
|
|
|
|
* Sorting is stable. This is important for keeping the order of rows in the CollapsingMergeTree engine
|
|
|
|
* - because based on the order of rows it is determined whether to delete or leave groups of rows when collapsing.
|
|
|
|
* Collations are not supported. Partial sorting is not supported.
|
2014-12-15 04:13:33 +00:00
|
|
|
*/
|
2013-11-29 22:10:15 +00:00
|
|
|
void stableSortBlock(Block & block, const SortDescription & description);
|
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/** Same as stableSortBlock, but do not sort the block, but only calculate the permutation of the values,
|
|
|
|
* so that you can rearrange the column values yourself.
|
2015-08-14 02:45:40 +00:00
|
|
|
*/
|
|
|
|
void stableGetPermutation(const Block & block, const SortDescription & description, IColumn::Permutation & out_permutation);
|
|
|
|
|
2015-11-21 15:47:32 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/** Quickly check whether the block is already sorted. If the block is not sorted - returns false as fast as possible.
|
|
|
|
* Collations are not supported.
|
2015-11-21 15:47:32 +00:00
|
|
|
*/
|
|
|
|
bool isAlreadySorted(const Block & block, const SortDescription & description);
|
|
|
|
|
2018-10-04 10:24:51 +00:00
|
|
|
using ColumnsWithSortDescriptions = std::vector<std::pair<const IColumn *, SortColumnDescription>>;
|
|
|
|
|
|
|
|
ColumnsWithSortDescriptions getColumnsWithSortDescription(const Block & block, const SortDescription & description);
|
|
|
|
|
2012-07-17 20:06:38 +00:00
|
|
|
}
|