1515// specific language governing permissions and limitations
1616// under the License.
1717
18- use async_trait:: async_trait;
19- use sqlx:: {
20- any:: { install_default_drivers, AnyPoolOptions , AnyRow } ,
21- AnyPool , Row ,
22- } ;
2318use std:: borrow:: Cow ;
2419use std:: collections:: HashMap ;
20+ use std:: time:: Duration ;
2521
22+ use async_trait:: async_trait;
23+ use iceberg:: io:: FileIO ;
24+ use iceberg:: spec:: { TableMetadata , TableMetadataBuilder } ;
25+ use iceberg:: table:: Table ;
2626use iceberg:: {
27- io:: FileIO ,
28- spec:: { TableMetadata , TableMetadataBuilder } ,
29- table:: Table ,
3027 Catalog , Error , ErrorKind , Namespace , NamespaceIdent , Result , TableCommit , TableCreation ,
3128 TableIdent ,
3229} ;
33- use std:: time:: Duration ;
30+ use sqlx:: any:: { install_default_drivers, AnyPoolOptions , AnyRow } ;
31+ use sqlx:: { AnyPool , Row } ;
3432use typed_builder:: TypedBuilder ;
3533use uuid:: Uuid ;
3634
@@ -278,7 +276,7 @@ impl Catalog for SqlCatalog {
278276 ) -> Result < Namespace > {
279277 {
280278 let catalog_name = self . name . clone ( ) ;
281- let namespace = namespace. encode_in_url ( ) ;
279+ let namespace = namespace. to_url_string ( ) ;
282280
283281 let query_string = format ! (
284282 "insert into {} ({}, {}, {}, {}) values (?, ?, ?, ?);" ,
@@ -290,27 +288,21 @@ impl Catalog for SqlCatalog {
290288 ) ;
291289
292290 if properties. is_empty ( ) {
293- self . execute_statement (
294- & query_string,
295- vec ! [
296- Some ( & catalog_name) ,
297- Some ( & namespace) ,
298- None :: <& String >,
299- None :: <& String >,
300- ] ,
301- )
291+ self . execute_statement ( & query_string, vec ! [
292+ Some ( & catalog_name) ,
293+ Some ( & namespace) ,
294+ None :: <& String >,
295+ None :: <& String >,
296+ ] )
302297 . await ?;
303298 } else {
304299 for ( key, value) in properties. iter ( ) {
305- self . execute_statement (
306- & query_string,
307- vec ! [
308- Some ( & catalog_name) ,
309- Some ( & namespace) ,
310- Some ( & key) ,
311- Some ( & value) ,
312- ] ,
313- )
300+ self . execute_statement ( & query_string, vec ! [
301+ Some ( & catalog_name) ,
302+ Some ( & namespace) ,
303+ Some ( & key) ,
304+ Some ( & value) ,
305+ ] )
314306 . await ?;
315307 }
316308 }
@@ -530,7 +522,7 @@ impl Catalog for SqlCatalog {
530522
531523 async fn drop_table ( & self , identifier : & TableIdent ) -> Result < ( ) > {
532524 let catalog_name = self . name . clone ( ) ;
533- let namespace = identifier. namespace ( ) . encode_in_url ( ) ;
525+ let namespace = identifier. namespace ( ) . to_url_string ( ) ;
534526 let name = identifier. name . to_string ( ) ;
535527
536528 self . execute_statement (
@@ -548,7 +540,7 @@ impl Catalog for SqlCatalog {
548540 async fn load_table ( & self , identifier : & TableIdent ) -> Result < Table > {
549541 let metadata_location = {
550542 let catalog_name = self . name . clone ( ) ;
551- let namespace = identifier. namespace ( ) . encode_in_url ( ) ;
543+ let namespace = identifier. namespace ( ) . to_url_string ( ) ;
552544 let name = identifier. name ( ) . to_string ( ) ;
553545 let row = self
554546 . execute_statement (
@@ -608,7 +600,7 @@ impl Catalog for SqlCatalog {
608600
609601 {
610602 let catalog_name = self . name . clone ( ) ;
611- let namespace = namespace. encode_in_url ( ) ;
603+ let namespace = namespace. to_url_string ( ) ;
612604 let name = name. clone ( ) ;
613605 let metadata_location = metadata_location. to_string ( ) ;
614606
@@ -640,10 +632,10 @@ impl Catalog for SqlCatalog {
640632 }
641633
642634 async fn rename_table ( & self , src : & TableIdent , dest : & TableIdent ) -> Result < ( ) > {
643- let source_namespace = & src. namespace . encode_in_url ( ) ;
635+ let source_namespace = & src. namespace . to_url_string ( ) ;
644636 let source_table = & src. name ;
645637
646- let destination_namespace = & dest. namespace . encode_in_url ( ) ;
638+ let destination_namespace = & dest. namespace . to_url_string ( ) ;
647639 let destination_table = & dest. name ;
648640
649641 let src_table_exist = self . table_exists ( src) . await ;
@@ -680,15 +672,12 @@ impl Catalog for SqlCatalog {
680672 CATALOG_TABLE_VIEW_NAME , TABLE_NAMESPACE , TABLE_NAME , TABLE_NAMESPACE , TABLE_NAME
681673 ) ;
682674
683- self . execute_statement (
684- & query,
685- vec ! [
686- Some ( destination_namespace) ,
687- Some ( destination_table) ,
688- Some ( source_namespace) ,
689- Some ( source_table) ,
690- ] ,
691- )
675+ self . execute_statement ( & query, vec ! [
676+ Some ( destination_namespace) ,
677+ Some ( destination_table) ,
678+ Some ( source_namespace) ,
679+ Some ( source_table) ,
680+ ] )
692681 . await ?;
693682
694683 let src_table_exist = self . table_exists ( src) . await ;
@@ -718,14 +707,12 @@ impl Catalog for SqlCatalog {
718707pub mod tests {
719708 use std:: collections:: HashMap ;
720709
721- use iceberg:: {
722- spec:: { NestedField , PrimitiveType , Schema , Type } ,
723- Catalog , Namespace , NamespaceIdent , TableCreation , TableIdent ,
724- } ;
710+ use iceberg:: spec:: { NestedField , PrimitiveType , Schema , Type } ;
711+ use iceberg:: { Catalog , Namespace , NamespaceIdent , TableCreation , TableIdent } ;
712+ use sqlx:: migrate:: MigrateDatabase ;
725713 use tempfile:: TempDir ;
726714
727715 use crate :: { SqlCatalog , SqlCatalogConfig } ;
728- use sqlx:: migrate:: MigrateDatabase ;
729716
730717 #[ tokio:: test]
731718 async fn test_create_update_drop_table ( ) {
@@ -790,7 +777,7 @@ pub mod tests {
790777 . list_namespaces ( None )
791778 . await
792779 . expect ( "Failed to list namespaces" ) ;
793- assert_eq ! ( namespaces[ 0 ] . encode_in_url ( ) , "test" ) ;
780+ assert_eq ! ( namespaces[ 0 ] . to_url_string ( ) , "test" ) ;
794781
795782 let test_namespace = catalog
796783 . get_namespace ( & namespace)
0 commit comments