diff --git a/superset/db_engine_specs/base.py b/superset/db_engine_specs/base.py index 502cd6e0673e8..f4a8408fb5ec3 100644 --- a/superset/db_engine_specs/base.py +++ b/superset/db_engine_specs/base.py @@ -878,16 +878,18 @@ def make_label_compatible(cls, label: str) -> Union[str, quoted_name]: 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 9b2c47b307667..bb8461311f690 100644 --- a/superset/db_engine_specs/presto.py +++ b/superset/db_engine_specs/presto.py @@ -174,7 +174,9 @@ def get_view_names( 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 @@ def _parse_structural_column( # pylint: disable=too-many-locals,too-many-branch # 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 @@ def get_columns( # 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 3a0346bfe2591..7045fc34ecb05 100644 --- a/tests/db_engine_specs/presto_tests.py +++ b/tests/db_engine_specs/presto_tests.py @@ -511,3 +511,6 @@ def test_get_sqla_column_type(self): 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