|
8 | 8 | from databricks.sdk.service.catalog import SchemaInfo, TableInfo |
9 | 9 |
|
10 | 10 | from databricks.labs.ucx.framework.crawlers import CrawlerBase |
| 11 | +from databricks.labs.ucx.framework.utils import escape_sql_identifier |
11 | 12 | from databricks.labs.ucx.hive_metastore.tables import TablesCrawler |
12 | 13 | from databricks.labs.ucx.hive_metastore.udfs import UdfsCrawler |
13 | 14 |
|
@@ -95,13 +96,13 @@ def hive_grant_sql(self) -> list[str]: |
95 | 96 |
|
96 | 97 | def hive_revoke_sql(self) -> str: |
97 | 98 | object_type, object_key = self.this_type_and_key() |
98 | | - return f"REVOKE {self.action_type} ON {object_type} {object_key} FROM `{self.principal}`" |
| 99 | + return f"REVOKE {self.action_type} ON {object_type} {escape_sql_identifier(object_key)} FROM `{self.principal}`" |
99 | 100 |
|
100 | 101 | def _set_owner_sql(self, object_type, object_key): |
101 | | - return f"ALTER {object_type} {object_key} OWNER TO `{self.principal}`" |
| 102 | + return f"ALTER {object_type} {escape_sql_identifier(object_key)} OWNER TO `{self.principal}`" |
102 | 103 |
|
103 | 104 | def _apply_grant_sql(self, action_type, object_type, object_key): |
104 | | - return f"GRANT {action_type} ON {object_type} {object_key} TO `{self.principal}`" |
| 105 | + return f"GRANT {action_type} ON {object_type} {escape_sql_identifier(object_key)} TO `{self.principal}`" |
105 | 106 |
|
106 | 107 | def _uc_action(self, action_type): |
107 | 108 | def inner(object_type, object_key): |
@@ -155,7 +156,7 @@ def snapshot(self) -> Iterable[Grant]: |
155 | 156 | return self._snapshot(partial(self._try_load), partial(self._crawl)) |
156 | 157 |
|
157 | 158 | def _try_load(self): |
158 | | - for row in self._fetch(f"SELECT * FROM {self._full_name}"): |
| 159 | + for row in self._fetch(f"SELECT * FROM {escape_sql_identifier(self._full_name)}"): |
159 | 160 | yield Grant(*row) |
160 | 161 |
|
161 | 162 | def _crawl(self) -> Iterable[Grant]: |
@@ -189,7 +190,7 @@ def _crawl(self) -> Iterable[Grant]: |
189 | 190 | tasks.append(partial(self._grants, catalog=catalog, any_file=True)) |
190 | 191 | tasks.append(partial(self._grants, catalog=catalog, anonymous_function=True)) |
191 | 192 | # scan all databases, even empty ones |
192 | | - for row in self._fetch(f"SHOW DATABASES FROM {catalog}"): |
| 193 | + for row in self._fetch(f"SHOW DATABASES FROM {escape_sql_identifier(catalog)}"): |
193 | 194 | tasks.append(partial(self._grants, catalog=catalog, database=row.databaseName)) |
194 | 195 | for table in self._tc.snapshot(): |
195 | 196 | fn = partial(self._grants, catalog=catalog, database=table.database) |
@@ -273,7 +274,7 @@ def _grants( |
273 | 274 | "ANY_FILE": "ANY FILE", |
274 | 275 | "ANONYMOUS_FUNCTION": "ANONYMOUS FUNCTION", |
275 | 276 | } |
276 | | - for row in self._fetch(f"SHOW GRANTS ON {on_type} {key}"): |
| 277 | + for row in self._fetch(f"SHOW GRANTS ON {on_type} {escape_sql_identifier(key)}"): |
277 | 278 | (principal, action_type, object_type, _) = row |
278 | 279 | object_type = object_type_normalization.get(object_type, object_type) |
279 | 280 | if on_type != object_type: |
|
0 commit comments