| 68 | } |
| 69 | |
| 70 | std::optional<Chunk> RemoteSource::tryGenerate() |
| 71 | { |
| 72 | /// onCancel() will do the cancel if the query was sent. |
| 73 | if (was_query_canceled) |
| 74 | return {}; |
| 75 | |
| 76 | if (!was_query_sent) |
| 77 | { |
| 78 | /// Progress method will be called on Progress packet. |
| 79 | query_executor->setProgressCallback([this](const Progress & value) { progress(value); }); |
| 80 | |
| 81 | /// Get rows_before_limit result for remote query from ProfileInfo packet. |
| 82 | query_executor->setProfileInfoCallback([this](const BlockStreamProfileInfo & info) |
| 83 | { |
| 84 | if (rows_before_limit && info.hasAppliedLimit()) |
| 85 | rows_before_limit->set(info.getRowsBeforeLimit()); |
| 86 | }); |
| 87 | |
| 88 | query_executor->sendQuery(); |
| 89 | |
| 90 | was_query_sent = true; |
| 91 | } |
| 92 | |
| 93 | Block block; |
| 94 | |
| 95 | if (async_read) |
| 96 | { |
| 97 | auto res = query_executor->read(read_context); |
| 98 | if (std::holds_alternative<int>(res)) |
| 99 | { |
| 100 | fd = std::get<int>(res); |
| 101 | is_async_state = true; |
| 102 | return Chunk(); |
| 103 | } |
| 104 | |
| 105 | is_async_state = false; |
| 106 | |
| 107 | block = std::get<Block>(std::move(res)); |
| 108 | } |
| 109 | else |
| 110 | block = query_executor->read(); |
| 111 | |
| 112 | if (!block) |
| 113 | { |
| 114 | query_executor->finish(&read_context); |
| 115 | return {}; |
| 116 | } |
| 117 | |
| 118 | UInt64 num_rows = block.rows(); |
| 119 | Chunk chunk(block.getColumns(), num_rows); |
| 120 | |
| 121 | if (add_aggregation_info) |
| 122 | { |
| 123 | auto info = std::make_shared<AggregatedChunkInfo>(); |
| 124 | info->bucket_num = block.info.bucket_num; |
| 125 | info->is_overflows = block.info.is_overflows; |
| 126 | chunk.setChunkInfo(std::move(info)); |
| 127 | } |
nothing calls this directly
no test coverage detected