Skip to content

Commit 53f71ea

Browse files
Use hex encoding
1 parent b87e4f6 commit 53f71ea

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

datafusion_iceberg/src/table.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,15 @@ impl TableProvider for DataFusionTable {
267267
fn fake_object_store_url(table_location_url: &str) -> Option<ObjectStoreUrl> {
268268
let mut u = url::Url::parse(table_location_url).ok()?;
269269
u.set_host(Some(&format!(
270-
"{}-0{}",
271-
u.host_str().unwrap_or("").replace('-', "-1"),
270+
"{}-{}",
271+
u.host_str().unwrap_or(""),
272+
// Append hex-encoded path to ensure we get a valid hostname
272273
u.path()
273-
.replace('-', "-1")
274-
.replace(object_store::path::DELIMITER, "-2")
275-
.replace(':', "-3")
274+
.as_bytes()
275+
.iter()
276+
.map(|b| format!("{:02x}", b))
277+
.collect::<Vec<_>>()
278+
.join("")
276279
)))
277280
.unwrap();
278281
u.set_path("");
@@ -1673,12 +1676,12 @@ mod tests {
16731676
#[test]
16741677
fn test_fake_object_store_url() {
16751678
assert_eq!(
1676-
fake_object_store_url("s3://aaa/bbb/ccc"),
1677-
Some(ObjectStoreUrl::parse("s3://aaa-0-2bbb-2ccc").unwrap()),
1679+
fake_object_store_url("s3://a"),
1680+
Some(ObjectStoreUrl::parse("s3://a-").unwrap()),
16781681
);
16791682
assert_eq!(
1680-
fake_object_store_url("s3://aaa/bbb-ccc"),
1681-
Some(ObjectStoreUrl::parse("s3://aaa-0-2bbb-1ccc").unwrap()),
1683+
fake_object_store_url("s3://a/b"),
1684+
Some(ObjectStoreUrl::parse("s3://a-2f62").unwrap()),
16821685
);
16831686
assert_eq!(fake_object_store_url("invalid url"), None);
16841687
}

0 commit comments

Comments
 (0)