diff --git a/src/databricks/labs/ucx/framework/crawlers.py b/src/databricks/labs/ucx/framework/crawlers.py index 49a03f5988..9a43fc0055 100644 --- a/src/databricks/labs/ucx/framework/crawlers.py +++ b/src/databricks/labs/ucx/framework/crawlers.py @@ -5,6 +5,8 @@ from databricks.labs.lsql.backends import SqlBackend from databricks.sdk.errors import NotFound +from databricks.labs.ucx.framework.utils import escape_sql_identifier + logger = logging.getLogger(__name__) @@ -52,7 +54,7 @@ def reset(self): Delete the content of the inventory table. The next call to `snapshot` will re-populate the table. """ - self._exec(f"DELETE FROM {self.full_name}") + self._exec(f"TRUNCATE TABLE {escape_sql_identifier(self.full_name)}") @staticmethod def _valid(name: str) -> str: diff --git a/tests/unit/hive_metastore/test_table_migrate.py b/tests/unit/hive_metastore/test_table_migrate.py index f3310186d8..8b8b5c502e 100644 --- a/tests/unit/hive_metastore/test_table_migrate.py +++ b/tests/unit/hive_metastore/test_table_migrate.py @@ -921,7 +921,7 @@ def test_table_status_reset(): table_status_crawler = MigrationStatusRefresher(client, backend, "ucx", table_crawler) table_status_crawler.reset() assert backend.queries == [ - "DELETE FROM hive_metastore.ucx.migration_status", + "TRUNCATE TABLE hive_metastore.ucx.migration_status", ] table_crawler.snapshot.assert_not_called() client.catalogs.list.assert_not_called() diff --git a/tests/unit/hive_metastore/test_workflows.py b/tests/unit/hive_metastore/test_workflows.py index 2cab1fd86c..11b8ced114 100644 --- a/tests/unit/hive_metastore/test_workflows.py +++ b/tests/unit/hive_metastore/test_workflows.py @@ -67,6 +67,6 @@ def test_migrate_ctas_views(run_workflow): def test_refresh_migration_status_is_refreshed(run_workflow, workflow): """Migration status is refreshed by deleting and showing new tables""" ctx = run_workflow(getattr(workflow, "refresh_migration_status")) - assert "DELETE FROM hive_metastore.ucx.migration_status" in ctx.sql_backend.queries + assert "TRUNCATE TABLE hive_metastore.ucx.migration_status" in ctx.sql_backend.queries assert "SHOW DATABASES" in ctx.sql_backend.queries # No "SHOW TABLE FROM" query as table are not mocked