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

Function register_object_store_and_config_extensions

datafusion-cli/src/exec.rs:476–516  ·  view source on GitHub ↗

Asynchronously registers an object store and its configuration extensions to the session context. This function dynamically registers a cloud object store based on the given location and options. It first parses the location to determine the scheme and constructs the URL accordingly. Depending on the scheme, it also registers relevant options. The function then alters the default table options wi

(
    ctx: &dyn CliSessionContext,
    location: &String,
    options: &HashMap<String, String>,
    format: Option<ConfigFileType>,
    resolve_region: bool,
)

Source from the content-addressed store, hash-verified

474/// alteration fails, or if the object store cannot be retrieved and registered
475/// successfully.
476pub(crate) async fn register_object_store_and_config_extensions(
477 ctx: &dyn CliSessionContext,
478 location: &String,
479 options: &HashMap<String, String>,
480 format: Option<ConfigFileType>,
481 resolve_region: bool,
482) -> Result<()> {
483 // Parse the location URL to extract the scheme and other components
484 let table_path = ListingTableUrl::parse(location)?;
485
486 // Extract the scheme (e.g., "s3", "gcs") from the parsed URL
487 let scheme = table_path.scheme();
488
489 // Obtain a reference to the URL
490 let url = table_path.as_ref();
491
492 // Register the options based on the scheme extracted from the location
493 ctx.register_table_options_extension_from_scheme(scheme);
494
495 // Clone and modify the default table options based on the provided options
496 let mut table_options = ctx.session_state().default_table_options();
497 if let Some(format) = format {
498 table_options.set_config_format(format);
499 }
500 table_options.alter_with_string_hash_map(options)?;
501
502 // Retrieve the appropriate object store based on the scheme, URL, and modified table options
503 let store = get_object_store(
504 &ctx.session_state(),
505 scheme,
506 url,
507 &table_options,
508 resolve_region,
509 )
510 .await?;
511
512 // Register the retrieved object store in the session context's runtime environment
513 ctx.register_object_store(url, store);
514
515 Ok(())
516}
517
518#[cfg(test)]
519mod tests {

Callers 3

create_planFunction · 0.85
copy_to_table_testFunction · 0.85

Calls 9

get_object_storeFunction · 0.85
schemeMethod · 0.80
set_config_formatMethod · 0.80
as_refMethod · 0.45
default_table_optionsMethod · 0.45
session_stateMethod · 0.45
register_object_storeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…