Skip to content

Commit 513d8d1

Browse files
aditanasealamb
andauthored
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 <andrew@nerdnetworks.org>
1 parent e893a2e commit 513d8d1

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

datafusion/execution/src/object_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl ObjectStoreRegistry for DefaultObjectStoreRegistry {
212212
.map(|o| o.value().clone())
213213
.ok_or_else(|| {
214214
DataFusionError::Internal(format!(
215-
"No suitable object store found for {url}"
215+
"No suitable object store found for {url}. See `RuntimeEnv::register_object_store`"
216216
))
217217
})
218218
}

datafusion/execution/src/runtime_env.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,39 @@ impl RuntimeEnv {
8989
/// scheme, if any.
9090
///
9191
/// See [`ObjectStoreRegistry`] for more details
92+
///
93+
/// # Example: Register local file system object store
94+
/// ```
95+
/// # use std::sync::Arc;
96+
/// # use url::Url;
97+
/// # use datafusion_execution::runtime_env::RuntimeEnv;
98+
/// # let runtime_env = RuntimeEnv::new(Default::default()).unwrap();
99+
/// let url = Url::try_from("file://").unwrap();
100+
/// let object_store = object_store::local::LocalFileSystem::new();
101+
/// // register the object store with the runtime environment
102+
/// runtime_env.register_object_store(&url, Arc::new(object_store));
103+
/// ```
104+
///
105+
/// # Example: Register local file system object store
106+
///
107+
/// To register reading from urls such as <https://github.com>`
108+
///
109+
/// ```
110+
/// # use std::sync::Arc;
111+
/// # use url::Url;
112+
/// # use datafusion_execution::runtime_env::RuntimeEnv;
113+
/// # let runtime_env = RuntimeEnv::new(Default::default()).unwrap();
114+
/// # // use local store for example as http feature is not enabled
115+
/// # let http_store = object_store::local::LocalFileSystem::new();
116+
/// // create a new object store via object_store::http::HttpBuilder;
117+
/// let base_url = Url::parse("https://github.com").unwrap();
118+
/// // let http_store = HttpBuilder::new()
119+
/// // .with_url(base_url.clone())
120+
/// // .build()
121+
/// // .unwrap();
122+
/// // register the object store with the runtime environment
123+
/// runtime_env.register_object_store(&base_url, Arc::new(http_store));
124+
/// ```
92125
pub fn register_object_store(
93126
&self,
94127
url: &Url,

0 commit comments

Comments
 (0)