Skip to content

Commit

Permalink
The returned path value of get_by_uri should be self-described with e…
Browse files Browse the repository at this point in the history
…ntire path (#1779)

* Make the return path value of get_by_uri() in ObjectStoreRegistry self-described for which object store to be used

* Improve the uri parse logic with considering host and port

* Revert "Improve the uri parse logic with considering host and port"

This reverts commit e5e8dd3.

Co-authored-by: yangzhong <[email protected]>
  • Loading branch information
yahoNanJing and kyotoYaho authored Feb 14, 2022
1 parent ca765d5 commit 7a46084
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions datafusion/src/datasource/object_store/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ pub struct LocalFileSystem;
#[async_trait]
impl ObjectStore for LocalFileSystem {
async fn list_file(&self, prefix: &str) -> Result<FileMetaStream> {
let prefix = if let Some((_scheme, path)) = prefix.split_once("://") {
path
} else {
prefix
};
list_all(prefix.to_owned()).await
}

Expand Down
7 changes: 3 additions & 4 deletions datafusion/src/datasource/object_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,12 @@ impl ObjectStoreRegistry {
/// Get a suitable store for the URI based on it's scheme. For example:
/// - URI with scheme `file://` or no schema will return the default LocalFS store
/// - URI with scheme `s3://` will return the S3 store if it's registered
/// Returns a tuple with the store and the path of the file in that store
/// (URI=scheme://path).
/// Returns a tuple with the store and the self-described uri of the file in that store
pub fn get_by_uri<'a>(
&self,
uri: &'a str,
) -> Result<(Arc<dyn ObjectStore>, &'a str)> {
if let Some((scheme, path)) = uri.split_once("://") {
if let Some((scheme, _path)) = uri.split_once("://") {
let stores = self.object_stores.read();
let store = stores
.get(&*scheme.to_lowercase())
Expand All @@ -237,7 +236,7 @@ impl ObjectStoreRegistry {
scheme
))
})?;
Ok((store, path))
Ok((store, uri))
} else {
Ok((Arc::new(LocalFileSystem), uri))
}
Expand Down

0 comments on commit 7a46084

Please sign in to comment.