Creates a cached provider that can be used to execute a query containing given references This method will walk through the references and look them up once, creating a cache of table providers. This cache will be returned as a synchronous TableProvider that can be used to plan and execute a query containing the given references. This cache is intended to be short-lived for the execution of a s
(
&self,
references: &[TableReference],
config: &SessionConfig,
catalog_name: &str,
schema_name: &str,
)
| 199 | /// |
| 200 | /// See the [`AsyncSchemaProvider`] documentation for additional details |
| 201 | async fn resolve( |
| 202 | &self, |
| 203 | references: &[TableReference], |
| 204 | config: &SessionConfig, |
| 205 | catalog_name: &str, |
| 206 | schema_name: &str, |
| 207 | ) -> Result<Arc<dyn SchemaProvider>> { |
| 208 | let mut cached_tables = HashMap::<String, Option<Arc<dyn TableProvider>>>::new(); |
| 209 | |
| 210 | for reference in references { |
| 211 | let ref_catalog_name = reference |
| 212 | .catalog() |
| 213 | .unwrap_or(&config.options().catalog.default_catalog); |
| 214 | |
| 215 | // Maybe this is a reference to some other catalog provided in another way |
| 216 | if ref_catalog_name != catalog_name { |
| 217 | continue; |
| 218 | } |
| 219 | |
| 220 | let ref_schema_name = reference |
| 221 | .schema() |
| 222 | .unwrap_or(&config.options().catalog.default_schema); |
| 223 | |
| 224 | if ref_schema_name != schema_name { |
| 225 | continue; |
| 226 | } |
| 227 | |
| 228 | if !cached_tables.contains_key(reference.table()) { |
| 229 | let resolved_table = self.table(reference.table()).await?; |
| 230 | cached_tables.insert(reference.table().to_string(), resolved_table); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | let cached_tables = cached_tables |
| 235 | .into_iter() |
| 236 | .filter_map(|(key, maybe_value)| maybe_value.map(|value| (key, value))) |
| 237 | .collect(); |
| 238 | |
| 239 | Ok(Arc::new(ResolvedSchemaProvider { |
| 240 | cached_tables, |
| 241 | owner_name: Some(catalog_name.to_string()), |
| 242 | })) |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | /// A trait for catalog providers that must resolve schemas asynchronously |