Skip to content

Commit bbc07ea

Browse files
Adding unskip CLI command to undo a skip on schema or a table (#2727)
🔧 This is still in progress... <!-- REMOVE IRRELEVANT COMMENTS BEFORE CREATING A PULL REQUEST --> ## Changes <!-- Summary of your changes that are easy to understand. Add screenshots when necessary --> ### Linked issues <!-- DOC: Link issue with a keyword: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved. See https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword --> Resolves #1938 ### Functionality - [ ] added relevant user documentation - [x] added new CLI command --> unskip ### Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] manually tested - [ ] added unit tests - [ ] added integration tests
1 parent e97910c commit bbc07ea

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/databricks/labs/ucx/cli.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ def skip(w: WorkspaceClient, schema: str | None = None, table: str | None = None
9898
return ctx.table_mapping.skip_schema(schema)
9999

100100

101+
@ucx.command
102+
def unskip(w: WorkspaceClient, schema: str | None = None, table: str | None = None):
103+
"""Create a unskip comment on a schema or a table"""
104+
logger.info("Running unskip command")
105+
if not schema:
106+
logger.error("--schema is a required parameter.")
107+
return None
108+
ctx = WorkspaceContext(w)
109+
if table:
110+
return ctx.table_mapping.unskip_table_or_view(schema, table, ctx.tables_crawler.load_one)
111+
return ctx.table_mapping.unskip_schema(schema)
112+
113+
101114
@ucx.command(is_account=True)
102115
def sync_workspace_info(a: AccountClient):
103116
"""upload workspace config to all workspaces in the account where ucx is installed"""

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ def skip_table_or_view(self, schema_name: str, table_name: str, load_table: Call
135135
except BadRequest as err:
136136
logger.error(f"Failed to apply skip marker for Table {schema_name}.{table_name}: {err!s}", exc_info=True)
137137

138+
def unskip_table_or_view(self, schema_name: str, table_name: str, load_table: Callable[[str, str], Table | None]):
139+
# Removes skip mark from the table property
140+
try:
141+
table = load_table(schema_name, table_name)
142+
if table is None:
143+
raise NotFound("[TABLE_OR_VIEW_NOT_FOUND]")
144+
self._sql_backend.execute(
145+
f"ALTER {table.kind} {escape_sql_identifier(schema_name)}.{escape_sql_identifier(table_name)} UNSET TBLPROPERTIES IF EXISTS('{self.UCX_SKIP_PROPERTY}' );"
146+
)
147+
except NotFound as err:
148+
if "[TABLE_OR_VIEW_NOT_FOUND]" in str(err) or "[DELTA_TABLE_NOT_FOUND]" in str(err):
149+
logger.error(f"Failed to apply skip marker for Table {schema_name}.{table_name}. Table not found.")
150+
else:
151+
logger.error(
152+
f"Failed to apply skip marker for Table {schema_name}.{table_name}: {err!s}", exc_info=True
153+
)
154+
except BadRequest as err:
155+
logger.error(f"Failed to apply skip marker for Table {schema_name}.{table_name}: {err!s}", exc_info=True)
156+
138157
def skip_schema(self, schema: str):
139158
# Marks a schema to be skipped in the migration process by applying a table property
140159
try:
@@ -149,6 +168,20 @@ def skip_schema(self, schema: str):
149168
except BadRequest as err:
150169
logger.error(err)
151170

171+
def unskip_schema(self, schema: str):
172+
# Removes skip mark from the schema property
173+
try:
174+
self._sql_backend.execute(
175+
f"ALTER SCHEMA {escape_sql_identifier(schema)} UNSET DBPROPERTIES IF EXISTS('{self.UCX_SKIP_PROPERTY}');"
176+
)
177+
except NotFound as err:
178+
if "[SCHEMA_NOT_FOUND]" in str(err):
179+
logger.error(f"Failed to remove skip marker for Schema {schema}. Schema not found.")
180+
else:
181+
logger.error(err)
182+
except BadRequest as err:
183+
logger.error(err)
184+
152185
def get_tables_to_migrate(self, tables_crawler: TablesCrawler) -> Collection[TableToMigrate]:
153186
rules = self.load()
154187
# Getting all the source tables from the rules

0 commit comments

Comments
 (0)