From 376de8b6892deca7dc5d83035c047f1e13eb67ea Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 31 Jan 2024 06:44:41 +0100 Subject: Merging upstream version 20.11.0. Signed-off-by: Daniel Baumann --- sqlglot/schema.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'sqlglot/schema.py') diff --git a/sqlglot/schema.py b/sqlglot/schema.py index 8acd89f..13f72d6 100644 --- a/sqlglot/schema.py +++ b/sqlglot/schema.py @@ -106,6 +106,19 @@ class Schema(abc.ABC): name = column if isinstance(column, str) else column.name return name in self.column_names(table, dialect=dialect, normalize=normalize) + @abc.abstractmethod + def find(self, table: exp.Table, raise_on_missing: bool = True) -> t.Optional[t.Any]: + """ + Returns the schema of a given table. + + Args: + table: the target table. + raise_on_missing: whether or not to raise in case the schema is not found. + + Returns: + The schema of the target table. + """ + @property @abc.abstractmethod def supported_table_args(self) -> t.Tuple[str, ...]: @@ -156,11 +169,9 @@ class AbstractMappingSchema: return [table.this.name] return [table.text(part) for part in exp.TABLE_PARTS if table.text(part)] - def find( - self, table: exp.Table, trie: t.Optional[t.Dict] = None, raise_on_missing: bool = True - ) -> t.Optional[t.Any]: + def find(self, table: exp.Table, raise_on_missing: bool = True) -> t.Optional[t.Any]: parts = self.table_parts(table)[0 : len(self.supported_table_args)] - value, trie = in_trie(self.mapping_trie if trie is None else trie, parts) + value, trie = in_trie(self.mapping_trie, parts) if value == TrieResult.FAILED: return None -- cgit v1.2.3