Skip to content

Commit

Permalink
Incorporate review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aminmovahed-db committed Sep 26, 2024
1 parent 466b13c commit 9be46eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
18 changes: 3 additions & 15 deletions src/databricks/labs/ucx/hive_metastore/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,8 @@ def unskip_table_or_view(
self._sql_backend.execute(
f"ALTER {table.kind} {escape_sql_identifier(table.full_name)} UNSET TBLPROPERTIES IF EXISTS('{self.UCX_SKIP_PROPERTY}');"
)
except NotFound as e:
if "[TABLE_OR_VIEW_NOT_FOUND]" in str(e) or "[DELTA_TABLE_NOT_FOUND]" in str(e):
logger.error(
f"Failed to remove skip marker from table: {schema_name}.{table_name}. Table not found.", exc_info=e
)
else:
logger.error(f"Failed to remove skip marker from table: {schema_name}.{table_name}", exc_info=e)
except BadRequest as e:
logger.error(f"Failed to remove skip marker from table: {schema_name}.{table_name}: {e!s}", exc_info=e)
except (NotFound, BadRequest) as e:
logger.error(f"Failed to remove skip marker from table: {table.full_name}", exc_info=e)

def skip_schema(self, schema: str):
# Marks a schema to be skipped in the migration process by applying a table property
Expand All @@ -189,12 +182,7 @@ def unskip_schema(self, schema: str) -> None:
self._sql_backend.execute(
f"ALTER SCHEMA hive_metastore.{escape_sql_identifier(schema)} UNSET DBPROPERTIES IF EXISTS('{self.UCX_SKIP_PROPERTY}');"
)
except NotFound as e:
if "[SCHEMA_NOT_FOUND]" in str(e):
logger.error(f"Failed to remove skip marker from schema: {schema}. Schema not found.", exc_info=e)
else:
logger.error(f"Failed to remove skip marker from schema: {schema}.", exc_info=e)
except BadRequest as e:
except (NotFound, BadRequest) as e:
logger.error(f"Failed to remove skip marker from schema: {schema}.", exc_info=e)

def get_tables_to_migrate(self, tables_crawler: TablesCrawler) -> Collection[TableToMigrate]:
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/hive_metastore/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_skip_happy_path(caplog):
assert len(caplog.records) == 0


def test_unskip_on_table():
def test_unskip_on_table() -> None:
ws = create_autospec(WorkspaceClient)
mock_backend = MockBackend()
installation = MockInstallation()
Expand All @@ -225,7 +225,7 @@ def test_unskip_on_table():
)


def test_unskip_on_view():
def test_unskip_on_view() -> None:
ws = create_autospec(WorkspaceClient)
mock_backend = MockBackend()
installation = MockInstallation()
Expand All @@ -241,7 +241,7 @@ def test_unskip_on_view():
)


def test_unskip_on_schema():
def test_unskip_on_schema() -> None:
ws = create_autospec(WorkspaceClient)
mock_backend = MockBackend()
installation = MockInstallation()
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_unskip_badrequest(caplog) -> None:
mapping = TableMapping(installation, ws, sbe)
table = Table(catalog="catalog", database="schema", name="table", object_type="table", table_format="csv")
mapping.unskip_table_or_view(schema_name="schema", table_name="table", load_table=lambda _schema, _table: table)
assert [rec.message for rec in caplog.records if "bad command" in rec.message.lower()]
assert [rec.message for rec in caplog.records if "failed to remove skip marker " in rec.message.lower()]
ws.tables.get.assert_not_called()


Expand Down

0 comments on commit 9be46eb

Please sign in to comment.