Skip to content

Commit

Permalink
Introduce a full name property for the table
Browse files Browse the repository at this point in the history
  • Loading branch information
JCZuurmond committed Nov 18, 2024
1 parent e1df761 commit ba8bcdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/databricks/labs/ucx/source_code/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,25 @@ def __init__(
):
self._ws = ws
self._sql_backend = sql_backend
self._inventory_database = inventory_database
self._migration_index = migration_index
self._directfs_crawler = directfs_crawler
self._used_tables_crawler = used_tables_crawler
self._include_dashboard_ids = include_dashboard_ids
self._debug_listing_upper_limit = debug_listing_upper_limit

self._catalog = "hive_metastore"
self._schema = inventory_database
self._table = "query_problems"

@property
def _full_name(self) -> str:
"""Generates the full name of the table.
Returns:
str: The full table name.
"""
return f"{self._catalog}.{self._schema}.{self._table}"

def refresh_report(self) -> None:
assessment_start = datetime.now(timezone.utc)
context = _ReportingContext()
Expand All @@ -76,7 +88,7 @@ def refresh_report(self) -> None:
def _dump_problems(self, problems: Sequence[QueryProblem]) -> None:
logger.info(f"Saving {len(problems)} linting problems...")
self._sql_backend.save_table(
f'{escape_sql_identifier(self._inventory_database)}.query_problems',
escape_sql_identifier(self._full_name),
problems,
QueryProblem,
mode='overwrite',
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/source_code/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_query_linter_refresh_report_writes_query_problems(migration_index, mock

linter.refresh_report()

assert mock_backend.has_rows_written_for("`test`.query_problems")
assert mock_backend.has_rows_written_for("`hive_metastore`.`test`.`query_problems`")
ws.dashboards.list.assert_called_once()
dfsa_crawler.assert_not_called()
used_tables_crawler.assert_not_called()
Expand All @@ -65,7 +65,7 @@ def test_lints_queries(migration_index, mock_backend) -> None:
linter = QueryLinter(ws, mock_backend, "test", migration_index, dfsa_crawler, used_tables_crawler, ["1"])
linter.refresh_report()

assert mock_backend.has_rows_written_for("`test`.query_problems")
assert mock_backend.has_rows_written_for("`hive_metastore`.`test`.`query_problems`")
ws.dashboards.list.assert_not_called()
dfsa_crawler.assert_not_called()
used_tables_crawler.assert_not_called()

0 comments on commit ba8bcdc

Please sign in to comment.