Stream the batches that were written to the work table.
(
&self,
partition: usize,
_context: Arc<TaskContext>,
)
| 194 | |
| 195 | /// Stream the batches that were written to the work table. |
| 196 | fn execute( |
| 197 | &self, |
| 198 | partition: usize, |
| 199 | _context: Arc<TaskContext>, |
| 200 | ) -> Result<SendableRecordBatchStream> { |
| 201 | // WorkTable streams must be the plan base. |
| 202 | assert_eq_or_internal_err!( |
| 203 | partition, |
| 204 | 0, |
| 205 | "WorkTableExec got an invalid partition {partition} (expected 0)" |
| 206 | ); |
| 207 | let ReservedBatches { |
| 208 | mut batches, |
| 209 | reservation, |
| 210 | } = self.work_table.take()?; |
| 211 | if let Some(projection) = &self.projection { |
| 212 | // We apply the projection |
| 213 | // TODO: it would be better to apply it as soon as possible and not only here |
| 214 | // TODO: an aggressive projection makes the memory reservation smaller, even if we do not edit it |
| 215 | batches = batches |
| 216 | .into_iter() |
| 217 | .map(|b| b.project(projection)) |
| 218 | .collect::<Result<Vec<_>, _>>()?; |
| 219 | } |
| 220 | |
| 221 | let stream = MemoryStream::try_new(batches, Arc::clone(&self.schema), None)? |
| 222 | .with_reservation(reservation); |
| 223 | Ok(Box::pin(cooperative(stream))) |
| 224 | } |
| 225 | |
| 226 | fn metrics(&self) -> Option<MetricsSet> { |
| 227 | Some(self.metrics.clone_inner()) |