MCPcopy Create free account
hub / github.com/apache/datafusion / create

Method create

datafusion-examples/examples/data_io/catalog.rs:147–176  ·  view source on GitHub ↗
(state: &SessionState, opts: DirSchemaOpts<'_>)

Source from the content-addressed store, hash-verified

145
146impl 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]

Callers 1

Calls 8

newFunction · 0.85
read_dirFunction · 0.85
with_listing_optionsMethod · 0.80
to_stringMethod · 0.45
pathMethod · 0.45
cloneMethod · 0.45
infer_schemaMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected