@@ -638,3 +638,77 @@ def test_is_target_exists():
638638 )
639639 assert not table_mapping .exists_in_uc (src_table , "cat1.schema1.dest1" )
640640 assert table_mapping .exists_in_uc (src_table , "cat1.schema2.dest2" )
641+
642+
643+ def test_mapping_broken_table (caplog ):
644+ client = create_autospec (WorkspaceClient )
645+ tables_crawler = create_autospec (TablesCrawler )
646+ # When check table properties, raise token error
647+ backend = MockBackend (fails_on_first = {"SHOW TBLPROPERTIES" : "tokentoken" })
648+ installation = MockInstallation (
649+ {
650+ 'mapping.csv' : [
651+ {
652+ 'catalog_name' : 'catalog' ,
653+ 'dst_schema' : 'schema1' ,
654+ 'dst_table' : 'table1' ,
655+ 'src_schema' : 'schema1' ,
656+ 'src_table' : 'table1' ,
657+ 'workspace_name' : 'workspace' ,
658+ },
659+ ]
660+ }
661+ )
662+ client .tables .get .side_effect = NotFound ()
663+ table_mapping = TableMapping (installation , client , backend )
664+ tables_crawler .snapshot .return_value = [
665+ Table (
666+ object_type = "EXTERNAL" ,
667+ table_format = "DELTA" ,
668+ catalog = "hive_metastore" ,
669+ database = "schema1" ,
670+ name = "table1" ,
671+ ),
672+ ]
673+ table_mapping .get_tables_to_migrate (tables_crawler )
674+ assert "Failed to get properties for Table hive_metastore.schema1.table1" in caplog .text
675+
676+
677+ def test_table_with_no_target_reverted_failed (caplog ):
678+ errors = {"ALTER TABLE" : "ALTER_TABLE_FAILED" }
679+ rows = {
680+ "SHOW TBLPROPERTIES schema1.table1" : [
681+ {"key" : "upgraded_to" , "value" : "non.existing.table" },
682+ ],
683+ }
684+ backend = MockBackend (fails_on_first = errors , rows = rows )
685+ client = create_autospec (WorkspaceClient )
686+ client .tables .get .side_effect = NotFound ()
687+
688+ installation = MockInstallation (
689+ {
690+ 'mapping.csv' : [
691+ {
692+ 'workspace_name' : "fake_ws" ,
693+ "catalog_name" : 'cat1' ,
694+ 'src_schema' : 'schema1' ,
695+ 'dst_schema' : 'schema1' ,
696+ 'src_table' : 'table1' ,
697+ 'dst_table' : 'table1' ,
698+ }
699+ ]
700+ }
701+ )
702+ table_mapping = TableMapping (installation , client , backend )
703+ tables_crawler = create_autospec (TablesCrawler )
704+ tables_crawler .snapshot .return_value = [
705+ Table (
706+ object_type = "EXTERNAL" ,
707+ table_format = "DELTA" ,
708+ catalog = "hive_metastore" ,
709+ database = "schema1" ,
710+ name = "table1" ,
711+ ),
712+ ]
713+ table_mapping .get_tables_to_migrate (tables_crawler )
714+ assert "Failed to unset upgraded_to property" in caplog .text
0 commit comments