1#pragma once
2#include <Processors/ISimpleTransform.h>
3#include <Core/SortDescription.h>
4
5namespace DB
6{
7
8/** Sorts each block individually by the values of the specified columns.
9 * At the moment, not very optimal algorithm is used.
10 */
11class PartialSortingTransform : public ISimpleTransform
12{
13public:
14 /// limit - if not 0, then you can sort each block not completely, but only `limit` first rows by order.
15 /// When count_rows is false, getNumReadRows() will always return 0.
16 PartialSortingTransform(
17 const Block & header_,
18 SortDescription & description_,
19 UInt64 limit_ = 0,
20 bool do_count_rows_ = true);
21
22 String getName() const override { return "PartialSortingTransform"; }
23
24 /// Total num rows passed to transform.
25 UInt64 getNumReadRows() const { return read_rows; }
26
27protected:
28 void transform(Chunk & chunk) override;
29
30private:
31 SortDescription description;
32 UInt64 limit;
33 UInt64 read_rows = 0;
34
35 /// Do we need calculate read_rows value?
36 /// Used to skip total row when count rows_before_limit_at_least.
37 bool do_count_rows;
38};
39
40}
41