| 167 | } |
| 168 | |
| 169 | Block executeSubPipelineWithOneRow( |
| 170 | const ASTPtr & query, ContextMutablePtr query_context, std::function<void(InterpreterSelectQueryUseOptimizer &)> pre_execute, bool tolerate_multi_rows) |
| 171 | { |
| 172 | if (!query->as<ASTSelectWithUnionQuery>()) |
| 173 | throw Exception( |
| 174 | ErrorCodes::LOGICAL_ERROR, |
| 175 | "Unrecognized query type '{}' when executing subquery {}", |
| 176 | query->getID(), |
| 177 | query->formatForErrorMessage()); |
| 178 | |
| 179 | Block block; |
| 180 | std::exception_ptr exception; |
| 181 | auto thread = ThreadFromGlobalPool([query_context = std::move(query_context), &query, pre_execute, tolerate_multi_rows, &block, &exception]() { |
| 182 | try |
| 183 | { |
| 184 | CurrentThread::QueryScope query_scope{query_context}; |
| 185 | { |
| 186 | SelectQueryOptions query_options; |
| 187 | InterpreterSelectQueryUseOptimizer interpreter{query, query_context, query_options}; |
| 188 | auto block_io = interpreter.execute(); |
| 189 | PullingPipelineExecutor executor(block_io.pipeline); |
| 190 | |
| 191 | pre_execute(interpreter); |
| 192 | |
| 193 | while (block.rows() == 0 && executor.pull(block)) |
| 194 | ; |
| 195 | |
| 196 | if (!tolerate_multi_rows && block.rows() != 1) |
| 197 | throw Exception(ErrorCodes::TOO_MANY_ROWS, "Unexcepted block"); |
| 198 | |
| 199 | Block tmp_block; |
| 200 | while (tmp_block.rows() == 0 && executor.pull(tmp_block)) |
| 201 | { |
| 202 | if (tmp_block.rows() > 0) |
| 203 | throw Exception(ErrorCodes::TOO_MANY_ROWS, "Unexcepted block"); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | catch (...) |
| 208 | { |
| 209 | exception = constructException(query_context); |
| 210 | } |
| 211 | }); |
| 212 | thread.join(); |
| 213 | |
| 214 | if (exception) |
| 215 | std::rethrow_exception(exception); |
| 216 | |
| 217 | return block; |
| 218 | } |
| 219 | |
| 220 | void executeSubPipeline( |
| 221 | const ASTPtr & query, |
no test coverage detected