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

Method resolve

datafusion/catalog/src/async.rs:266–317  ·  view source on GitHub ↗

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 schema providers (each with their own cache of table providers). This cache will be returned as a synchronous CatalogProvider that can be used to plan and execute a query containing the given references. This cache is i

(
        &self,
        references: &[TableReference],
        config: &SessionConfig,
        catalog_name: &str,
    )

Source from the content-addressed store, hash-verified

264 /// This cache is intended to be short-lived for the execution of a single query. There is no mechanism
265 /// for refresh or eviction of stale entries.
266 async fn resolve(
267 &self,
268 references: &[TableReference],
269 config: &SessionConfig,
270 catalog_name: &str,
271 ) -> Result<Arc<dyn CatalogProvider>> {
272 let mut cached_schemas =
273 HashMap::<String, Option<ResolvedSchemaProviderBuilder>>::new();
274
275 for reference in references {
276 let ref_catalog_name = reference
277 .catalog()
278 .unwrap_or(&config.options().catalog.default_catalog);
279
280 // Maybe this is a reference to some other catalog provided in another way
281 if ref_catalog_name != catalog_name {
282 continue;
283 }
284
285 let schema_name = reference
286 .schema()
287 .unwrap_or(&config.options().catalog.default_schema);
288
289 let schema = if let Some(schema) = cached_schemas.get_mut(schema_name) {
290 schema
291 } else {
292 let resolved_schema = self.schema(schema_name).await?;
293 let resolved_schema = resolved_schema.map(|resolved_schema| {
294 ResolvedSchemaProviderBuilder::new(
295 catalog_name.to_string(),
296 resolved_schema,
297 )
298 });
299 cached_schemas.insert(schema_name.to_string(), resolved_schema);
300 cached_schemas.get_mut(schema_name).unwrap()
301 };
302
303 // If we can't find the catalog don't bother checking the table
304 let Some(schema) = schema else { continue };
305
306 schema.resolve_table(reference.table()).await?;
307 }
308
309 let cached_schemas = cached_schemas
310 .into_iter()
311 .filter_map(|(key, maybe_builder)| {
312 maybe_builder.map(|schema_builder| (key, schema_builder.finish()))
313 })
314 .collect::<HashMap<_, _>>();
315
316 Ok(Arc::new(ResolvedCatalogProvider { cached_schemas }))
317 }
318}
319
320/// A trait for catalog provider lists that must resolve catalogs asynchronously

Callers

nothing calls this directly

Implementers 1

async.rsdatafusion/catalog/src/async.rs

Calls 12

newFunction · 0.85
get_mutMethod · 0.80
resolve_tableMethod · 0.80
catalogMethod · 0.45
optionsMethod · 0.45
schemaMethod · 0.45
mapMethod · 0.45
to_stringMethod · 0.45
insertMethod · 0.45
tableMethod · 0.45
into_iterMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected