Skip to content

Commit

Permalink
fix: handle relative paths in global builder
Browse files Browse the repository at this point in the history
  • Loading branch information
roeap committed Jan 3, 2023
1 parent bb04455 commit 93c3b6a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/object_store.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.2 (main, Jan 23 2022, 23:15:21) [GCC 9.3.0]"
"version": "3.10.6"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "69ab9af89d9d563f0fb5bfeaa648303cf762996854f981544c3fe8758fe10dff"
"hash": "9d6ce819d12cb3dc1d584870253e9f5e189fd2e2773823a6ff4f2c218d69ebab"
}
}
},
Expand Down
26 changes: 22 additions & 4 deletions object-store/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,28 @@ impl ObjectStoreBuilder {
}

pub fn build(mut self) -> ObjectStoreResult<Arc<DynObjectStore>> {
let url = Url::parse(&self.url).map_err(|err| ObjectStoreError::Generic {
store: "Generic",
source: Box::new(err),
})?;
let maybe_url = Url::parse(&self.url);
let url =
match maybe_url {
Ok(url) => Ok(url),
Err(url::ParseError::RelativeUrlWithoutBase) => {
let abs_path = std::fs::canonicalize(std::path::PathBuf::from(&self.url))
.map_err(|err| ObjectStoreError::Generic {
store: "Generic",
source: Box::new(err),
})?;
Url::parse(&format!("file://{}", abs_path.to_str().unwrap())).map_err(|err| {
ObjectStoreError::Generic {
store: "Generic",
source: Box::new(err),
}
})
}
Err(err) => Err(ObjectStoreError::Generic {
store: "Generic",
source: Box::new(err),
}),
}?;
let root_store = match ObjectStoreKind::parse_url(&url)? {
ObjectStoreKind::Local => ObjectStoreImpl::Local(LocalFileSystem::new()),
ObjectStoreKind::InMemory => ObjectStoreImpl::InMemory(InMemory::new()),
Expand Down
1 change: 1 addition & 0 deletions object-store/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl ArrowFileSystemHandler {
#[args(options = "None")]
fn new(root: String, options: Option<HashMap<String, String>>) -> PyResult<Self> {
let inner = ObjectStoreBuilder::new(root.clone())
.with_path_as_prefix(true)
.with_options(options.clone().unwrap_or_default())
.build()
.map_err(ObjectStoreError::from)?;
Expand Down
1 change: 1 addition & 0 deletions object-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ impl PyObjectStore {
/// Create a new ObjectStore instance
fn new(root: String, options: Option<HashMap<String, String>>) -> PyResult<Self> {
let inner = ObjectStoreBuilder::new(root.clone())
.with_path_as_prefix(true)
.with_options(options.clone().unwrap_or_default())
.build()
.map_err(ObjectStoreError::from)?;
Expand Down

0 comments on commit 93c3b6a

Please sign in to comment.