You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2022/04/13 19:43:22 UTC

[superset] 01/01: convert column type in function

This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch fix-ds-save-array
in repository https://gitbox.apache.org/repos/asf/superset.git

commit c0ba42eb69439e789ba52cf396574d8b77431ff4
Author: hughhhh <hu...@gmail.com>
AuthorDate: Wed Apr 13 15:42:22 2022 -0400

    convert column type in function
---
 superset/connectors/sqla/utils.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/superset/connectors/sqla/utils.py b/superset/connectors/sqla/utils.py
index a2b54201d6..d635ea08f5 100644
--- a/superset/connectors/sqla/utils.py
+++ b/superset/connectors/sqla/utils.py
@@ -22,7 +22,7 @@ import sqlparse
 from flask_babel import lazy_gettext as _
 from sqlalchemy import and_, inspect, or_
 from sqlalchemy.engine import Engine
-from sqlalchemy.exc import NoSuchTableError
+from sqlalchemy.exc import NoSuchTableError, UnsupportedCompilationError
 from sqlalchemy.orm import Session
 from sqlalchemy.sql.type_api import TypeEngine
 
@@ -180,6 +180,16 @@ def is_column_type_temporal(column_type: TypeEngine) -> bool:
         return False
 
 
+def convert_column_type(column_type: TypeEngine) -> str:
+    try:
+        if column_type.python_type == list:
+            return "ARRAY"
+        else:
+            return str(column_type)
+    except UnsupportedCompilationError:
+        return "STRING"
+
+
 def load_or_create_tables(  # pylint: disable=too-many-arguments
     session: Session,
     database_id: int,
@@ -229,7 +239,7 @@ def load_or_create_tables(  # pylint: disable=too-many-arguments
             columns = [
                 NewColumn(
                     name=column["name"],
-                    type=str(column["type"]),
+                    type=convert_column_type(column["type"]),
                     expression=conditional_quote(column["name"]),
                     is_temporal=is_column_type_temporal(column["type"]),
                     is_aggregation=False,