Merge row batches from multiple shards into one result set. Rows are concatenated in shard-arrival order (order-independent for an unsorted slice). If `coordinator_limit > 0` the merged list is truncated to at most `coordinator_limit` rows after concatenation — this is the final cut-off after shards have already applied their own per-shard limit via `ArrayShardSliceReq::limit`. Pass `coordinator
(
shard_resps: &[ArrayShardSliceResp],
coordinator_limit: u32,
)
| 107 | /// |
| 108 | /// Pass `coordinator_limit = 0` to return all rows without truncation. |
| 109 | pub fn merge_slice_rows( |
| 110 | shard_resps: &[ArrayShardSliceResp], |
| 111 | coordinator_limit: u32, |
| 112 | ) -> Vec<Vec<u8>> { |
| 113 | let total: usize = shard_resps.iter().map(|r| r.rows_msgpack.len()).sum(); |
| 114 | let cap = if coordinator_limit > 0 { |
| 115 | total.min(coordinator_limit as usize) |
| 116 | } else { |
| 117 | total |
| 118 | }; |
| 119 | let mut merged = Vec::with_capacity(cap); |
| 120 | 'outer: for resp in shard_resps { |
| 121 | for row in &resp.rows_msgpack { |
| 122 | if coordinator_limit > 0 && merged.len() >= coordinator_limit as usize { |
| 123 | break 'outer; |
| 124 | } |
| 125 | merged.push(row.clone()); |
| 126 | } |
| 127 | } |
| 128 | merged |
| 129 | } |
| 130 | |
| 131 | /// Merge per-shard partial aggregates into one result per group-by key. |
| 132 | /// |