1#pragma once
2
3#include <Processors/IProcessor.h>
4#include <Processors/SharedChunk.h>
5#include <Core/SortDescription.h>
6
7namespace DB
8{
9
10class LimitTransform : public IProcessor
11{
12private:
13 InputPort & input;
14 OutputPort & output;
15
16 size_t limit;
17 size_t offset;
18 size_t rows_read = 0; /// including the last read block
19 bool always_read_till_end;
20
21 bool has_block = false;
22 bool block_processed = false;
23 Chunk current_chunk;
24
25 UInt64 rows_before_limit_at_least = 0;
26
27 bool with_ties;
28 const SortDescription description;
29 SharedChunkRowRef ties_row_ref;
30
31 std::vector<size_t> sort_column_positions;
32 ColumnRawPtrs extractSortColumns(const Columns & columns);
33
34public:
35 LimitTransform(
36 const Block & header_, size_t limit_, size_t offset_,
37 bool always_read_till_end_ = false, bool with_ties_ = false,
38 const SortDescription & description_ = {});
39
40 String getName() const override { return "Limit"; }
41
42 Status prepare() override;
43 void work() override;
44
45 InputPort & getInputPort() { return input; }
46 OutputPort & getOutputPort() { return output; }
47
48 UInt64 getRowsBeforeLimitAtLeast() const { return rows_before_limit_at_least; }
49};
50
51}
52