-
Notifications
You must be signed in to change notification settings - Fork 732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
object_store: add Path::from_url_path #3663
object_store: add Path::from_url_path #3663
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, mostly just some additional test suggestions
object_store/src/path/mod.rs
Outdated
@@ -162,6 +162,13 @@ impl Path { | |||
}) | |||
} | |||
|
|||
/// Parse a url encoded string as a [`Path`], returning a [`Error`] if invalid, | |||
/// as defined on the docstring for [`Path`] | |||
pub fn from_url_path(path: impl AsRef<str>) -> Result<Self, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of this taking AsRef<Url>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense, let me do it later today
ps: then we can name it from_url(url: impl AsRef<URL>)
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ps: then we can name it from_url(url: impl AsRef) instead?
I think I would keep it as from_url_path
as it will ignore the rest of the URL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
turn out existing code have
arrow-rs/object_store/src/path/mod.rs
Lines 197 to 210 in d14135d
pub(crate) fn from_absolute_path_with_base( | |
path: impl AsRef<std::path::Path>, | |
base: Option<&Url>, | |
) -> Result<Self, Error> { | |
let url = absolute_path_to_url(path)?; | |
let path = match base { | |
Some(prefix) => url.path().strip_prefix(prefix.path()).ok_or_else(|| { | |
Error::PrefixMismatch { | |
path: url.path().to_string(), | |
prefix: prefix.to_string(), | |
} | |
})?, | |
None => url.path(), | |
}; |
so do you think it makes more sense to use from_url_path(&str)
?
object_store/src/path/mod.rs
Outdated
|
||
/// Parse a url encoded string as a [`Path`], returning a [`Error`] if invalid, | ||
/// as defined on the docstring for [`Path`] | ||
pub fn from_url_path(path: &str) -> Result<Self, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking to define as impl AsRef<str>
, but
as_bytes
method not found inimpl AsRef<str>
NonUnicodeSnafu { path }
: the traitFrom<impl AsRef<str>>
is not implemented forString
object_store/src/path/mod.rs
Outdated
|
||
/// Parse a url encoded string as a [`Path`], returning a [`Error`] if invalid, | ||
/// as defined on the docstring for [`Path`] | ||
pub fn from_url_path(path: &str) -> Result<Self, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn from_url_path(path: &str) -> Result<Self, Error> { | |
pub fn from_url_path(path: impl AsRef<str>) -> Result<Self, Error> { | |
let path = path.as_ref() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you
I took the liberty of patching this slightly to get it in, thank you 👍 |
Benchmark runs are scheduled for baseline = 9131c30 and contender = fb11792. fb11792 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
Which issue does this PR close?
Closes #3651
Rationale for this change
#3651 (comment)
This would simplify user usage of Path, e.g.
What changes are included in this PR?
Implement new method
from_url_path
Are there any user-facing changes?
New method is provided, no impact to existing methods