15
15
// specific language governing permissions and limitations
16
16
// under the License.
17
17
18
- use async_trait:: async_trait;
19
- use sqlx:: {
20
- any:: { install_default_drivers, AnyPoolOptions , AnyRow } ,
21
- AnyPool , Row ,
22
- } ;
23
18
use std:: borrow:: Cow ;
24
19
use std:: collections:: HashMap ;
20
+ use std:: time:: Duration ;
25
21
22
+ use async_trait:: async_trait;
23
+ use iceberg:: io:: FileIO ;
24
+ use iceberg:: spec:: { TableMetadata , TableMetadataBuilder } ;
25
+ use iceberg:: table:: Table ;
26
26
use iceberg:: {
27
- io:: FileIO ,
28
- spec:: { TableMetadata , TableMetadataBuilder } ,
29
- table:: Table ,
30
27
Catalog , Error , ErrorKind , Namespace , NamespaceIdent , Result , TableCommit , TableCreation ,
31
28
TableIdent ,
32
29
} ;
33
- use std:: time:: Duration ;
30
+ use sqlx:: any:: { install_default_drivers, AnyPoolOptions , AnyRow } ;
31
+ use sqlx:: { AnyPool , Row } ;
34
32
use typed_builder:: TypedBuilder ;
35
33
use uuid:: Uuid ;
36
34
@@ -278,7 +276,7 @@ impl Catalog for SqlCatalog {
278
276
) -> Result < Namespace > {
279
277
{
280
278
let catalog_name = self . name . clone ( ) ;
281
- let namespace = namespace. encode_in_url ( ) ;
279
+ let namespace = namespace. to_url_string ( ) ;
282
280
283
281
let query_string = format ! (
284
282
"insert into {} ({}, {}, {}, {}) values (?, ?, ?, ?);" ,
@@ -290,27 +288,21 @@ impl Catalog for SqlCatalog {
290
288
) ;
291
289
292
290
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
+ ] )
302
297
. await ?;
303
298
} else {
304
299
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
+ ] )
314
306
. await ?;
315
307
}
316
308
}
@@ -530,7 +522,7 @@ impl Catalog for SqlCatalog {
530
522
531
523
async fn drop_table ( & self , identifier : & TableIdent ) -> Result < ( ) > {
532
524
let catalog_name = self . name . clone ( ) ;
533
- let namespace = identifier. namespace ( ) . encode_in_url ( ) ;
525
+ let namespace = identifier. namespace ( ) . to_url_string ( ) ;
534
526
let name = identifier. name . to_string ( ) ;
535
527
536
528
self . execute_statement (
@@ -548,7 +540,7 @@ impl Catalog for SqlCatalog {
548
540
async fn load_table ( & self , identifier : & TableIdent ) -> Result < Table > {
549
541
let metadata_location = {
550
542
let catalog_name = self . name . clone ( ) ;
551
- let namespace = identifier. namespace ( ) . encode_in_url ( ) ;
543
+ let namespace = identifier. namespace ( ) . to_url_string ( ) ;
552
544
let name = identifier. name ( ) . to_string ( ) ;
553
545
let row = self
554
546
. execute_statement (
@@ -608,7 +600,7 @@ impl Catalog for SqlCatalog {
608
600
609
601
{
610
602
let catalog_name = self . name . clone ( ) ;
611
- let namespace = namespace. encode_in_url ( ) ;
603
+ let namespace = namespace. to_url_string ( ) ;
612
604
let name = name. clone ( ) ;
613
605
let metadata_location = metadata_location. to_string ( ) ;
614
606
@@ -640,10 +632,10 @@ impl Catalog for SqlCatalog {
640
632
}
641
633
642
634
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 ( ) ;
644
636
let source_table = & src. name ;
645
637
646
- let destination_namespace = & dest. namespace . encode_in_url ( ) ;
638
+ let destination_namespace = & dest. namespace . to_url_string ( ) ;
647
639
let destination_table = & dest. name ;
648
640
649
641
let src_table_exist = self . table_exists ( src) . await ;
@@ -680,15 +672,12 @@ impl Catalog for SqlCatalog {
680
672
CATALOG_TABLE_VIEW_NAME , TABLE_NAMESPACE , TABLE_NAME , TABLE_NAMESPACE , TABLE_NAME
681
673
) ;
682
674
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
+ ] )
692
681
. await ?;
693
682
694
683
let src_table_exist = self . table_exists ( src) . await ;
@@ -718,14 +707,12 @@ impl Catalog for SqlCatalog {
718
707
pub mod tests {
719
708
use std:: collections:: HashMap ;
720
709
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 ;
725
713
use tempfile:: TempDir ;
726
714
727
715
use crate :: { SqlCatalog , SqlCatalogConfig } ;
728
- use sqlx:: migrate:: MigrateDatabase ;
729
716
730
717
#[ tokio:: test]
731
718
async fn test_create_update_drop_table ( ) {
@@ -790,7 +777,7 @@ pub mod tests {
790
777
. list_namespaces ( None )
791
778
. await
792
779
. expect ( "Failed to list namespaces" ) ;
793
- assert_eq ! ( namespaces[ 0 ] . encode_in_url ( ) , "test" ) ;
780
+ assert_eq ! ( namespaces[ 0 ] . to_url_string ( ) , "test" ) ;
794
781
795
782
let test_namespace = catalog
796
783
. get_namespace ( & namespace)
0 commit comments