(
&self,
mut data: SendableRecordBatchStream,
_context: &Arc<TaskContext>,
)
| 259 | |
| 260 | #[instrument(skip_all, ret(level = Level::DEBUG), err(level = Level::ERROR))] |
| 261 | async fn write_all( |
| 262 | &self, |
| 263 | mut data: SendableRecordBatchStream, |
| 264 | _context: &Arc<TaskContext>, |
| 265 | ) -> Result<u64> { |
| 266 | let num_partitions = self.batches.len(); |
| 267 | |
| 268 | // buffer up the data round robin style into num_partitions |
| 269 | |
| 270 | let mut new_batches = vec![vec![]; num_partitions]; |
| 271 | let mut i = 0; |
| 272 | let mut row_count = 0; |
| 273 | while let Some(batch) = data.next().await.transpose()? { |
| 274 | row_count += batch.num_rows(); |
| 275 | new_batches[i].push(batch); |
| 276 | i = (i + 1) % num_partitions; |
| 277 | } |
| 278 | |
| 279 | // write the outputs into the batches |
| 280 | for (target, mut batches) in self.batches.iter().zip(new_batches.into_iter()) { |
| 281 | // Append all the new batches in one go to minimize locking overhead |
| 282 | target.write().await.append(&mut batches); |
| 283 | } |
| 284 | |
| 285 | Ok(row_count as u64) |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | #[cfg(test)] |
no test coverage detected