| 145 | } |
| 146 | |
| 147 | void QueryPlan::addStep(QueryPlanStepPtr step, PlanNodes children) |
| 148 | { |
| 149 | (void)children; |
| 150 | checkNotCompleted(); |
| 151 | |
| 152 | size_t num_input_streams = step->getInputStreams().size(); |
| 153 | if (num_input_streams == 0) |
| 154 | { |
| 155 | if (isInitialized()) |
| 156 | throw Exception( |
| 157 | "Cannot add step " + step->getName() |
| 158 | + " to QueryPlan because " |
| 159 | "step has no inputs, but QueryPlan is already initialized", |
| 160 | ErrorCodes::LOGICAL_ERROR); |
| 161 | |
| 162 | nodes.emplace_back(Node{.step = std::move(step)}); |
| 163 | root = &nodes.back(); |
| 164 | return; |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | if (!isInitialized()) |
| 169 | throw Exception( |
| 170 | "Cannot add step " + step->getName() |
| 171 | + " to QueryPlan because " |
| 172 | "step has input, but QueryPlan is not initialized", |
| 173 | ErrorCodes::LOGICAL_ERROR); |
| 174 | |
| 175 | const auto & root_header = root->step->getOutputStream().header; |
| 176 | const auto & step_header = step->getInputStreams().front().header; |
| 177 | if (!blocksHaveEqualStructure(root_header, step_header)) |
| 178 | throw Exception( |
| 179 | "Cannot add step " + step->getName() |
| 180 | + " to QueryPlan because " |
| 181 | "it has incompatible header with root step " |
| 182 | + root->step->getName() |
| 183 | + " " |
| 184 | "root header: " |
| 185 | + root_header.dumpStructure() + "step header: " + step_header.dumpStructure(), |
| 186 | ErrorCodes::LOGICAL_ERROR); |
| 187 | |
| 188 | nodes.emplace_back(Node{.step = std::move(step), .children = {root}}); |
| 189 | root = &nodes.back(); |
| 190 | return; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | void QueryPlan::addNode(Node && node_) |
| 195 | { |
no test coverage detected