Skip to content

Commit 46091ff

Browse files
committed
Add Display
1 parent 15e3d2d commit 46091ff

File tree

5 files changed

+115
-86
lines changed

5 files changed

+115
-86
lines changed

crates/catalog/glue/src/catalog.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// under the License.
1717

1818
use std::collections::HashMap;
19-
use std::fmt::Debug;
19+
use std::fmt::{self, Debug, Display, Formatter};
2020

2121
use anyhow::anyhow;
2222
use async_trait::async_trait;
@@ -123,14 +123,23 @@ impl CatalogBuilder for GlueCatalogBuilder {
123123
/// Glue Catalog configuration
124124
#[derive(Debug)]
125125
pub(crate) struct GlueCatalogConfig {
126-
#[allow(dead_code)] // can be used for debugging
127126
name: String,
128127
uri: Option<String>,
129128
catalog_id: Option<String>,
130129
warehouse: String,
131130
props: HashMap<String, String>,
132131
}
133132

133+
impl Display for GlueCatalogConfig {
134+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
135+
write!(
136+
f,
137+
"GlueCatalogConfig(name={}, warehouse={})",
138+
self.name, self.warehouse
139+
)
140+
}
141+
}
142+
134143
struct GlueClient(aws_sdk_glue::Client);
135144

136145
/// Glue Catalog

crates/catalog/hms/src/catalog.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl CatalogBuilder for HmsCatalogBuilder {
123123
}
124124

