Skip to content

Commit 0937f19

Browse files
fix: Fix namespace identifier in url (#435)
* fix: Fix namespace identifier in url * Remove table encoding
1 parent b341910 commit 0937f19

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

crates/catalog/rest/src/catalog.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use reqwest::header::{self, HeaderMap, HeaderName, HeaderValue};
2626
use reqwest::{Method, StatusCode, Url};
2727
use tokio::sync::OnceCell;
2828
use typed_builder::TypedBuilder;
29-
use urlencoding::encode;
3029

3130
use crate::client::HttpClient;
3231
use crate::types::{
@@ -82,11 +81,11 @@ impl RestCatalogConfig {
8281
}
8382

8483
fn namespace_endpoint(&self, ns: &NamespaceIdent) -> String {
85-
self.url_prefixed(&["namespaces", &ns.encode_in_url()])
84+
self.url_prefixed(&["namespaces", &ns.to_url_string()])
8685
}
8786

8887
fn tables_endpoint(&self, ns: &NamespaceIdent) -> String {
89-
self.url_prefixed(&["namespaces", &ns.encode_in_url(), "tables"])
88+
self.url_prefixed(&["namespaces", &ns.to_url_string(), "tables"])
9089
}
9190

9291
fn rename_table_endpoint(&self) -> String {
@@ -96,9 +95,9 @@ impl RestCatalogConfig {
9695
fn table_endpoint(&self, table: &TableIdent) -> String {
9796
self.url_prefixed(&[
9897
"namespaces",
99-
&table.namespace.encode_in_url(),
98+
&table.namespace.to_url_string(),
10099
"tables",
101-
encode(&table.name).as_ref(),
100+
&table.name,
102101
])
103102
}
104103

@@ -320,7 +319,7 @@ impl Catalog for RestCatalog {
320319
self.context().await?.config.namespaces_endpoint(),
321320
);
322321
if let Some(ns) = parent {
323-
request = request.query(&[("parent", ns.encode_in_url())]);
322+
request = request.query(&[("parent", ns.to_url_string())]);
324323
}
325324

326325
let resp = self

crates/catalog/rest/tests/rest_catalog_test.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,38 @@ fn assert_map_contains(map1: &HashMap<String, String>, map2: &HashMap<String, St
375375
assert_eq!(map2.get(k).unwrap(), v);
376376
}
377377
}
378+
379+
#[tokio::test]
380+
async fn test_list_empty_multi_level_namespace() {
381+
let fixture = set_test_fixture("test_list_empty_multi_level_namespace").await;
382+
383+
let ns_apple = Namespace::with_properties(
384+
NamespaceIdent::from_strs(["a_a", "apple"]).unwrap(),
385+
HashMap::from([
386+
("owner".to_string(), "ray".to_string()),
387+
("community".to_string(), "apache".to_string()),
388+
]),
389+
);
390+
391+
// Currently this namespace doesn't exist, so it should return error.
392+
assert!(fixture
393+
.rest_catalog
394+
.list_namespaces(Some(ns_apple.name()))
395+
.await
396+
.is_err());
397+
398+
// Create namespaces
399+
fixture
400+
.rest_catalog
401+
.create_namespace(ns_apple.name(), ns_apple.properties().clone())
402+
.await
403+
.unwrap();
404+
405+
// List namespace
406+
let nss = fixture
407+
.rest_catalog
408+
.list_namespaces(Some(&NamespaceIdent::from_strs(["a_a", "apple"]).unwrap()))
409+
.await
410+
.unwrap();
411+
assert!(nss.is_empty());
412+
}

crates/iceberg/src/catalog/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use std::fmt::Debug;
3030
use std::mem::take;
3131
use std::ops::Deref;
3232
use typed_builder::TypedBuilder;
33-
use urlencoding::encode;
3433
use uuid::Uuid;
3534

3635
/// The catalog API for Iceberg Rust.
@@ -123,9 +122,9 @@ impl NamespaceIdent {
123122
Self::from_vec(iter.into_iter().map(|s| s.to_string()).collect())
124123
}
125124

126-
/// Returns url encoded format.
127-
pub fn encode_in_url(&self) -> String {
128-
encode(&self.as_ref().join("\u{1F}")).to_string()
125+
/// Returns a string for used in url.
126+
pub fn to_url_string(&self) -> String {
127+
self.as_ref().join("\u{001f}")
129128
}
130129

131130
/// Returns inner strings.

0 commit comments

Comments
 (0)