From 36b2829877527bea4c6398f3125fbfd340254256 Mon Sep 17 00:00:00 2001 From: Adrian Tanase Date: Wed, 22 May 2024 14:28:51 +0300 Subject: [PATCH 1/2] Docs: add examples for RuntimeEnv::register_object_store --- datafusion/execution/src/object_store.rs | 2 +- datafusion/execution/src/runtime_env.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/datafusion/execution/src/object_store.rs b/datafusion/execution/src/object_store.rs index c0c58a87dcc66..126f83f7e238e 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 e78a9e0de9f04..befe215a509c7 100644 --- a/datafusion/execution/src/runtime_env.rs +++ b/datafusion/execution/src/runtime_env.rs @@ -89,6 +89,27 @@ impl RuntimeEnv { /// scheme, if any. /// /// See [`ObjectStoreRegistry`] for more details + /// + /// # Examples + /// + /// Here's how to set up a local file system object store: + /// ``` + /// let url = Url::try_from("file://").unwrap(); + /// let object_store = object_store::local::LocalFileSystem::new(); + /// ctx.runtime_env() + /// .register_object_store(&url, Arc::new(object_store)); + /// ``` + /// + /// Or how to set up a http object store: + /// ``` + /// let base_url = Url::parse("https://github.com").unwrap(); + /// let http_store = HttpBuilder::new() + /// .with_url(base_url.clone()) + /// .build() + /// .unwrap(); + /// ctx.runtime_env() + /// .register_object_store(&base_url, Arc::new(http_store)); + /// ``` pub fn register_object_store( &self, url: &Url, From 087d73a63b21a3a1c9c9cff803bc4dbd1b6044e9 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Wed, 22 May 2024 10:30:54 -0400 Subject: [PATCH 2/2] adjust example --- datafusion/execution/src/runtime_env.rs | 36 ++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/datafusion/execution/src/runtime_env.rs b/datafusion/execution/src/runtime_env.rs index befe215a509c7..25573d915959b 100644 --- a/datafusion/execution/src/runtime_env.rs +++ b/datafusion/execution/src/runtime_env.rs @@ -90,25 +90,37 @@ impl RuntimeEnv { /// /// See [`ObjectStoreRegistry`] for more details /// - /// # Examples - /// - /// Here's how to set up a local file system object store: + /// # 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(); - /// ctx.runtime_env() - /// .register_object_store(&url, Arc::new(object_store)); + /// // register the object store with the runtime environment + /// runtime_env.register_object_store(&url, Arc::new(object_store)); /// ``` /// - /// Or how to set up a http 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(); - /// ctx.runtime_env() - /// .register_object_store(&base_url, Arc::new(http_store)); + /// // 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,