ClickHouse/src/Processors/QueryPlan/LimitStep.h
2022-06-27 13:16:52 +02:00

51 lines
1.3 KiB
C++

#pragma once
#include <Processors/QueryPlan/ITransformingStep.h>
#include <Core/SortDescription.h>
namespace DB
{
/// Executes LIMIT. See LimitTransform.
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.
SortDescription description_ = {});
String getName() const override { return "Limit"; }
void transformPipeline(QueryPipelineBuilder & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
size_t getLimitForSorting() const
{
if (limit > std::numeric_limits<UInt64>::max() - offset)
return 0;
return limit + offset;
}
bool withTies() const { return with_ties; }
private:
void updateOutputStream() override
{
output_stream = createOutputStream(input_streams.front(), input_streams.front().header, getDataStreamTraits());
}
size_t limit;
size_t offset;
bool always_read_till_end;
bool with_ties;
const SortDescription description;
};
}