Skip to content

Commit 93c3b6a

Browse files
committed
fix: handle relative paths in global builder
1 parent bb04455 commit 93c3b6a

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

examples/object_store.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@
157157
"name": "python",
158158
"nbconvert_exporter": "python",
159159
"pygments_lexer": "ipython3",
160-
"version": "3.10.2 (main, Jan 23 2022, 23:15:21) [GCC 9.3.0]"
160+
"version": "3.10.6"
161161
},
162162
"orig_nbformat": 4,
163163
"vscode": {
164164
"interpreter": {
165-
"hash": "69ab9af89d9d563f0fb5bfeaa648303cf762996854f981544c3fe8758fe10dff"
165+
"hash": "9d6ce819d12cb3dc1d584870253e9f5e189fd2e2773823a6ff4f2c218d69ebab"
166166
}
167167
}
168168
},

object-store/src/builder.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,28 @@ impl ObjectStoreBuilder {
130130
}
131131

132132
pub fn build(mut self) -> ObjectStoreResult<Arc<DynObjectStore>> {
133-
let url = Url::parse(&self.url).map_err(|err| ObjectStoreError::Generic {
134-
store: "Generic",
135-
source: Box::new(err),
136-
})?;
133+
let maybe_url = Url::parse(&self.url);
134+
let url =
135+
match maybe_url {
136+
Ok(url) => Ok(url),
137+
Err(url::ParseError::RelativeUrlWithoutBase) => {
138+
let abs_path = std::fs::canonicalize(std::path::PathBuf::from(&self.url))
139+
.map_err(|err| ObjectStoreError::Generic {
140+
store: "Generic",
141+
source: Box::new(err),
142+
})?;
143+
Url::parse(&format!("file://{}", abs_path.to_str().unwrap())).map_err(|err| {
144+
ObjectStoreError::Generic {
145+
store: "Generic",
146+
source: Box::new(err),
147+
}
148+
})
149+
}
150+
Err(err) => Err(ObjectStoreError::Generic {
151+
store: "Generic",
152+
source: Box::new(err),
153+
}),
154+
}?;
137155
let root_store = match ObjectStoreKind::parse_url(&url)? {
138156
ObjectStoreKind::Local => ObjectStoreImpl::Local(LocalFileSystem::new()),
139157
ObjectStoreKind::InMemory => ObjectStoreImpl::InMemory(InMemory::new()),

object-store/src/file.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl ArrowFileSystemHandler {
2828
#[args(options = "None")]
2929
fn new(root: String, options: Option<HashMap<String, String>>) -> PyResult<Self> {
3030
let inner = ObjectStoreBuilder::new(root.clone())
31+
.with_path_as_prefix(true)
3132
.with_options(options.clone().unwrap_or_default())
3233
.build()
3334
.map_err(ObjectStoreError::from)?;

object-store/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ impl PyObjectStore {
230230
/// Create a new ObjectStore instance
231231
fn new(root: String, options: Option<HashMap<String, String>>) -> PyResult<Self> {
232232
let inner = ObjectStoreBuilder::new(root.clone())
233+
.with_path_as_prefix(true)
233234
.with_options(options.clone().unwrap_or_default())
234235
.build()
235236
.map_err(ObjectStoreError::from)?;

0 commit comments

Comments
 (0)