Skip to content

Commit 4fc885d

Browse files
committed
Addressed test issues
1 parent 48d2828 commit 4fc885d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/databricks/labs/ucx/hive_metastore/table_migrate.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,18 @@ def _convert_wasbs_table_to_abfss(self, src_table: Table) -> bool:
386386
inventory_table = self._tables_crawler.full_name
387387
database = self._spark._jvm.scala.Some(src_table.database) # pylint: disable=protected-access
388388
table_identifier = self._table_identifier(src_table.name, database)
389+
new_table_location = ExternalLocations.wasbs_to_abfss(src_table.location)
390+
if not new_table_location:
391+
logger.warning(f"Invalid wasbs location for table {src_table.name}, skipping conversion.")
392+
return False
389393
try:
390394
old_table = self._catalog.getTableMetadata(table_identifier)
391395
entity_storage_locations = self._get_entity_storage_locations(old_table)
392396
table_location = old_table.storage()
393-
new_table_location = self._spark._jvm.java.net.URI( # pylint: disable=protected-access
394-
ExternalLocations.wasbs_to_abfss(src_table.location)
395-
)
396397
new_location = self._catalog_storage(
397-
self._spark._jvm.scala.Some(new_table_location), # pylint: disable=protected-access
398-
table_location.inputFormat(),
398+
self._spark._jvm.scala.Some( # pylint: disable=protected-access
399+
self._spark._jvm.java.net.URI(new_table_location) # pylint: disable=protected-access
400+
),
399401
table_location.outputFormat(),
400402
table_location.serde(),
401403
table_location.compressed(),
@@ -431,7 +433,7 @@ def _convert_wasbs_table_to_abfss(self, src_table: Table) -> bool:
431433
except Exception as e: # pylint: disable=broad-exception-caught
432434
logger.warning(f"Error converting HMS table {src_table.name} to abfss: {e}", exc_info=True)
433435
return False
434-
self._update_table_location(src_table, inventory_table, new_table_location.toString())
436+
self._update_table_location(src_table, inventory_table, new_table_location)
435437
logger.info(f"Converted {src_table.name} to External Table type.")
436438
return True
437439

tests/unit/hive_metastore/test_table_migrate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ def test_convert_wasbs_to_adls_gen2(ws, mock_pyspark):
242242
table_migrate.convert_wasbs_to_adls_gen2()
243243
migrate_grants.apply.assert_not_called()
244244
external_locations.resolve_mount.assert_not_called()
245-
assert backend.queries[0].startswith("UPDATE `hive_metastore`.`inventory_database`.`tables` SET location =")
245+
assert backend.queries == [
246+
"UPDATE `hive_metastore`.`inventory_database`.`tables` SET location = 'abfss://bucket/test/table1' WHERE catalog='hive_metastore' AND database='db1_src' AND name='wasbs_src';"
247+
]
246248

247249

248250
def test_migrate_managed_table_as_external_tables_without_conversion(ws, mock_pyspark):

0 commit comments

Comments
 (0)