Skip to content

Commit

Permalink
Minor: Improve ObjectStoreUrl docs + examples (#10619)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored May 26, 2024
1 parent 6167ce9 commit 3a795a4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion datafusion/execution/src/object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,32 @@ use object_store::ObjectStore;
use std::sync::Arc;
use url::Url;

/// A parsed URL identifying a particular [`ObjectStore`]
/// A parsed URL identifying a particular [`ObjectStore`] instance
///
/// For example:
/// * `file://` for local file system
/// * `s3://bucket` for AWS S3 bucket
/// * `oss://bucket` for Aliyun OSS bucket
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ObjectStoreUrl {
url: Url,
}

impl ObjectStoreUrl {
/// Parse an [`ObjectStoreUrl`] from a string
///
/// # Example
/// ```
/// # use url::Url;
/// # use datafusion_execution::object_store::ObjectStoreUrl;
/// let object_store_url = ObjectStoreUrl::parse("s3://bucket").unwrap();
/// assert_eq!(object_store_url.as_str(), "s3://bucket/");
/// // can also access the underlying `Url`
/// let url: &Url = object_store_url.as_ref();
/// assert_eq!(url.scheme(), "s3");
/// assert_eq!(url.host_str(), Some("bucket"));
/// assert_eq!(url.path(), "/");
/// ```
pub fn parse(s: impl AsRef<str>) -> Result<Self> {
let mut parsed =
Url::parse(s.as_ref()).map_err(|e| DataFusionError::External(Box::new(e)))?;
Expand Down

0 comments on commit 3a795a4

Please sign in to comment.