sqlassert 0.1.2__py3-none-any.whl → 0.3.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. sqlassert/__init__.py +34 -9
  2. sqlassert/__main__.py +9 -0
  3. sqlassert/check.py +451 -0
  4. sqlassert/diagnostics.py +70 -0
  5. sqlassert/dialects.py +258 -0
  6. sqlassert/discovery/__init__.py +30 -0
  7. sqlassert/discovery/bigquery.py +71 -0
  8. sqlassert/discovery/databricks.py +18 -0
  9. sqlassert/discovery/duckdb.py +159 -0
  10. sqlassert/discovery/fetcher.py +418 -0
  11. sqlassert/discovery/information_schema.py +327 -0
  12. sqlassert/discovery/mysql.py +70 -0
  13. sqlassert/discovery/postgres.py +142 -0
  14. sqlassert/discovery/redshift.py +36 -0
  15. sqlassert/discovery/snowflake.py +63 -0
  16. sqlassert/discovery/trino.py +37 -0
  17. sqlassert/edits.py +240 -0
  18. sqlassert/hazards.py +574 -0
  19. sqlassert/ir/__init__.py +58 -0
  20. sqlassert/ir/convert.py +3509 -0
  21. sqlassert/ir/model.py +779 -0
  22. sqlassert/main.py +51 -0
  23. sqlassert/properties.py +121 -0
  24. sqlassert/provenance.py +73 -0
  25. sqlassert/python_engine.py +356 -0
  26. sqlassert/reporting.py +105 -0
  27. sqlassert/rewrites.py +1541 -0
  28. sqlassert/rules/STYLEGUIDE.md +19 -0
  29. sqlassert/rules/__init__.py +11 -0
  30. sqlassert/rules/column_set.py +34 -0
  31. sqlassert/rules/domain.py +472 -0
  32. sqlassert/rules/equality.py +442 -0
  33. sqlassert/rules/exactly_one.py +114 -0
  34. sqlassert/rules/foreign_key.py +319 -0
  35. sqlassert/rules/join_cardinality.py +116 -0
  36. sqlassert/rules/nullability.py +627 -0
  37. sqlassert/rules/uniqueness.py +904 -0
  38. sqlassert/sql_parse.py +1081 -0
  39. sqlassert/suggest.py +418 -0
  40. sqlassert-0.3.3.dist-info/METADATA +807 -0
  41. sqlassert-0.3.3.dist-info/RECORD +46 -0
  42. {sqlassert-0.1.2.dist-info → sqlassert-0.3.3.dist-info}/WHEEL +1 -1
  43. sqlassert-0.3.3.dist-info/entry_points.txt +2 -0
  44. sqlassert-0.3.3.dist-info/licenses/LICENSE +21 -0
  45. sqlassert-0.3.3.dist-info/top_level.txt +2 -0
  46. sqlassert_cli.py +130 -0
  47. sqlassert/unique.py +0 -605
  48. sqlassert-0.1.2.dist-info/METADATA +0 -173
  49. sqlassert-0.1.2.dist-info/RECORD +0 -6
  50. sqlassert-0.1.2.dist-info/top_level.txt +0 -1
