| 350 | /// batches are provided. |
| 351 | #[expect(clippy::needless_pass_by_value)] |
| 352 | pub fn try_new_from_batches( |
| 353 | schema: SchemaRef, |
| 354 | batches: Vec<RecordBatch>, |
| 355 | ) -> Result<Arc<DataSourceExec>> { |
| 356 | if batches.is_empty() { |
| 357 | return plan_err!("Values list cannot be empty"); |
| 358 | } |
| 359 | |
| 360 | for batch in &batches { |
| 361 | let batch_schema = batch.schema(); |
| 362 | if batch_schema != schema { |
| 363 | return plan_err!( |
| 364 | "Batch has invalid schema. Expected: {}, got: {}", |
| 365 | schema, |
| 366 | batch_schema |
| 367 | ); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | let partitions = vec![batches]; |
| 372 | let source = Self { |
| 373 | partitions, |
| 374 | schema: Arc::clone(&schema), |
| 375 | projected_schema: Arc::clone(&schema), |
| 376 | projection: None, |
| 377 | sort_information: vec![], |
| 378 | show_sizes: true, |
| 379 | fetch: None, |
| 380 | }; |
| 381 | Ok(DataSourceExec::from_data_source(source)) |
| 382 | } |
| 383 | |
| 384 | /// Set the limit of the files |
| 385 | pub fn with_limit(mut self, limit: Option<usize>) -> Self { |