mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-19 06:01:57 +00:00
69 lines
1.8 KiB
C++
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';
|
|
}
|
|
}
|
|
|
|
}
|