Skip to content

Commit 314ecc6

Browse files
committed
fix: to_uri() in the logstore implementation should use Url::join
Any places where we see hard-coded string formatting (e.g. format!()) around Url is likely to be **wrong** and need to be removed. This commit fixes the failing integration tests with the lakefs connector Signed-off-by: R. Tyler Croy <rtyler@brokenco.de>
1 parent 2dec25b commit 314ecc6

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

crates/core/src/logstore/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,9 @@ pub(crate) fn object_store_path(table_root: &Url) -> DeltaResult<Path> {
551551
})
552552
}
553553

554-
/// TODO
554+
/// Join the given `root` [Url] with the [Path] to produce a URI (String) of the two together.
555+
///
556+
/// This is largely a convenience function to help with the nuances of empty [Path] and file [Url]s
555557
pub fn to_uri(root: &Url, location: &Path) -> String {
556558
match root.scheme() {
557559
"file" => {
@@ -575,7 +577,9 @@ pub fn to_uri(root: &Url, location: &Path) -> String {
575577
if location.as_ref().is_empty() || location.as_ref() == "/" {
576578
root.as_ref().to_string()
577579
} else {
578-
format!("{}/{}", root.as_ref(), location.as_ref())
580+
root.join(location.as_ref())
581+
.expect("Somehow failed to join on a Url!")
582+
.to_string()
579583
}
580584
}
581585
}

crates/lakefs/src/logstore.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use bytes::Bytes;
55
use deltalake_core::logstore::{
66
DefaultObjectStoreRegistry, ObjectStoreRegistry, commit_uri_from_version,
77
};
8+
use deltalake_core::table::normalize_table_url;
89
use deltalake_core::{
910
DeltaResult, kernel::transaction::TransactionError, logstore::ObjectStoreRef,
1011
};
@@ -116,7 +117,13 @@ impl LakeFSLogStore {
116117
"lakefs://{repo}/{}/{table}",
117118
self.client.get_transaction(operation_id)?,
118119
);
119-
Ok(Url::parse(&string_url).unwrap())
120+
Ok(normalize_table_url(&Url::parse(&string_url).map_err(
121+
|_| {
122+
DeltaTableError::NotATable(format!(
123+
"Could not convert {string_url} into a table URL"
124+
))
125+
},
126+
)?))
120127
}
121128

122129
fn get_transaction_objectstore(
@@ -399,3 +406,6 @@ fn put_options() -> &'static PutOptions {
399406
extensions: Default::default(),
400407
})
401408
}
409+
410+
#[cfg(test)]
411+
mod tests {}

python/tests/test_fs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_read_simple_table_from_remote(s3_localstack):
9696
"part-00007-3a0e4727-de0d-41b6-81ef-5223cf40f025-c000.snappy.parquet",
9797
]
9898

99-
assert dt.file_uris() == [table_path + "/" + path for path in expected_files]
99+
assert dt.file_uris() == [table_path + path for path in expected_files]
100100

101101

102102
@pytest.mark.pyarrow

0 commit comments

Comments
 (0)