(
state: &dyn Session,
format: &dyn FileFormat,
schema: Option<SchemaRef>,
store_root: &str,
file_name: &str,
projection: Option<Vec<usize>>,
li
| 48 | use crate::test::object_store::local_unpartitioned_file; |
| 49 | |
| 50 | pub async fn scan_format( |
| 51 | state: &dyn Session, |
| 52 | format: &dyn FileFormat, |
| 53 | schema: Option<SchemaRef>, |
| 54 | store_root: &str, |
| 55 | file_name: &str, |
| 56 | projection: Option<Vec<usize>>, |
| 57 | limit: Option<usize>, |
| 58 | ) -> Result<Arc<dyn datafusion_physical_plan::ExecutionPlan>> { |
| 59 | let store = Arc::new(object_store::local::LocalFileSystem::new()) as _; |
| 60 | let meta = local_unpartitioned_file(format!("{store_root}/{file_name}")); |
| 61 | |
| 62 | let file_schema = if let Some(file_schema) = schema { |
| 63 | file_schema |
| 64 | } else { |
| 65 | format |
| 66 | .infer_schema(state, &store, std::slice::from_ref(&meta)) |
| 67 | .await? |
| 68 | }; |
| 69 | |
| 70 | let table_schema = TableSchema::new(file_schema.clone(), vec![]); |
| 71 | |
| 72 | let statistics = format |
| 73 | .infer_stats(state, &store, file_schema.clone(), &meta) |
| 74 | .await?; |
| 75 | |
| 76 | let file_groups = vec![vec![PartitionedFile::new_from_meta(meta)].into()]; |
| 77 | |
| 78 | let exec = format |
| 79 | .create_physical_plan( |
| 80 | state, |
| 81 | FileScanConfigBuilder::new( |
| 82 | ObjectStoreUrl::local_filesystem(), |
| 83 | format.file_source(table_schema), |
| 84 | ) |
| 85 | .with_file_groups(file_groups) |
| 86 | .with_statistics(statistics) |
| 87 | .with_projection_indices(projection)? |
| 88 | .with_limit(limit) |
| 89 | .build(), |
| 90 | ) |
| 91 | .await?; |
| 92 | Ok(exec) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | #[cfg(test)] |
searching dependent graphs…