@@ -534,7 +534,24 @@ impl Catalog for SqlCatalog {
534534 )
535535 . await ?;
536536
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+ }
538555 }
539556
540557 async fn load_table ( & self , identifier : & TableIdent ) -> Result < Table > {
@@ -560,7 +577,6 @@ impl Catalog for SqlCatalog {
560577 vec ! [ Some ( & catalog_name) , Some ( & namespace) , Some ( & name) ] ,
561578 )
562579 . await ?;
563- assert_eq ! ( row. len( ) , 1 , "expected only one row from load_table query" ) ;
564580 let row = query_map ( & row[ 0 ] ) . map_err ( from_sqlx_error) ?;
565581 row. metadata_location
566582 } ;
@@ -641,30 +657,25 @@ impl Catalog for SqlCatalog {
641657 let src_table_exist = self . table_exists ( src) . await ;
642658 let dst_table_exist = self . table_exists ( dest) . await ;
643659
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 {
661670 Err ( Error :: new (
662671 ErrorKind :: Unexpected ,
663672 "failed to rename table as source does not exist" ,
664673 ) )
674+ } else {
675+ Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) )
665676 }
666677 }
667- Err ( _ ) => Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) ) ,
678+ _ => Err ( Error :: new ( ErrorKind :: Unexpected , "failed to rename table" ) ) ,
668679 } ?;
669680
670681 let query = format ! (
@@ -683,18 +694,15 @@ impl Catalog for SqlCatalog {
683694 let src_table_exist = self . table_exists ( src) . await ;
684695 let dst_table_exist = self . table_exists ( dest) . await ;
685696
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" ) )
694703 }
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" ) ) ,
698706 }
699707 }
700708
@@ -806,8 +814,6 @@ pub mod tests {
806814 Namespace :: with_properties( namespace. clone( ) , props. clone( ) )
807815 ) ;
808816
809- //load table points to a /var location - check why
810-
811817 let table = catalog. load_table ( & identifier) . await . unwrap ( ) ;
812818
813819 assert ! ( table. metadata( ) . location( ) . ends_with( "/warehouse/table1" ) ) ;
0 commit comments