ClickHouse/src/Processors/QueryPlan/LimitStep.cpp
2020-07-27 18:37:43 +03:00

69 lines
1.8 KiB
C++

#include <Processors/QueryPlan/LimitStep.h>
#include <Processors/QueryPipeline.h>
#include <Processors/LimitTransform.h>
#include <IO/Operators.h>
namespace DB
{
static ITransformingStep::DataStreamTraits getTraits()
{
return ITransformingStep::DataStreamTraits
{
.preserves_distinct_columns = true,
.returns_single_stream = false,
.preserves_number_of_streams = true,
.preserves_number_of_rows = false,
.preserves_sorting = true,
};
}
LimitStep::LimitStep(
const DataStream & input_stream_,
size_t limit_, size_t offset_,
bool always_read_till_end_,
bool with_ties_,
SortDescription description_)
: ITransformingStep(input_stream_, input_stream_.header, getTraits())
, limit(limit_), offset(offset_)
, always_read_till_end(always_read_till_end_)
, with_ties(with_ties_), description(std::move(description_))
{
}
void LimitStep::transformPipeline(QueryPipeline & pipeline)
{
auto transform = std::make_shared<LimitTransform>(
pipeline.getHeader(), limit, offset, pipeline.getNumStreams(), always_read_till_end, with_ties, description);
pipeline.addPipe({std::move(transform)});
}
void LimitStep::describeActions(FormatSettings & settings) const
{
String prefix(settings.offset, ' ');
settings.out << prefix << "Limit " << limit << '\n';
settings.out << prefix << "Offset " << offset << '\n';
if (with_ties || always_read_till_end)
{
settings.out << prefix;
String str;
if (with_ties)
settings.out << "WITH TIES";
if (always_read_till_end)
{
if (!with_ties)
settings.out << ", ";
settings.out << "Reads all data";
}
settings.out << '\n';
}
}
}