Collect the results of the `FileStream`
(self)
| 291 | |
| 292 | /// Collect the results of the `FileStream` |
| 293 | pub async fn result(self) -> Result<Vec<RecordBatch>> { |
| 294 | let file_schema = self |
| 295 | .opener |
| 296 | .records |
| 297 | .first() |
| 298 | .map(|batch| batch.schema()) |
| 299 | .unwrap_or_else(|| Arc::new(Schema::empty())); |
| 300 | |
| 301 | // let ctx = SessionContext::new(); |
| 302 | let mock_files: Vec<(String, u64)> = (0..self.num_files) |
| 303 | .map(|idx| (format!("mock_file{idx}"), 10_u64)) |
| 304 | .collect(); |
| 305 | |
| 306 | // let mock_files_ref: Vec<(&str, u64)> = mock_files |
| 307 | // .iter() |
| 308 | // .map(|(name, size)| (name.as_str(), *size)) |
| 309 | // .collect(); |
| 310 | |
| 311 | let file_group = mock_files |
| 312 | .into_iter() |
| 313 | .map(|(name, size)| PartitionedFile::new(name, size)) |
| 314 | .collect(); |
| 315 | |
| 316 | let on_error = self.on_error; |
| 317 | |
| 318 | let table_schema = TableSchema::new(file_schema, vec![]); |
| 319 | let config = FileScanConfigBuilder::new( |
| 320 | ObjectStoreUrl::parse("test:///").unwrap(), |
| 321 | Arc::new(MockSource::new(table_schema)), |
| 322 | ) |
| 323 | .with_file_group(file_group) |
| 324 | .with_limit(self.limit) |
| 325 | .build(); |
| 326 | let metrics_set = ExecutionPlanMetricsSet::new(); |
| 327 | let file_stream = FileStreamBuilder::new(&config) |
| 328 | .with_partition(0) |
| 329 | .with_file_opener(Arc::new(self.opener)) |
| 330 | .with_metrics(&metrics_set) |
| 331 | .with_on_error(on_error) |
| 332 | .build()?; |
| 333 | |
| 334 | file_stream |
| 335 | .collect::<Vec<_>>() |
| 336 | .await |
| 337 | .into_iter() |
| 338 | .collect::<Result<Vec<_>>>() |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | /// helper that creates a stream of 2 files with the same pair of batches in each ([0,1,2] and [0,1]) |
no test coverage detected