You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by dp...@apache.org on 2020/09/22 13:29:18 UTC
[incubator-superset] 09/09: fix(presto): default unknown types to
string type (#10753)
This is an automated email from the ASF dual-hosted git repository.
dpgaspar pushed a commit to branch 0.38
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit eba85d590309bc3b9461242567dbe8175453ad12
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Tue Sep 22 13:16:54 2020 +0300
fix(presto): default unknown types to string type (#10753)
* fix(presto): default unknown types to string type
* lint
---
superset/db_engine_specs/base.py | 6 ++++--
superset/db_engine_specs/presto.py | 18 +++++++++++++-----
tests/db_engine_specs/presto_tests.py | 3 +++
3 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/superset/db_engine_specs/base.py b/superset/db_engine_specs/base.py
index 502cd6e..f4a8408 100644
--- a/superset/db_engine_specs/base.py
+++ b/superset/db_engine_specs/base.py
@@ -878,16 +878,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 9b2c47b..bb84613 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 3a0346b..7045fc3 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