ClickHouse/dbms/src/DataStreams/LimitBlockInputStream.h

47 lines
1.6 KiB
C++
Raw Normal View History

2011-09-04 21:23:19 +00:00
#pragma once
2010-03-12 18:25:35 +00:00
#include <DataStreams/IBlockInputStream.h>
2019-04-19 13:38:25 +00:00
#include <Common/SharedBlockRowRef.h>
2010-03-12 18:25:35 +00:00
namespace DB
{
2017-05-13 22:19:04 +00:00
/** Implements the LIMIT relational operation.
2010-03-12 18:25:35 +00:00
*/
class LimitBlockInputStream : public IBlockInputStream
2010-03-12 18:25:35 +00:00
{
public:
2017-05-13 22:19:04 +00:00
/** If always_read_till_end = false (by default), then after reading enough data,
* returns an empty block, and this causes the query to be canceled.
* If always_read_till_end = true - reads all the data to the end, but ignores them. This is necessary in rare cases:
* when otherwise, due to the cancellation of the request, we would not have received the data for GROUP BY WITH TOTALS from the remote server.
* If use_limit_as_total_rows_approx = true, then addTotalRowsApprox is called to use the limit in progress & stats
2019-08-22 23:16:00 +00:00
* with_ties = true, when query has WITH TIES modifier. If so, description should be provided
2019-04-19 15:45:42 +00:00
* description lets us know which row we should check for equality
*/
2019-04-19 13:38:25 +00:00
LimitBlockInputStream(
const BlockInputStreamPtr & input, UInt64 limit_, UInt64 offset_,
bool always_read_till_end_ = false, bool use_limit_as_total_rows_approx = false,
bool with_ties_ = false, const SortDescription & description_ = {});
String getName() const override { return "Limit"; }
Block getHeader() const override { return children.at(0)->getHeader(); }
2012-10-20 02:10:47 +00:00
protected:
Block readImpl() override;
2012-10-20 02:10:47 +00:00
2010-03-12 18:25:35 +00:00
private:
2019-02-10 15:17:45 +00:00
UInt64 limit;
2019-02-10 16:22:38 +00:00
UInt64 offset;
UInt64 pos = 0;
bool always_read_till_end;
2019-04-19 13:38:25 +00:00
bool with_ties;
const SortDescription description;
2019-04-19 15:45:42 +00:00
SharedBlockRowRef ties_row_ref;
2010-03-12 18:25:35 +00:00
};
}