From 513d8d1d2afd450416e8dd77cf9be8d634f6550b Mon Sep 17 00:00:00 2001 From: Adrian Tanase Date: Wed, 22 May 2024 18:35:21 +0300 Subject: [PATCH] Docs: add examples for `RuntimeEnv::register_object_store`, improve error messages (#10617) * Docs: add examples for RuntimeEnv::register_object_store * adjust example --------- Co-authored-by: Andrew Lamb --- datafusion/execution/src/object_store.rs | 2 +- datafusion/execution/src/runtime_env.rs | 33 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/datafusion/execution/src/object_store.rs b/datafusion/execution/src/object_store.rs index c0c58a87dcc6..126f83f7e238 100644 --- a/datafusion/execution/src/object_store.rs +++ b/datafusion/execution/src/object_store.rs @@ -212,7 +212,7 @@ impl ObjectStoreRegistry for DefaultObjectStoreRegistry { .map(|o| o.value().clone()) .ok_or_else(|| { DataFusionError::Internal(format!( - "No suitable object store found for {url}" + "No suitable object store found for {url}. See `RuntimeEnv::register_object_store`" )) }) } diff --git a/datafusion/execution/src/runtime_env.rs b/datafusion/execution/src/runtime_env.rs index e78a9e0de9f0..25573d915959 100644 --- a/datafusion/execution/src/runtime_env.rs +++ b/datafusion/execution/src/runtime_env.rs @@ -89,6 +89,39 @@ impl RuntimeEnv { /// scheme, if any. /// /// See [`ObjectStoreRegistry`] for more details + /// + /// # Example: Register local file system object store + /// ``` + /// # use std::sync::Arc; + /// # use url::Url; + /// # use datafusion_execution::runtime_env::RuntimeEnv; + /// # let runtime_env = RuntimeEnv::new(Default::default()).unwrap(); + /// let url = Url::try_from("file://").unwrap(); + /// let object_store = object_store::local::LocalFileSystem::new(); + /// // register the object store with the runtime environment + /// runtime_env.register_object_store(&url, Arc::new(object_store)); + /// ``` + /// + /// # Example: Register local file system object store + /// + /// To register reading from urls such as ` + /// + /// ``` + /// # use std::sync::Arc; + /// # use url::Url; + /// # use datafusion_execution::runtime_env::RuntimeEnv; + /// # let runtime_env = RuntimeEnv::new(Default::default()).unwrap(); + /// # // use local store for example as http feature is not enabled + /// # let http_store = object_store::local::LocalFileSystem::new(); + /// // create a new object store via object_store::http::HttpBuilder; + /// let base_url = Url::parse("https://github.com").unwrap(); + /// // let http_store = HttpBuilder::new() + /// // .with_url(base_url.clone()) + /// // .build() + /// // .unwrap(); + /// // register the object store with the runtime environment + /// runtime_env.register_object_store(&base_url, Arc::new(http_store)); + /// ``` pub fn register_object_store( &self, url: &Url,