summaryrefslogtreecommitdiffstats
path: root/sqlglot/schema.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-12-22 07:22:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-12-22 07:23:29 +0000
commitd5c2cca0ebcd090fb36660f7f900b75452782aa5 (patch)
tree9169d15c801dda9ff3f417a886f4c3e4b9bd2308 /sqlglot/schema.py
parentReleasing debian version 10.2.6-1. (diff)
downloadsqlglot-d5c2cca0ebcd090fb36660f7f900b75452782aa5.tar.xz
sqlglot-d5c2cca0ebcd090fb36660f7f900b75452782aa5.zip
Merging upstream version 10.2.9.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/schema.py')
-rw-r--r--sqlglot/schema.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/sqlglot/schema.py b/sqlglot/schema.py
index 8a264a2..c223ee0 100644
--- a/sqlglot/schema.py
+++ b/sqlglot/schema.py
@@ -237,12 +237,17 @@ class MappingSchema(AbstractMappingSchema[t.Dict[str, str]], Schema):
if table_:
table_schema = self.find(table_, raise_on_missing=False)
if table_schema:
- schema_type = table_schema.get(column_name).upper() # type: ignore
- return self._convert_type(schema_type)
+ column_type = table_schema.get(column_name)
+
+ if isinstance(column_type, exp.DataType):
+ return column_type
+ elif isinstance(column_type, str):
+ return self._to_data_type(column_type.upper())
+ raise SchemaError(f"Unknown column type '{column_type}'")
return exp.DataType(this=exp.DataType.Type.UNKNOWN)
raise SchemaError(f"Could not convert table '{table}'")
- def _convert_type(self, schema_type: str) -> exp.DataType:
+ def _to_data_type(self, schema_type: str) -> exp.DataType:
"""
Convert a type represented as a string to the corresponding :class:`sqlglot.exp.DataType` object.