125125
let config = HmsCatalogConfig {
126-
name: Some(name),
126+
name,
127127
address,
128128
thrift_transport: self.thrift_transport,
129129
warehouse,
@@ -149,8 +149,7 @@ pub enum HmsThriftTransport {
149149
/// Hive metastore Catalog configuration.
150150
#[derive(Debug)]
151151
pub(crate) struct HmsCatalogConfig {
152-
#[allow(dead_code)] // Stored for debugging and potential future use
153-
name: Option<String>,
152+
name: String,
154153
address: String,
155154
thrift_transport: HmsThriftTransport,
156155
warehouse: String,

crates/catalog/rest/src/catalog.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
2020
use std::any::Any;
2121
use std::collections::HashMap;
22+
use std::fmt::{self, Display, Formatter};
2223
use std::future::Future;
2324
use std::str::FromStr;
2425

@@ -129,7 +130,6 @@ impl CatalogBuilder for RestCatalogBuilder {
129130
/// Rest catalog configuration.
130131
#[derive(Clone, Debug, TypedBuilder)]
131132
pub(crate) struct RestCatalogConfig {
132-
#[allow(dead_code)] // Stored for debugging and potential future use
133133
#[builder(default, setter(strip_option))]
134134
name: Option<String>,
135135

@@ -145,6 +145,16 @@ pub(crate) struct RestCatalogConfig {
145145
client: Option<Client>,
146146
}
147147

148+
impl Display for RestCatalogConfig {
149+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
150+
if let Some(name) = &self.name {
151+
write!(f, "RestCatalogConfig(name={}, uri={})", name, self.uri)
152+
} else {
153+
write!(f, "RestCatalogConfig(name=<none>, uri={})", self.uri)
154+
}
155+
}
156+
}
157+
148158
impl RestCatalogConfig {
149159
fn url_prefixed(&self, parts: &[&str]) -> String {
150160
[&self.uri, PATH_V1]

crates/catalog/s3tables/src/catalog.rs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717

1818
use std::collections::HashMap;
19+
use std::fmt::{self, Display, Formatter};
1920
use std::future::Future;
2021

2122
use async_trait::async_trait;
@@ -44,17 +45,16 @@ pub const S3TABLES_CATALOG_PROP_ENDPOINT_URL: &str = "endpoint_url";
4445
#[derive(Debug)]
4546
pub(crate) struct S3TablesCatalogConfig {
4647
/// Catalog name.
47-
#[allow(dead_code)] // Stored for debugging and potential future use
48-
name: Option<String>,
48+
name: String,
4949
/// Unlike other buckets, S3Tables bucket is not a physical bucket, but a virtual bucket
5050
/// that is managed by s3tables. We can't directly access the bucket with path like
5151
/// s3://{bucket_name}/{file_path}, all the operations are done with respect of the bucket
5252
/// ARN.
5353
table_bucket_arn: String,
5454
/// Endpoint URL for the catalog.
55-
endpoint_url: Option<String>,
56-
/// Optional pre-configured AWS SDK client for S3Tables.
57-
client: Option<aws_sdk_s3tables::Client>,
55+
endpoint_url: String,
56+
/// Pre-configured AWS SDK client for S3Tables.
57+
client: aws_sdk_s3tables::Client,
5858
/// Properties for the catalog. The available properties are:
5959
/// - `profile_name`: The name of the AWS profile to use.
6060
/// - `region_name`: The AWS region to use.
@@ -64,8 +64,18 @@ pub(crate) struct S3TablesCatalogConfig {
6464
props: HashMap<String, String>,
6565
}
6666

67+
impl Display for S3TablesCatalogConfig {
68+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
69+
write!(
70+
f,
71+
"S3TablesCatalogConfig(name={}, table_bucket_arn={}, endpoint_url={})",
72+
self.name, self.table_bucket_arn, self.endpoint_url
73+
)
74+
}
75+
}
76+
6777
/// Builder for [`S3TablesCatalog`].
68-
#[derive(Debug)]
78+
#[derive(Debug, Default)]
6979
pub struct S3TablesCatalogBuilder {
7080
name: Option<String>,
7181
table_bucket_arn: Option<String>,
@@ -74,19 +84,6 @@ pub struct S3TablesCatalogBuilder {
7484
props: HashMap<String, String>,
7585
}
7686

77-
/// Default builder for [`S3TablesCatalog`].
78-
impl Default for S3TablesCatalogBuilder {
79-
fn default() -> Self {
80-
Self {
81-
name: None,
82-
table_bucket_arn: None,
83-
endpoint_url: None,
84-
client: None,
85-
props: HashMap::new(),
86-
}
87-
}
88-
}
89-
9087
/// Builder methods for [`S3TablesCatalog`].
9188
impl S3TablesCatalogBuilder {
9289
/// Configure the catalog with a custom endpoint URL (useful for local testing/mocking).
@@ -169,11 +166,23 @@ impl CatalogBuilder for S3TablesCatalogBuilder {
169166
));
170167
}
171168

169+
let endpoint_url = self.endpoint_url.unwrap_or_default();
170+
171+
let client = if let Some(client) = self.client {
172+
client
173+
} else {
174+
let aws_config = create_sdk_config(
175+
&self.props,
176+
if endpoint_url.is_empty() { None } else { Some(endpoint_url.clone()) },
177+
).await;
178+
aws_sdk_s3tables::Client::new(&aws_config)
179+
};
180+
172181
let config = S3TablesCatalogConfig {
173-
name: Some(catalog_name),
182+
name: catalog_name,
174183
table_bucket_arn,
175-
endpoint_url: self.endpoint_url,
176-
client: self.client,
184+
endpoint_url,
185+
client,
177186
props: self.props,
178187
};
179188

@@ -193,14 +202,8 @@ pub struct S3TablesCatalog {
193202
impl S3TablesCatalog {
194203
/// Creates a new S3Tables catalog.
195204
async fn new(config: S3TablesCatalogConfig) -> Result<Self> {
196-
let s3tables_client = if let Some(client) = config.client.clone() {
197-
client
198-
} else {
199-
let aws_config = create_sdk_config(&config.props, config.endpoint_url.clone()).await;
200-
aws_sdk_s3tables::Client::new(&aws_config)
201-
};
202-
203205
let file_io = FileIOBuilder::new("s3").with_props(&config.props).build()?;
206+
let s3tables_client = config.client.clone();
204207

205208
Ok(Self {
206209
config,
@@ -684,11 +687,14 @@ mod tests {
684687
None => return Ok(None),
685688
};
686689

690+
let aws_config = create_sdk_config(&HashMap::new(), None).await;
691+
let client = aws_sdk_s3tables::Client::new(&aws_config);
692+
687693
let config = S3TablesCatalogConfig {
688-
name: None,
694+
name: "test".to_string(),
689695
table_bucket_arn,
690-
endpoint_url: None,
691-
client: None,
696+
endpoint_url: String::new(),
697+
client,
692698
props: HashMap::new(),
693699
};
694700

@@ -993,11 +999,11 @@ mod tests {
993999
// Property value should override builder method value
9941000
assert_eq!(
9951001
catalog.config.endpoint_url,
996-
Some(property_endpoint.to_string())
1002+
property_endpoint.to_string()
9971003
);
9981004
assert_ne!(
9991005
catalog.config.endpoint_url,
1000-
Some(builder_endpoint.to_string())
1006+
builder_endpoint.to_string()
10011007
);
10021008
}
10031009

@@ -1017,7 +1023,7 @@ mod tests {
10171023

10181024
assert_eq!(
10191025
catalog.config.endpoint_url,
1020-
Some(builder_endpoint.to_string())
1026+
builder_endpoint.to_string()
10211027
);
10221028
}
10231029

@@ -1041,7 +1047,7 @@ mod tests {
10411047

10421048
assert_eq!(
10431049
catalog.config.endpoint_url,
1044-
Some(property_endpoint.to_string())
1050+
property_endpoint.to_string()
10451051
);
10461052
}
10471053

crates/iceberg/src/catalog/memory/catalog.rs

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
//! This module contains memory catalog implementation.
1919
2020
use std::collections::HashMap;
21+
use std::fmt::{self, Display, Formatter};
2122

2223
use async_trait::async_trait;
2324
use futures::lock::{Mutex, MutexGuard};
@@ -39,29 +40,11 @@ pub const MEMORY_CATALOG_WAREHOUSE: &str = "warehouse";
3940
const LOCATION: &str = "location";
4041

4142
/// Builder for [`MemoryCatalog`].
42-
#[derive(Debug)]
43-
pub struct MemoryCatalogBuilder(MemoryCatalogConfig);
44-
45-
impl Default for MemoryCatalogBuilder {
46-
fn default() -> Self {
47-
Self(MemoryCatalogConfig {
48-
name: None,
49-
warehouse: "".to_string(),
50-
props: HashMap::new(),
51-
})
52-
}
53-
}
54-
55-
impl MemoryCatalogBuilder {
56-
/// Get a mutable reference to the catalog configuration.
57-
pub(crate) fn catalog_config(&mut self) -> &mut MemoryCatalogConfig {
58-
&mut self.0
59-
}
60-
61-
/// Consume the builder and return the catalog configuration.
62-
pub(crate) fn into_config(self) -> MemoryCatalogConfig {
63-
self.0
64-
}
43+
#[derive(Debug, Default)]
44+
pub struct MemoryCatalogBuilder {
45+
name: Option<String>,
46+
warehouse: Option<String>,
47+
props: HashMap<String, String>,
6548
}
6649

6750
impl CatalogBuilder for MemoryCatalogBuilder {
@@ -72,49 +55,71 @@ impl CatalogBuilder for MemoryCatalogBuilder {
7255
name: impl Into<String>,
7356
props: HashMap<String, String>,
7457
) -> impl Future<Output = Result<Self::C>> + Send {
75-
self.catalog_config().name = Some(name.into());
58+
self.name = Some(name.into());
7659

7760
if props.contains_key(MEMORY_CATALOG_WAREHOUSE) {
78-
self.catalog_config().warehouse = props
79-
.get(MEMORY_CATALOG_WAREHOUSE)
80-
.cloned()
81-
.unwrap_or_default()
61+
self.warehouse = props.get(MEMORY_CATALOG_WAREHOUSE).cloned();
8262
}
8363

8464
// Collect other remaining properties
85-
self.catalog_config().props = props
65+
self.props = props
8666
.into_iter()
8767
.filter(|(k, _)| k != MEMORY_CATALOG_WAREHOUSE)
8868
.collect();
8969

90-
let config = self.into_config();
91-
let result = {
92-
if config.name.is_none() {
93-
Err(Error::new(
94-
ErrorKind::DataInvalid,
95-
"Catalog name is required",
96-
))
97-
} else if config.warehouse.is_empty() {
98-
Err(Error::new(
70+
async move {
71+
let name = self
72+
.name
73+
.ok_or_else(|| Error::new(ErrorKind::DataInvalid, "Catalog name is required"))?;
74+
75+
let warehouse = self.warehouse.ok_or_else(|| {
76+
Error::new(ErrorKind::DataInvalid, "Catalog warehouse is required")
77+
})?;
78+
79+
if warehouse.is_empty() {
80+
return Err(Error::new(
9981
ErrorKind::DataInvalid,
100-
"Catalog warehouse is required",
101-
))
102-
} else {
103-
MemoryCatalog::new(config)
82+
"Catalog warehouse cannot be empty",
83+
));
10484
}
105-
};
10685

107-
std::future::ready(result)
86+
let config = MemoryCatalogConfig {
87+
name: Some(name),
88+
warehouse,
89+
props: self.props,
90+
};
91+
92+
MemoryCatalog::new(config)
93+
}
10894
}
10995
}
11096

97+
/// Memory catalog configuration.
11198
#[derive(Clone, Debug)]
11299
pub(crate) struct MemoryCatalogConfig {
113100
name: Option<String>,
114101
warehouse: String,
115102
props: HashMap<String, String>,
116103
}
117104

105+
impl Display for MemoryCatalogConfig {
106+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
107+
if let Some(name) = &self.name {
108+
write!(
109+
f,
110+
"MemoryCatalogConfig(name={}, warehouse={})",
111+
name, self.warehouse
112+
)
113+
} else {
114+
write!(
115+
f,
116+
"MemoryCatalogConfig(name=<none>, warehouse={})",
117+
self.warehouse
118+
)
119+
}
120+
}
121+
}
122+
118123
/// Memory catalog implementation.
119124
#[derive(Debug)]
120125
pub struct MemoryCatalog {

0 commit comments

Comments
 (0)