From 0667178d9b032102444a90a4c2b0eb80c7fde188 Mon Sep 17 00:00:00 2001 From: Joe_Yi Date: Thu, 14 May 2026 16:55:58 +0800 Subject: [PATCH] Fix skip CLI to ALTER HMS tables using three-part name skip_table_or_view used schema.table, which breaks on Unity Catalog-enabled SQL warehouses when the workspace default catalog is not hive_metastore. unskip_table_or_view already used table.full_name (catalog.schema.table). Use escape_sql_identifier(table.full_name) for SET TBLPROPERTIES, matching unskip. Fixes TABLE_OR_VIEW_NOT_FOUND when running: databricks labs ucx skip Co-authored-by: Cursor --- src/databricks/labs/ucx/hive_metastore/mapping.py | 2 +- tests/unit/hive_metastore/test_mapping.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/databricks/labs/ucx/hive_metastore/mapping.py b/src/databricks/labs/ucx/hive_metastore/mapping.py index c87e7406e1..8f8e08b1f5 100644 --- a/src/databricks/labs/ucx/hive_metastore/mapping.py +++ b/src/databricks/labs/ucx/hive_metastore/mapping.py @@ -133,7 +133,7 @@ def skip_table_or_view(self, schema_name: str, table_name: str, load_table: Call if table is None: raise NotFound("[TABLE_OR_VIEW_NOT_FOUND]") self._sql_backend.execute( - f"ALTER {table.kind} {escape_sql_identifier(schema_name)}.{escape_sql_identifier(table_name)} SET TBLPROPERTIES('{self.UCX_SKIP_PROPERTY}' = true)" + f"ALTER {table.kind} {escape_sql_identifier(table.full_name)} SET TBLPROPERTIES('{self.UCX_SKIP_PROPERTY}' = true)" ) except NotFound as err: if "[TABLE_OR_VIEW_NOT_FOUND]" in str(err) or "[DELTA_TABLE_NOT_FOUND]" in str(err): diff --git a/tests/unit/hive_metastore/test_mapping.py b/tests/unit/hive_metastore/test_mapping.py index 01944256f6..a7fcf7dd3b 100644 --- a/tests/unit/hive_metastore/test_mapping.py +++ b/tests/unit/hive_metastore/test_mapping.py @@ -208,15 +208,15 @@ def test_skip_happy_path(caplog): mapping.skip_table_or_view(schema_name="schema", table_name="table", load_table=lambda _schema, _table: table) ws.tables.get.assert_not_called() sbe.execute.assert_called_with( - f"ALTER TABLE `schema`.`table` SET TBLPROPERTIES('{mapping.UCX_SKIP_PROPERTY}' = true)" + f"ALTER TABLE `catalog`.`schema`.`table` SET TBLPROPERTIES('{mapping.UCX_SKIP_PROPERTY}' = true)" ) view = Table( - catalog="catalog", database="schema", name="table", object_type="table", table_format="csv", view_text="stuff" + catalog="catalog", database="schema", name="view", object_type="table", table_format="csv", view_text="stuff" ) mapping.skip_table_or_view(schema_name="schema", table_name="view", load_table=lambda _schema, _table: view) ws.tables.get.assert_not_called() sbe.execute.assert_called_with( - f"ALTER VIEW `schema`.`view` SET TBLPROPERTIES('{mapping.UCX_SKIP_PROPERTY}' = true)" + f"ALTER VIEW `catalog`.`schema`.`view` SET TBLPROPERTIES('{mapping.UCX_SKIP_PROPERTY}' = true)" ) assert len(caplog.records) == 0 mapping.skip_schema(schema="schema")