@@ -2,27 +2,34 @@ 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+ }
18+
1219/// S3Tables catalog implementation.
1320#[ derive( Debug ) ]
1421pub struct S3TablesCatalog {
15- table_bucket_arn : String ,
16- client : aws_sdk_s3tables:: Client ,
22+ config : S3TablesCatalogConfig ,
23+ s3tables_client : aws_sdk_s3tables:: Client ,
1724}
1825
1926impl 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 ) ;
27+ pub async fn new ( config : S3TablesCatalogConfig ) -> Self {
28+ let aws_config = create_sdk_config ( & config . properties ) . await ;
29+ let s3tables_client = aws_sdk_s3tables:: Client :: new ( & aws_config ) ;
2330 Self {
24- table_bucket_arn ,
25- client ,
31+ config ,
32+ s3tables_client ,
2633 }
2734 }
2835}
@@ -34,21 +41,16 @@ impl Catalog for S3TablesCatalog {
3441 parent : Option < & NamespaceIdent > ,
3542 ) -> Result < Vec < NamespaceIdent > > {
3643 let mut req = self
37- . client
44+ . s3tables_client
3845 . list_namespaces ( )
39- . table_bucket_arn ( self . table_bucket_arn . clone ( ) ) ;
46+ . table_bucket_arn ( self . config . table_bucket_arn . clone ( ) ) ;
4047 if let Some ( parent) = parent {
4148 req = req. prefix ( parent. to_url_string ( ) ) ;
4249 }
4350 let resp = req. send ( ) . await . map_err ( from_aws_sdk_error) ?;
4451 let mut result = Vec :: new ( ) ;
4552 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- ) ;
53+ result. push ( NamespaceIdent :: from_vec ( ns. namespace ( ) . to_vec ( ) ) ?) ;
5254 }
5355 Ok ( result)
5456 }
0 commit comments