@@ -0,0 +1,418 @@
1
+ """Hydrate a SQL Program's external Relations from a database catalog.
2
+
3
+ A `DatabaseKnowledgeFetcher` runs before the engine. It links the Program once
4
+ without a connection to find the external Named Relations it reaches, asks
5
+ its database-specific hooks for their catalog metadata and view definitions,
6
+ and relinks the Program with that metadata turned into ordinary declarations:
7
+ a fetched table becomes a column-only `CREATE TABLE`, a fetched view the
8
+ `CREATE VIEW` the database stored. Each relink reveals the Relations the new
9
+ view bodies read, so view expansion recurses until nothing new is reached; a
10
+ cycle among views is left to the linker, which reports it.
11
+
12
+ Catalog constraints never pass through those declarations. `bind` turns them
13
+ into Properties over the final IR's own Output Columns, so the engine sees
14
+ Properties only, never a name, a catalog row, or a connection: Knowledge for
15
+ what the dialect enforces, Property Declarations for unenforced keys the
16
+ caller trusts (`trust_unenforced_keys`), as `ir/convert.py` decides for keys
17
+ written in SQL.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ from abc import ABC, abstractmethod
23
+ from collections.abc import Mapping
24
+ from dataclasses import dataclass, field, replace
25
+ from enum import Enum
26
+
27
+ from sqlglot import Expr, exp
28
+ from sqlglot.errors import SqlglotError
29
+ from sqlglot.optimizer.scope import traverse_scope
30
+
31
+ from sqlassert import diagnostics as diag
32
+ from sqlassert import ir
33
+ from sqlassert.diagnostics import Diagnostic, quoted_all
34
+ from sqlassert.dialects import semantics
35
+ from sqlassert.ir.convert import IrConversionResult, IrParser
36
+ from sqlassert.properties import NonNullColumn, Property, ReferentialCoverage, UniqueSet
37
+ from sqlassert.provenance import Origin
38
+ from sqlassert.sql_parse import ParsedProgram, SqlParser
39
+
40
+ CATALOG = "catalog"
41
+
42
+
43
+ class DatabaseRelationKind(Enum):
44
+ TABLE = "table"
45
+ VIEW = "view"
46
+
47
+
48
+ @dataclass(frozen=True)
49
+ class DatabaseColumn:
50
+ """One catalog column. `data_type` is its SQL type as the database writes
51
+ it (in the fetcher's `type_dialect`), or None when unknown. sqlassert
52
+ supports the dialect's default collation only: a fetcher reports a column
53
+ under any other collation that may not compare by identity with
54
+ `data_type` None, so no comparison of it is assumed to be by identity."""
55
+
56
+ name: str
57
+ nullable: bool
58
+ data_type: str | None = None
59
+
60
+
61
+ @dataclass(frozen=True)
62
+ class DatabaseForeignKey:
63
+ """An enforced foreign key: `columns` pair by position with `referenced_columns`
64
+ of the Relation whose canonical identity is `referenced`."""
65
+
66
+ columns: tuple[str, ...]
67
+ referenced: str
68
+ referenced_columns: tuple[str, ...]
69
+
70
+
71
+ @dataclass(frozen=True)
72
+ class DatabaseRelationMetadata:
73
+ """One catalog Relation, identified canonically, with its complete enforced facts.
74
+
75
+ Columns, keys, unique sets, and foreign keys describe base tables only; a
76
+ view's are derived from its definition instead.
77
+ """
78
+
79
+ catalog: str
80
+ schema: str
81
+ name: str
82
+ kind: DatabaseRelationKind
83
+ columns: tuple[DatabaseColumn, ...] = ()
84
+ primary_key: tuple[str, ...] = ()
85
+ unique_sets: tuple[tuple[str, ...], ...] = ()
86
+ foreign_keys: tuple[DatabaseForeignKey, ...] = ()
87
+
88
+ @property
89
+ def identity(self) -> str:
90
+ return f"{self.catalog}.{self.schema}.{self.name}"
91
+
92
+
93
+ @dataclass(frozen=True)
94
+ class DatabaseViewDefinition:
95
+ """The `CREATE VIEW` statement a database stored for one view: structural input, never Knowledge."""
96
+
97
+ sql: str
98
+
99
+
100
+ class DatabaseMetadataError(Exception):
101
+ """The catalog could not be read, for example for lack of permission."""
102
+
103
+
104
+ @dataclass(frozen=True)
105
+ class DatabaseHydration:
106
+ """The final linked Program and the catalog tables declared into it, by declared name."""
107
+
108
+ conversion: IrConversionResult
109
+ tables: Mapping[str, DatabaseRelationMetadata] = field(default_factory=dict)
110
+ diagnostics: tuple[Diagnostic, ...] = ()
111
+ dialect: str = "duckdb"
112
+ trust_unenforced_keys: bool = True
113
+
114
+
115
+ @dataclass(frozen=True)
116
+ class CatalogFacts:
117
+ """What `bind` makes of the catalog: Knowledge the database enforces,
118
+ Property Declarations it does not but the caller trusts, and a warning
119
+ for each key left out."""
120
+
121
+ knowledge: tuple[Property, ...] = ()
122
+ declarations: tuple[Property, ...] = ()
123
+ warnings: tuple[Diagnostic, ...] = ()
124
+
125
+
126
+ class DatabaseKnowledgeFetcher(ABC):
127
+ """Generic catalog discovery; subclasses own one database's catalog boundary."""
128
+
129
+ # The SQL dialect the database writes column types in.
130
+ type_dialect: str | None = None
131
+
132
+ def hydrate(self, ast: ParsedProgram, *, dialect: str, trust_unenforced_keys: bool = True) -> DatabaseHydration:
133
+ return _Hydration(self, ast, dialect, trust_unenforced_keys).run()
134
+
135
+ def convert(
136
+ self, ast: ParsedProgram, *, dialect: str, trust_unenforced_keys: bool = True,
137
+ ) -> tuple[IrConversionResult, DatabaseHydration]:
138
+ """`hydrate` and `bind` together: the conversion with the catalog's
139
+ declarations, Knowledge and diagnostics merged in, and the hydration.
140
+ Its warnings are the catalog facts' and the SQL's own
141
+ (`diagnostics.SQL_WARNINGS`): a connection warning asks for what the
142
+ catalog has just answered."""
143
+ hydration = self.hydrate(ast, dialect=dialect, trust_unenforced_keys=trust_unenforced_keys)
144
+ conversion = hydration.conversion
145
+ facts = self.bind(conversion.program, hydration)
146
+ merged = replace(
147
+ conversion,
148
+ program=replace(conversion.program, declarations=conversion.program.declarations + facts.declarations),
149
+ knowledge=conversion.knowledge + facts.knowledge,
150
+ diagnostics=hydration.diagnostics + conversion.diagnostics,
151
+ warnings=(*facts.warnings, *(warning for warning in conversion.warnings if warning.code in diag.SQL_WARNINGS)),
152
+ )
153
+ return merged, hydration
154
+
155
+ def bind(self, program: ir.Program, hydration: DatabaseHydration) -> CatalogFacts:
156
+ """Catalog facts as Properties over ``program``'s Output Columns.
157
+
158
+ NOT NULL columns are Knowledge. Keys and foreign keys are Knowledge
159
+ where the dialect enforces them; elsewhere, as for SQL declarations,
160
+ they are Property Declarations under `trust_unenforced_keys`, and
161
+ otherwise left out with a warning (`docs/dialects.md`). A foreign key
162
+ binds only when the Program reaches its referenced Relation.
163
+ """
164
+ meaning = semantics(hydration.dialect)
165
+ knowledge: list[Property] = []
166
+ declarations: list[Property] = []
167
+ warnings: list[Diagnostic] = []
168
+
169
+ def place(facts: list[Property], enforced: bool, kind: str, columns: tuple[str, ...], metadata: DatabaseRelationMetadata) -> None:
170
+ if enforced:
171
+ knowledge.extend(facts)
172
+ elif hydration.trust_unenforced_keys:
173
+ declarations.extend(facts)
174
+ else:
175
+ warnings.append(Diagnostic(
176
+ diag.UNENFORCED_CONSTRAINT,
177
+ f"the {kind} ({quoted_all(columns)}) of {metadata.identity} is not Knowledge, since {hydration.dialect} "
178
+ "does not enforce it: if the data satisfies it, analyze with trust_unenforced_keys=True",
179
+ _origin(metadata),
180
+ ))
181
+
182
+ tables = [
183
+ (relation, metadata) for relation in program.named_relations
184
+ if relation.role is ir.RelationRole.TABLE and (metadata := hydration.tables.get(relation.name.lower())) is not None
185
+ ]
186
+ by_identity: dict[str, list[tuple[ir.NamedRelation, DatabaseRelationMetadata]]] = {}
187
+ for relation, metadata in tables:
188
+ by_identity.setdefault(metadata.identity.lower(), []).append((relation, metadata))
189
+ keys_enforced = meaning.unique_keys == "enforced"
190
+ for relation, metadata in tables:
191
+ columns = {column.name.lower(): column for column in relation.output_columns}
192
+ non_null = sorted({column.name.lower() for column in metadata.columns if not column.nullable})
193
+ knowledge.extend(NonNullColumn(column=columns[name]) for name in non_null if name in columns)
194
+ for position, unique_set in enumerate(_unique_sets(metadata)):
195
+ facts: list[Property] = [UniqueSet(columns=frozenset(columns[name.lower()] for name in unique_set))]
196
+ primary = position == 0 and bool(metadata.primary_key)
197
+ if primary and (meaning.primary_key_not_null or not keys_enforced):
198
+ facts.extend(NonNullColumn(column=columns[name.lower()]) for name in unique_set if name.lower() not in non_null)
199
+ place(facts, keys_enforced, "primary key" if primary else "unique key", unique_set, metadata)
200
+ for foreign_key in metadata.foreign_keys:
201
+ for target, target_metadata in by_identity.get(foreign_key.referenced.lower(), ()):
202
+ if _incomplete_reference(foreign_key, target_metadata):
203
+ continue # Never seen from a consistent catalog; no fact is safer than a wrong one.
204
+ referenced = {column.name.lower(): column for column in target.output_columns}
205
+ place([ReferentialCoverage(
206
+ columns=tuple(columns[name.lower()] for name in foreign_key.columns),
207
+ referenced_columns=tuple(referenced[name.lower()] for name in foreign_key.referenced_columns),
208
+ )], meaning.foreign_keys == "enforced", "foreign key", foreign_key.columns, metadata)
209
+ return CatalogFacts(tuple(knowledge), tuple(declarations), tuple(dict.fromkeys(warnings)))
210
+
211
+ @abstractmethod
212
+ def fetch_relation_metadata(
213
+ self, names: tuple[str, ...], scope: DatabaseRelationMetadata | None = None
214
+ ) -> Mapping[str, DatabaseRelationMetadata]:
215
+ """Resolve query-visible ``names`` and fetch each one's complete metadata.
216
+
217
+ ``scope`` is the view whose definition contains the names, or None for
218
+ the SQL Program itself. A name absent from the result does not exist.
219
+ Raises DatabaseMetadataError when the catalog cannot be read.
220
+ """
221
+
222
+ @abstractmethod
223
+ def fetch_view_definition(self, relation: DatabaseRelationMetadata) -> DatabaseViewDefinition:
224
+ """The stored definition of one view. Raises DatabaseMetadataError when unreadable."""
225
+
226
+
227
+ def _unique_sets(metadata: DatabaseRelationMetadata) -> tuple[tuple[str, ...], ...]:
228
+ return ((metadata.primary_key,) if metadata.primary_key else ()) + metadata.unique_sets
229
+
230
+
231
+ def _incompleteness(metadata: DatabaseRelationMetadata) -> str | None:
232
+ if metadata.kind is not DatabaseRelationKind.TABLE:
233
+ return None
234
+ if not metadata.columns:
235
+ return "has no columns"
236
+ names = {column.name.lower() for column in metadata.columns}
237
+ for unique_set in _unique_sets(metadata):
238
+ if not unique_set or not {name.lower() for name in unique_set} <= names:
239
+ return f"has a key ({quoted_all(unique_set)}) over columns it does not list"
240
+ for foreign_key in metadata.foreign_keys:
241
+ if not {name.lower() for name in foreign_key.columns} <= names or len(foreign_key.columns) != len(foreign_key.referenced_columns):
242
+ return f"has a foreign key ({quoted_all(foreign_key.columns)}) that does not pair columns it lists"
243
+ return None
244
+
245
+
246
+ def _incomplete_reference(foreign_key: DatabaseForeignKey, target: DatabaseRelationMetadata) -> bool:
247
+ names = {column.name.lower() for column in target.columns}
248
+ return not {name.lower() for name in foreign_key.referenced_columns} <= names
249
+
250
+
251
+ class _Hydration:
252
+ """The state of hydrating one SQL Program: catalog answers are memoized for it alone."""
253
+
254
+ def __init__(self, fetcher: DatabaseKnowledgeFetcher, ast: ParsedProgram, dialect: str, trust_unenforced_keys: bool):
255
+ self.fetcher = fetcher
256
+ self.ast = ast
257
+ self.dialect = dialect
258
+ self.trust_unenforced_keys = trust_unenforced_keys
259
+ self.sql_declared = {_qualified_name(table).lower() for table in map(_created_table, ast.create_statements) if table is not None}
260
+ self.resolved: dict[str, DatabaseRelationMetadata | None] = {}
261
+ self.views: dict[str, exp.Create | None] = {}
262
+ self.declarations: dict[str, exp.Create] = {}
263
+ self.tables: dict[str, DatabaseRelationMetadata] = {}
264
+ self.unavailable: set[str] = set()
265
+ self.diagnostics: list[Diagnostic] = []
266
+
267
+ def run(self) -> DatabaseHydration:
268
+ while True:
269
+ program = ParsedProgram((*self.declarations.values(), *self.ast.create_statements), self.ast.root_select)
270
+ conversion = IrParser(self.dialect, self.trust_unenforced_keys).parse(program)
271
+ pending = tuple(dict.fromkeys(
272
+ relation.name for relation in conversion.program.named_relations if self._is_external(relation)
273
+ ))
274
+ if not pending:
275
+ return DatabaseHydration(
276
+ conversion, dict(self.tables), tuple(dict.fromkeys(self.diagnostics)), self.dialect, self.trust_unenforced_keys,
277
+ )
278
+ self.resolved.update(self._resolve(tuple(name for name in pending if name.lower() not in self.resolved), None))
279
+ for name in pending:
280
+ self._declare(name, self.resolved[name.lower()])
281
+
282
+ def _is_external(self, relation: ir.NamedRelation) -> bool:
283
+ key = relation.name.lower()
284
+ return (
285
+ relation.role is ir.RelationRole.TABLE
286
+ and key not in self.sql_declared
287
+ and key not in self.declarations
288
+ and key not in self.unavailable
289
+ )
290
+
291
+ def _resolve(self, names: tuple[str, ...], scope: DatabaseRelationMetadata | None) -> dict[str, DatabaseRelationMetadata | None]:
292
+ if not names:
293
+ return {}
294
+ where = f" read by view {scope.identity}" if scope is not None else ""
295
+ try:
296
+ found = self.fetcher.fetch_relation_metadata(names, scope)
297
+ except DatabaseMetadataError as error:
298
+ self.diagnostics.append(Diagnostic(diag.CATALOG_METADATA_UNAVAILABLE, f"catalog metadata for {', '.join(names)}{where} could not be read: {error}"))
299
+ return dict.fromkeys((name.lower() for name in names), None)
300
+ resolved: dict[str, DatabaseRelationMetadata | None] = {}
301
+ for name in names:
302
+ metadata = found.get(name)
303
+ if metadata is None:
304
+ self.diagnostics.append(Diagnostic(diag.CATALOG_RELATION_NOT_FOUND, f"relation {name}{where} is not in the database catalog"))
305
+ resolved[name.lower()] = metadata
306
+ return resolved
307
+
308
+ def _declare(self, name: str, metadata: DatabaseRelationMetadata | None) -> None:
309
+ key = name.lower()
310
+ declaration = self._declaration(name, metadata) if metadata is not None else None
311
+ if declaration is None:
312
+ self.unavailable.add(key)
313
+ return
314
+ self.declarations[key] = declaration
315
+ if metadata is not None and metadata.kind is DatabaseRelationKind.TABLE:
316
+ self.tables[key] = metadata
317
+
318
+ def _declaration(self, name: str, metadata: DatabaseRelationMetadata) -> exp.Create | None:
319
+ problem = _incompleteness(metadata)
320
+ if problem is not None:
321
+ self.diagnostics.append(Diagnostic(diag.INCOMPLETE_CATALOG_METADATA, f"catalog relation {metadata.identity} {problem}", _origin(metadata)))
322
+ return None
323
+ target = _table(name)
324
+ if metadata.kind is DatabaseRelationKind.TABLE:
325
+ columns = [self._column_definition(column) for column in metadata.columns]
326
+ return exp.Create(kind="TABLE", this=exp.Schema(this=target, expressions=columns))
327
+ view = self._view(metadata)
328
+ if view is None:
329
+ return None
330
+ declaration = view.copy()
331
+ if isinstance(declaration.this, exp.Schema):
332
+ declaration.this.set("this", target)
333
+ else:
334
+ declaration.set("this", target)
335
+ return declaration
336
+
337
+ def _column_definition(self, column: DatabaseColumn) -> exp.ColumnDef:
338
+ """The column with its catalog type, so the Program
339
+ compares and enumerates it as the database does; untyped if the type
340
+ does not parse."""
341
+ definition = exp.ColumnDef(this=exp.to_identifier(column.name))
342
+ if column.data_type is None:
343
+ return definition
344
+ try:
345
+ kind = exp.DataType.build(column.data_type, dialect=self.fetcher.type_dialect)
346
+ except SqlglotError:
347
+ return definition
348
+ definition.set("kind", kind)
349
+ return definition
350
+
351
+ def _view(self, metadata: DatabaseRelationMetadata) -> exp.Create | None:
352
+ """The view's definition with every Relation it reads named by canonical identity, memoized."""
353
+ if metadata.identity not in self.views:
354
+ self.views[metadata.identity] = self._fetch_view(metadata)
355
+ return self.views[metadata.identity]
356
+
357
+ def _fetch_view(self, metadata: DatabaseRelationMetadata) -> exp.Create | None:
358
+ try:
359
+ definition = self.fetcher.fetch_view_definition(metadata)
360
+ except DatabaseMetadataError as error:
361
+ self.diagnostics.append(Diagnostic(diag.CATALOG_METADATA_UNAVAILABLE, f"definition of view {metadata.identity} could not be read: {error}", _origin(metadata)))
362
+ return None
363
+ parsed = SqlParser(self.dialect).parse(definition.sql)
364
+ self.diagnostics.extend(parsed.diagnostics)
365
+ create = parsed.create_statements[0] if len(parsed.create_statements) == 1 and parsed.root_select is None else None
366
+ body = create.args.get("expression") if isinstance(create, exp.Create) and (create.kind or "").upper() == "VIEW" else None
367
+ if not isinstance(create, exp.Create) or not isinstance(body, exp.Query) or parsed.diagnostics:
368
+ self.diagnostics.append(Diagnostic(diag.INCOMPLETE_CATALOG_METADATA, f"definition of view {metadata.identity} is not one analyzable CREATE VIEW statement", _origin(metadata)))
369
+ return None
370
+ try:
371
+ tables = [source for scope in traverse_scope(body) for source in scope.sources.values() if isinstance(source, exp.Table)]
372
+ except SqlglotError as error:
373
+ self.diagnostics.append(Diagnostic(diag.INCOMPLETE_CATALOG_METADATA, f"definition of view {metadata.identity} could not be scoped: {error}", _origin(metadata)))
374
+ return None
375
+
376
+ # Names inside a view resolve in the view's own scope, so they are
377
+ # rewritten to identities before they join the Program's global names.
378
+ resolved = self._resolve(tuple(dict.fromkeys(_qualified_name(table) for table in tables)), metadata)
379
+ if None in resolved.values():
380
+ return None
381
+ # A column qualified by its table's schema (MySQL stores `db`.`t`.`c`)
382
+ # is qualified by the alias the table is given below.
383
+ columns = [column for column in body.find_all(exp.Column) if column.args.get("db")]
384
+ for table in tables:
385
+ target = resolved[_qualified_name(table).lower()]
386
+ assert target is not None
387
+ for column in columns:
388
+ if not table.alias and _qualified_name(table).lower().endswith(".".join((column.db, column.table)).lower()):
389
+ column.set("db", None)
390
+ column.set("catalog", None)
391
+ self.resolved[target.identity.lower()] = target
392
+ alias = table.alias or table.name
393
+ table.set("this", exp.to_identifier(target.name))
394
+ table.set("db", exp.to_identifier(target.schema))
395
+ table.set("catalog", exp.to_identifier(target.catalog))
396
+ table.set("alias", exp.TableAlias(this=exp.to_identifier(alias)))
397
+ return create
398
+
399
+
400
+ def _origin(metadata: DatabaseRelationMetadata) -> Origin:
401
+ return Origin(CATALOG, metadata.identity)
402
+
403
+
404
+ def _table(name: str) -> exp.Table:
405
+ *qualifiers, table = name.split(".")
406
+ catalog, db = ([None, None] + qualifiers)[-2:]
407
+ return exp.table_(table, db=db, catalog=catalog)
408
+
409
+
410
+ def _created_table(statement: Expr) -> exp.Table | None:
411
+ target = statement.this if isinstance(statement, exp.Create) else None
412
+ if isinstance(target, exp.Schema):
413
+ target = target.this
414
+ return target if isinstance(target, exp.Table) else None
415
+
416
+
417
+ def _qualified_name(table: exp.Table) -> str:
418
+ return ".".join(part for part in (table.catalog, table.db, table.name) if part)