1616// under the License.
1717
1818use std:: collections:: HashMap ;
19+ use std:: fmt:: { self , Display , Formatter } ;
1920use std:: future:: Future ;
2021
2122use async_trait:: async_trait;
@@ -44,17 +45,16 @@ pub const S3TABLES_CATALOG_PROP_ENDPOINT_URL: &str = "endpoint_url";
4445#[ derive( Debug ) ]
4546pub ( 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 ) ]
6979pub 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`].
9188impl 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 {
193202impl 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
0 commit comments