ClickHouse/src/Processors/QueryPlan/LimitStep.h

51 lines
1.3 KiB
C++
Raw Normal View History

2020-06-16 18:23:01 +00:00
#pragma once
#include <Processors/QueryPlan/ITransformingStep.h>
#include <Core/SortDescription.h>
namespace DB
{
/// Executes LIMIT. See LimitTransform.
2020-06-16 18:23:01 +00:00
class LimitStep : public ITransformingStep
{
public:
LimitStep(
const DataStream & input_stream_,
size_t limit_, size_t offset_,
bool always_read_till_end_ = false, /// Read all data even if limit is reached. Needed for totals.
bool with_ties_ = false, /// Limit with ties.
2020-06-16 18:23:01 +00:00
SortDescription description_ = {});
String getName() const override { return "Limit"; }
void transformPipeline(QueryPipelineBuilder & pipeline, const BuildQueryPipelineSettings &) override;
2020-06-16 18:23:01 +00:00
void describeActions(JSONBuilder::JSONMap & map) const override;
2020-06-27 14:02:24 +00:00
void describeActions(FormatSettings & settings) const override;
2020-06-24 12:09:01 +00:00
2020-07-29 12:29:20 +00:00
size_t getLimitForSorting() const
{
if (limit > std::numeric_limits<UInt64>::max() - offset)
return 0;
return limit + offset;
}
2020-07-28 14:13:31 +00:00
2020-07-29 11:06:00 +00:00
bool withTies() const { return with_ties; }
2020-06-16 18:23:01 +00:00
private:
void updateOutputStream() override
{
output_stream = createOutputStream(input_streams.front(), input_streams.front().header, getDataStreamTraits());
}
2020-06-16 18:23:01 +00:00
size_t limit;
size_t offset;
bool always_read_till_end;
bool with_ties;
const SortDescription description;
};
}