@@ -534,7 +534,24 @@ impl Catalog for SqlCatalog {
534
534
)
535
535
. await ?;
536
536
537
- Ok ( ( ) )
537
+ let table_existence = self . table_exists ( & identifier) . await ;
538
+
539
+ match table_existence {
540
+ Ok ( res) => {
541
+ if res {
542
+ Err ( Error :: new (
543
+ ErrorKind :: Unexpected ,
544
+ "drop table was not successful" ,
545
+ ) )
546
+ } else {
547
+ Ok ( ( ) )
548
+ }
549
+ }
550
+ _ => Err ( Error :: new (
551
+ ErrorKind :: Unexpected ,
552
+ "drop table was not successful" ,
553
+ ) ) ,
554
+ }
538
555
}
539
556
540
557
async fn load_table ( & self , identifier : & TableIdent ) -> Result < Table > {
@@ -560,7 +577,6 @@ impl Catalog for SqlCatalog {
560
577
vec ! [ Some ( & catalog_name) , Some ( & namespace) , Some ( & name) ] ,
561
578
)
562
579
. await ?;
563
- assert_eq ! ( row. len( ) , 1 , "expected only one row from load_table query" ) ;
564
580
let row = query_map ( & row[ 0 ] ) . map_err ( from_sqlx_error) ?;
565
581
row. metadata_location
566
582
} ;
@@ -641,30 +657,25 @@ impl Catalog for SqlCatalog {
641
657
let src_table_exist = self . table_exists ( src) . await ;
642
658
let dst_table_exist = self . table_exists ( dest) . await ;
643
659
644
- match src_table_exist {
645
- Ok ( res) => {
646
- if res {
647
- match dst_table_exist {
648
- Ok ( dst_res) => {
649
- if dst_res {
650
- Err ( Error :: new (
651
- ErrorKind :: Unexpected ,
652
- "failed to rename table as destination already exists" ,
653
- ) )
654
- } else {
655
- Ok ( ( ) )
656
- }
657
- }
658
- Err ( _) => Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) ) ,
659
- }
660
- } else {
660
+ match ( src_table_exist, dst_table_exist) {
661
+ ( Ok ( src_res) , Ok ( dst_res) ) => {
662
+ if src_res && !dst_res {
663
+ Ok ( ( ) )
664
+ } else if src_res && dst_res {
665
+ Err ( Error :: new (
666
+ ErrorKind :: Unexpected ,
667
+ "failed to rename table as destination already exists" ,
668
+ ) )
669
+ } else if !src_res && dst_res {
661
670
Err ( Error :: new (
662
671
ErrorKind :: Unexpected ,
663
672
"failed to rename table as source does not exist" ,
664
673
) )
674
+ } else {
675
+ Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) )
665
676
}
666
677
}
667
- Err ( _ ) => Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) ) ,
678
+ _ => Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) ) ,
668
679
} ?;
669
680
670
681
let query = format ! (
@@ -683,18 +694,15 @@ impl Catalog for SqlCatalog {
683
694
let src_table_exist = self . table_exists ( src) . await ;
684
695
let dst_table_exist = self . table_exists ( dest) . await ;
685
696
686
- match src_table_exist {
687
- Ok ( src_res) => match dst_table_exist {
688
- Ok ( dst_res) => {
689
- if !src_res && dst_res {
690
- Ok ( ( ) )
691
- } else {
692
- Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) )
693
- }
697
+ match ( src_table_exist, dst_table_exist) {
698
+ ( Ok ( src_res) , Ok ( dst_res) ) => {
699
+ if !src_res && dst_res {
700
+ Ok ( ( ) )
701
+ } else {
702
+ Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) )
694
703
}
695
- Err ( _) => Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) ) ,
696
- } ,
697
- Err ( _) => Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) ) ,
704
+ }
705
+ _ => Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) ) ,
698
706
}
699
707
}
700
708
@@ -806,8 +814,6 @@ pub mod tests {
806
814
Namespace :: with_properties( namespace. clone( ) , props. clone( ) )
807
815
) ;
808
816
809
- //load table points to a /var location - check why
810
-
811
817
let table = catalog. load_table ( & identifier) . await . unwrap ( ) ;
812
818
813
819
assert ! ( table. metadata( ) . location( ) . ends_with( "/warehouse/table1" ) ) ;
0 commit comments