Skip to content

Commit

Permalink
Docs: add examples for RuntimeEnv::register_object_store, improve e…
Browse files Browse the repository at this point in the history
…rror messages (#10617)

* Docs: add examples for RuntimeEnv::register_object_store

* adjust example

---------

Co-authored-by: Andrew Lamb <[email protected]>
  • Loading branch information
aditanase and alamb authored May 22, 2024
1 parent e893a2e commit 513d8d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion datafusion/execution/src/object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
))
})
}
Expand Down
33 changes: 33 additions & 0 deletions datafusion/execution/src/runtime_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 513d8d1

Please sign in to comment.