@@ -2,27 +2,35 @@ use std::collections::HashMap;
22
33use anyhow:: anyhow;
44use async_trait:: async_trait;
5- use aws_config:: BehaviorVersion ;
65use iceberg:: table:: Table ;
76use iceberg:: {
87 Catalog , Error , ErrorKind , Namespace , NamespaceIdent , Result , TableCommit , TableCreation ,
98 TableIdent ,
109} ;
1110
11+ use crate :: utils:: create_sdk_config;
12+
13+ #[ derive( Debug ) ]
14+ pub struct S3TablesCatalogConfig {
15+ table_bucket_arn : String ,
16+ properties : HashMap < String , String > ,
17+ endpoint_url : Option < String > ,
18+ }
19+
1220/// S3Tables catalog implementation.
1321#[ derive( Debug ) ]
1422pub struct S3TablesCatalog {
15- table_bucket_arn : String ,
16- client : aws_sdk_s3tables:: Client ,
23+ config : S3TablesCatalogConfig ,
24+ s3tables_client : aws_sdk_s3tables:: Client ,
1725}
1826
1927impl S3TablesCatalog {
20- pub async fn new ( table_bucket_arn : String ) -> Self {
21- let config = aws_config :: load_defaults ( BehaviorVersion :: latest ( ) ) . await ;
22- let client = aws_sdk_s3tables:: Client :: new ( & config ) ;
28+ pub async fn new ( config : S3TablesCatalogConfig ) -> Self {
29+ let aws_config = create_sdk_config ( & config . properties , config . endpoint_url . clone ( ) ) . await ;
30+ let s3tables_client = aws_sdk_s3tables:: Client :: new ( & aws_config ) ;
2331 Self {
24- table_bucket_arn ,
25- client ,
32+ config ,
33+ s3tables_client ,
2634 }
2735 }
2836}
@@ -34,21 +42,16 @@ impl Catalog for S3TablesCatalog {
3442 parent : Option < & NamespaceIdent > ,
3543 ) -> Result < Vec < NamespaceIdent > > {
3644 let mut req = self
37- . client
45+ . s3tables_client
3846 . list_namespaces ( )
39- . table_bucket_arn ( self . table_bucket_arn . clone ( ) ) ;
47+ . table_bucket_arn ( self . config . table_bucket_arn . clone ( ) ) ;
4048 if let Some ( parent) = parent {
4149 req = req. prefix ( parent. to_url_string ( ) ) ;
4250 }
4351 let resp = req. send ( ) . await . map_err ( from_aws_sdk_error) ?;
4452 let mut result = Vec :: new ( ) ;
4553 for ns in resp. namespaces ( ) {
46- let ns_names = ns. namespace ( ) ;
47- result. extend (
48- ns_names
49- . into_iter ( )
50- . map ( |name| NamespaceIdent :: new ( name. to_string ( ) ) ) ,
51- ) ;
54+ result. push ( NamespaceIdent :: from_vec ( ns. namespace ( ) . to_vec ( ) ) ?) ;
5255 }
5356 Ok ( result)
5457 }
0 commit comments