| 218 | } |
| 219 | |
| 220 | void executeSubPipeline( |
| 221 | const ASTPtr & query, |
| 222 | ContextMutablePtr query_context, |
| 223 | std::function<void(InterpreterSelectQueryUseOptimizer &)> pre_execute, |
| 224 | std::function<void(Block &)> proc_block) |
| 225 | { |
| 226 | if (!query->as<ASTSelectWithUnionQuery>()) |
| 227 | throw Exception( |
| 228 | ErrorCodes::LOGICAL_ERROR, |
| 229 | "Unrecognized query type '{}' when executing subquery {}", |
| 230 | query->getID(), |
| 231 | query->formatForErrorMessage()); |
| 232 | |
| 233 | std::exception_ptr exception; |
| 234 | auto thread = ThreadFromGlobalPool([query_context = std::move(query_context), &query, pre_execute, proc_block, &exception]() { |
| 235 | try |
| 236 | { |
| 237 | CurrentThread::QueryScope query_scope{query_context}; |
| 238 | { |
| 239 | SelectQueryOptions query_options; |
| 240 | InterpreterSelectQueryUseOptimizer interpreter{query, query_context, query_options}; |
| 241 | auto block_io = interpreter.execute(); |
| 242 | PullingPipelineExecutor executor(block_io.pipeline); |
| 243 | |
| 244 | pre_execute(interpreter); |
| 245 | |
| 246 | Block block; |
| 247 | while (executor.pull(block)) |
| 248 | { |
| 249 | if (block.rows() == 0) |
| 250 | continue; |
| 251 | proc_block(block); |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | catch (...) |
| 256 | { |
| 257 | exception = constructException(query_context); |
| 258 | } |
| 259 | }); |
| 260 | thread.join(); |
| 261 | |
| 262 | if (exception) |
| 263 | std::rethrow_exception(exception); |
| 264 | } |
| 265 | } |
no test coverage detected