diff --git a/superset/db_engine_specs/base.py b/superset/db_engine_specs/base.py index f924ade58e..4ed9ec5e44 100644 --- a/superset/db_engine_specs/base.py +++ b/superset/db_engine_specs/base.py @@ -902,16 +902,18 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods return label_mutated @classmethod - def get_sqla_column_type(cls, type_: str) -> Optional[TypeEngine]: + def get_sqla_column_type(cls, type_: Optional[str]) -> Optional[TypeEngine]: """ Return a sqlalchemy native column type that corresponds to the column type defined in the data source (return None to use default type inferred by - SQLAlchemy). Override `_column_type_mappings` for specific needs + SQLAlchemy). Override `column_type_mappings` for specific needs (see MSSQL for example of NCHAR/NVARCHAR handling). :param type_: Column type returned by inspector :return: SqlAlchemy column type """ + if not type_: + return None for regex, sqla_type in cls.column_type_mappings: match = regex.match(type_) if match: diff --git a/superset/db_engine_specs/presto.py b/superset/db_engine_specs/presto.py index 9b2c47b307..bb8461311f 100644 --- a/superset/db_engine_specs/presto.py +++ b/superset/db_engine_specs/presto.py @@ -174,7 +174,9 @@ class PrestoEngineSpec(BaseEngineSpec): return [row[0] for row in results] @classmethod - def _create_column_info(cls, name: str, data_type: str) -> Dict[str, Any]: + def _create_column_info( + cls, name: str, data_type: types.TypeEngine + ) -> Dict[str, Any]: """ Create column info object :param name: column name @@ -265,8 +267,11 @@ class PrestoEngineSpec(BaseEngineSpec): # overall structural data type column_type = cls.get_sqla_column_type(field_info[1]) if column_type is None: - raise NotImplementedError( - _("Unknown column type: %(col)s", col=field_info[1]) + column_type = types.String() + logger.info( + "Did not recognize type %s of column %s", + field_info[1], + field_info[0], ) if field_info[1] == "array" or field_info[1] == "row": stack.append((field_info[0], field_info[1])) @@ -381,8 +386,11 @@ class PrestoEngineSpec(BaseEngineSpec): # otherwise column is a basic data type column_type = cls.get_sqla_column_type(column.Type) if column_type is None: - raise NotImplementedError( - _("Unknown column type: %(col)s", col=column_type) + column_type = types.String() + logger.info( + "Did not recognize type %s of column %s", + str(column.Type), + str(column.Column), ) column_info = cls._create_column_info(column.Column, column_type) column_info["nullable"] = getattr(column, "Null", True) diff --git a/tests/db_engine_specs/presto_tests.py b/tests/db_engine_specs/presto_tests.py index 3a0346bfe2..7045fc34ec 100644 --- a/tests/db_engine_specs/presto_tests.py +++ b/tests/db_engine_specs/presto_tests.py @@ -511,3 +511,6 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec): sqla_type = PrestoEngineSpec.get_sqla_column_type("integer") assert isinstance(sqla_type, types.Integer) + + sqla_type = PrestoEngineSpec.get_sqla_column_type(None) + assert sqla_type is None