1#include <Processors/Transforms/PartialSortingTransform.h>
2#include <Interpreters/sortBlock.h>
3
4namespace DB
5{
6
7PartialSortingTransform::PartialSortingTransform(
8 const Block & header_, SortDescription & description_, UInt64 limit_, bool do_count_rows_)
9 : ISimpleTransform(header_, header_, false)
10 , description(description_), limit(limit_), do_count_rows(do_count_rows_)
11{
12}
13
14void PartialSortingTransform::transform(Chunk & chunk)
15{
16 if (do_count_rows)
17 read_rows += chunk.getNumRows();
18
19 auto block = getInputPort().getHeader().cloneWithColumns(chunk.detachColumns());
20 chunk.clear();
21
22 sortBlock(block, description, limit);
23 chunk.setColumns(block.getColumns(), block.rows());
24}
25
26}
27