diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-01-31 05:44:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-01-31 05:44:41 +0000 |
commit | 376de8b6892deca7dc5d83035c047f1e13eb67ea (patch) | |
tree | 334a1753cd914294aa99128fac3fb59bf14dc10f /sqlglot/schema.py | |
parent | Releasing debian version 20.9.0-1. (diff) | |
download | sqlglot-376de8b6892deca7dc5d83035c047f1e13eb67ea.tar.xz sqlglot-376de8b6892deca7dc5d83035c047f1e13eb67ea.zip |
Merging upstream version 20.11.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/schema.py')
-rw-r--r-- | sqlglot/schema.py | 19 |
1 files changed, 15 insertions, 4 deletions
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 |