ClickHouse/dbms/src/Processors/LimitTransform.h

54 lines
1.4 KiB
C++
Raw Normal View History

#pragma once
#include <Processors/IProcessor.h>
2019-08-27 17:48:42 +00:00
#include <Core/SortDescription.h>
namespace DB
{
class LimitTransform : public IProcessor
{
private:
InputPort & input;
OutputPort & output;
size_t limit;
size_t offset;
size_t rows_read = 0; /// including the last read block
bool always_read_till_end;
2019-02-07 18:51:53 +00:00
bool has_block = false;
bool block_processed = false;
Chunk current_chunk;
2019-04-08 14:55:20 +00:00
UInt64 rows_before_limit_at_least = 0;
2019-08-27 17:48:42 +00:00
bool with_ties;
const SortDescription description;
2020-02-28 20:20:39 +00:00
2020-03-02 12:56:47 +00:00
Chunk previous_row_chunk; /// for WITH TIES, contains only sort columns
2019-08-27 17:48:42 +00:00
std::vector<size_t> sort_column_positions;
2020-03-02 12:56:47 +00:00
Chunk makeChunkWithPreviousRow(const Chunk & current_chunk, size_t row_num) const;
2020-02-28 20:20:39 +00:00
ColumnRawPtrs extractSortColumns(const Columns & columns) const;
2020-03-02 12:56:47 +00:00
bool sortColumnsEqualAt(const ColumnRawPtrs & current_chunk_sort_columns, size_t current_chunk_row_num) const;
2019-08-27 17:48:42 +00:00
public:
2019-04-09 10:17:25 +00:00
LimitTransform(
2019-08-03 11:02:40 +00:00
const Block & header_, size_t limit_, size_t offset_,
2019-08-27 17:48:42 +00:00
bool always_read_till_end_ = false, bool with_ties_ = false,
const SortDescription & description_ = {});
String getName() const override { return "Limit"; }
Status prepare() override;
void work() override;
InputPort & getInputPort() { return input; }
OutputPort & getOutputPort() { return output; }
2019-04-08 14:55:20 +00:00
UInt64 getRowsBeforeLimitAtLeast() const { return rows_before_limit_at_least; }
};
}