| 155 | } |
| 156 | |
| 157 | std::optional<Chunk> RemoteSource::tryGenerate() |
| 158 | { |
| 159 | /// onCancel() will do the cancel if the query was sent. |
| 160 | if (isCancelled()) |
| 161 | return {}; |
| 162 | |
| 163 | if (!was_query_sent) |
| 164 | { |
| 165 | if (async_query_sending) |
| 166 | { |
| 167 | int fd_ = query_executor->sendQueryAsync(); |
| 168 | if (fd_ >= 0) |
| 169 | { |
| 170 | fd = fd_; |
| 171 | is_async_state = true; |
| 172 | return Chunk(); |
| 173 | } |
| 174 | |
| 175 | is_async_state = false; |
| 176 | } |
| 177 | else |
| 178 | { |
| 179 | query_executor->sendQuery(); |
| 180 | } |
| 181 | |
| 182 | was_query_sent = true; |
| 183 | } |
| 184 | |
| 185 | Block block; |
| 186 | |
| 187 | if (async_read) |
| 188 | { |
| 189 | auto res = query_executor->readAsync(); |
| 190 | |
| 191 | if (res.getType() == RemoteQueryExecutor::ReadResult::Type::Nothing) |
| 192 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Got an empty packet from the RemoteQueryExecutor. This is a bug"); |
| 193 | |
| 194 | if (res.getType() == RemoteQueryExecutor::ReadResult::Type::FileDescriptor) |
| 195 | { |
| 196 | fd = res.getFileDescriptor(); |
| 197 | is_async_state = true; |
| 198 | return Chunk(); |
| 199 | } |
| 200 | |
| 201 | if (res.getType() == RemoteQueryExecutor::ReadResult::Type::ParallelReplicasToken) |
| 202 | { |
| 203 | is_async_state = false; |
| 204 | return Chunk(); |
| 205 | } |
| 206 | |
| 207 | is_async_state = false; |
| 208 | |
| 209 | block = res.getBlock(); |
| 210 | } |
| 211 | else |
| 212 | block = query_executor->readBlock(); |
| 213 | |
| 214 | if (block.empty()) |
nothing calls this directly
no test coverage detected