(state: &SessionState, opts: DirSchemaOpts<'_>)
| 145 | |
| 146 | impl DirSchema { |
| 147 | async fn create(state: &SessionState, opts: DirSchemaOpts<'_>) -> Result<Arc<Self>> { |
| 148 | let DirSchemaOpts { ext, dir, format } = opts; |
| 149 | let mut tables = HashMap::new(); |
| 150 | let dir_entries = std::fs::read_dir(dir).unwrap(); |
| 151 | for res in dir_entries { |
| 152 | let entry = res.unwrap(); |
| 153 | let filename = entry.file_name().to_str().unwrap().to_string(); |
| 154 | if !filename.ends_with(ext) { |
| 155 | continue; |
| 156 | } |
| 157 | |
| 158 | let table_path = ListingTableUrl::parse(entry.path().to_str().unwrap())?; |
| 159 | let opts = ListingOptions::new(format.clone()); |
| 160 | let conf = ListingTableConfig::new(table_path) |
| 161 | .with_listing_options(opts) |
| 162 | .infer_schema(state) |
| 163 | .await; |
| 164 | |
| 165 | if let Err(err) = conf { |
| 166 | log::error!("Error while inferring schema for {filename}: {err}"); |
| 167 | continue; |
| 168 | } |
| 169 | |
| 170 | let table = ListingTable::try_new(conf?)?; |
| 171 | tables.insert(filename, Arc::new(table) as Arc<dyn TableProvider>); |
| 172 | } |
| 173 | Ok(Arc::new(Self { |
| 174 | tables: RwLock::new(tables), |
| 175 | })) |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | #[async_trait] |
no test coverage detected