This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 513d8d1d2a Docs: add examples for `RuntimeEnv::register_object_store`,
improve error messages (#10617)
513d8d1d2a is described below
commit 513d8d1d2afd450416e8dd77cf9be8d634f6550b
Author: Adrian Tanase <[email protected]>
AuthorDate: Wed May 22 18:35:21 2024 +0300
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 <[email protected]>
---
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 c0c58a87dc..126f83f7e2 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 e78a9e0de9..25573d9159 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 <https://github.com>`
+ ///
+ /// ```
+ /// # 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,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]