1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include <Processors/QueryPlan/LimitByStep.h>
#include <Processors/Transforms/LimitByTransform.h>
#include <QueryPipeline/QueryPipelineBuilder.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
static ITransformingStep::Traits getTraits()
{
return ITransformingStep::Traits
{
{
.returns_single_stream = true,
.preserves_number_of_streams = false,
.preserves_sorting = true,
},
{
.preserves_number_of_rows = false,
}
};
}
LimitByStep::LimitByStep(
const DataStream & input_stream_,
size_t group_length_, size_t group_offset_, const Names & columns_)
: ITransformingStep(input_stream_, input_stream_.header, getTraits())
, group_length(group_length_)
, group_offset(group_offset_)
, columns(columns_)
{
}
void LimitByStep::transformPipeline(QueryPipelineBuilder & pipeline, const BuildQueryPipelineSettings &)
{
pipeline.resize(1);
pipeline.addSimpleTransform([&](const Block & header, QueryPipelineBuilder::StreamType stream_type) -> ProcessorPtr
{
if (stream_type != QueryPipelineBuilder::StreamType::Main)
return nullptr;
return std::make_shared<LimitByTransform>(header, group_length, group_offset, columns);
});
}
void LimitByStep::describeActions(FormatSettings & settings) const
{
String prefix(settings.offset, ' ');
settings.out << prefix << "Columns: ";
if (columns.empty())
settings.out << "none\n";
else
{
bool first = true;
for (const auto & column : columns)
{
if (!first)
settings.out << ", ";
first = false;
settings.out << column;
}
settings.out << '\n';
}
settings.out << prefix << "Length " << group_length << '\n';
settings.out << prefix << "Offset " << group_offset << '\n';
}
void LimitByStep::describeActions(JSONBuilder::JSONMap & map) const
{
auto columns_array = std::make_unique<JSONBuilder::JSONArray>();
for (const auto & column : columns)
columns_array->add(column);
map.add("Columns", std::move(columns_array));
map.add("Length", group_length);
map.add("Offset", group_offset);
}
}
|