| 87 | } |
| 88 | |
| 89 | Block executeSubQueryWithOneRow(const String & query, ContextMutablePtr query_context, bool internal, bool tolerate_multi_rows) |
| 90 | { |
| 91 | modifyQueryContext(query_context, internal); |
| 92 | |
| 93 | Block block; |
| 94 | std::exception_ptr exception; |
| 95 | auto thread = ThreadFromGlobalPool([query_context = std::move(query_context), &query, internal, tolerate_multi_rows, &block, &exception]() { |
| 96 | try |
| 97 | { |
| 98 | CurrentThread::QueryScope query_scope{query_context}; |
| 99 | { |
| 100 | auto block_io = executeQuery(query, query_context, internal); |
| 101 | |
| 102 | auto input_stream = block_io.getInputStream(); |
| 103 | input_stream->readPrefix(); |
| 104 | block = input_stream->read(); |
| 105 | |
| 106 | if (!tolerate_multi_rows && block.rows() != 1) |
| 107 | throw Exception(ErrorCodes::TOO_MANY_ROWS, "Unexcepted block"); |
| 108 | |
| 109 | while (const auto & tmp_block = input_stream->read()) |
| 110 | { |
| 111 | if (tmp_block.rows() > 0) |
| 112 | throw Exception(ErrorCodes::TOO_MANY_ROWS, "Unexcepted block"); |
| 113 | } |
| 114 | |
| 115 | input_stream->readSuffix(); |
| 116 | |
| 117 | block_io.onFinish(); |
| 118 | } |
| 119 | } |
| 120 | catch (...) |
| 121 | { |
| 122 | exception = constructException(query_context); |
| 123 | } |
| 124 | }); |
| 125 | thread.join(); |
| 126 | |
| 127 | if (exception) |
| 128 | std::rethrow_exception(exception); |
| 129 | |
| 130 | return block; |
| 131 | } |
| 132 | |
| 133 | void executeSubQuery(const String & query, ContextMutablePtr query_context, std::function<void(Block &)> proc_block, bool internal) |
| 134 | { |
no test coverage detected