Repository navigation
Expand file tree
/
Copy pathIProcessor.cpp
More file actions
181 lines (148 loc) · 4.26 KB
/
Copy pathIProcessor.cpp
File metadata and controls
181 lines (148 loc) · 4.26 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <iostream>
#include <Processors/IProcessor.h>
#include <Processors/Port.h>
#include <Processors/QueryPlan/IQueryPlanStep.h>
#include <Common/CurrentThread.h>
#include <IO/WriteHelpers.h>
#include <IO/WriteBufferFromString.h>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
extern const int NOT_IMPLEMENTED;
}
IProcessor::IProcessor()
{
processor_index = CurrentThread::isInitialized() ? CurrentThread::get().getNextPipelineProcessorIndex() : 0;
}
IProcessor::IProcessor(InputPorts inputs_, OutputPorts outputs_) : inputs(std::move(inputs_)), outputs(std::move(outputs_))
{
for (auto & port : inputs)
port.processor = this;
for (auto & port : outputs)
port.processor = this;
processor_index = CurrentThread::isInitialized() ? CurrentThread::get().getNextPipelineProcessorIndex() : 0;
}
void IProcessor::setQueryPlanStep(IQueryPlanStep * step, size_t group)
{
query_plan_step = step;
query_plan_step_group = group;
if (step)
{
plan_step_name = step->getName();
plan_step_description = step->getStepDescription();
step_uniq_id = step->getUniqID();
}
}
IProcessor::Status IProcessor::prepare()
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method 'prepare' is not implemented for {} processor", getName());
}
void IProcessor::work()
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method 'work' is not implemented for {} processor", getName());
}
int IProcessor::schedule()
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method 'schedule' is not implemented for {} processor", getName());
}
Processors IProcessor::expandPipeline()
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method 'expandPipeline' is not implemented for {} processor", getName());
}
void IProcessor::cancel() noexcept
{
bool already_cancelled = is_cancelled.exchange(true, std::memory_order_acq_rel);
if (already_cancelled)
return;
onCancel();
}
UInt64 IProcessor::getInputPortNumber(const InputPort * input_port) const
{
UInt64 number = 0;
for (const auto & port : inputs)
{
if (&port == input_port)
return number;
++number;
}
throw Exception(ErrorCodes::LOGICAL_ERROR, "Can't find input port for {} processor", getName());
}
UInt64 IProcessor::getOutputPortNumber(const OutputPort * output_port) const
{
UInt64 number = 0;
for (const auto & port : outputs)
{
if (&port == output_port)
return number;
++number;
}
throw Exception(ErrorCodes::LOGICAL_ERROR, "Can't find output port for {} processor", getName());
}
IProcessor::ProcessorDataStats IProcessor::getProcessorDataStats() const
{
ProcessorDataStats stats;
for (const auto & input : inputs)
{
stats.input_rows += input.rows;
stats.input_bytes += input.bytes;
}
for (const auto & output : outputs)
{
stats.output_rows += output.rows;
stats.output_bytes += output.bytes;
}
return stats;
}
String IProcessor::debug() const
{
WriteBufferFromOwnString buf;
writeString(getName(), buf);
buf.write('\n');
writeString("inputs (hasData, isFinished):\n", buf);
for (const auto & port : inputs)
{
buf.write('\t');
writeBoolText(port.hasData(), buf);
buf.write(' ');
writeBoolText(port.isFinished(), buf);
buf.write('\n');
}
writeString("outputs (hasData, isNeeded):\n", buf);
for (const auto & port : outputs)
{
buf.write('\t');
writeBoolText(port.hasData(), buf);
buf.write(' ');
writeBoolText(port.isNeeded(), buf);
buf.write('\n');
}
buf.finalize();
return buf.str();
}
void IProcessor::dump() const
{
std::cerr << debug();
}
std::string IProcessor::statusToName(std::optional<Status> status)
{
if (status == std::nullopt)
return "NotStarted";
switch (*status)
{
case Status::NeedData:
return "NeedData";
case Status::PortFull:
return "PortFull";
case Status::Finished:
return "Finished";
case Status::Ready:
return "Ready";
case Status::Async:
return "Async";
case Status::ExpandPipeline:
return "ExpandPipeline";
}
}
}