This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new c44ae61 Improve Unicode support for MSSQL (#6690)
c44ae61 is described below
commit c44ae612dfc797e2002134cc3fc78eb7057beeed
Author: Ville Brofeldt <[email protected]>
AuthorDate: Tue Jan 29 08:56:46 2019 +0200
Improve Unicode support for MSSQL (#6690)
* Implement unicode where cluases for mssql queries
* Add comment about unicode support on sqla 1.3+
---
docs/installation.rst | 5 +++++
superset/connectors/sqla/models.py | 4 +++-
superset/db_engine_specs.py | 16 ++++++++++++++++
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/docs/installation.rst b/docs/installation.rst
index ecce52f..85183c0 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -405,6 +405,11 @@ You can also use `PyAthena` library(no java required) like
this ::
See `PyAthena <https://github.com/laughingman7743/PyAthena#sqlalchemy>`_.
+MSSQL
+-----
+
+Full Unicode support requires SQLAlchemy 1.3 or later.
+
Snowflake
---------
diff --git a/superset/connectors/sqla/models.py
b/superset/connectors/sqla/models.py
index 8a21f52..73f45c4 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -115,7 +115,9 @@ class TableColumn(Model, BaseColumn):
label = label if label else self.column_name
label = self.table.get_label(label)
if not self.expression:
- col = column(self.column_name).label(label)
+ db_engine_spec = self.table.database.db_engine_spec
+ type_ = db_engine_spec.get_sqla_column_type(self.type)
+ col = column(self.column_name, type_=type_).label(label)
else:
col = literal_column(self.expression).label(label)
return col
diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index f724781..937537b 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -46,6 +46,7 @@ from sqlalchemy.engine import create_engine
from sqlalchemy.engine.url import make_url
from sqlalchemy.sql import quoted_name, text
from sqlalchemy.sql.expression import TextAsFrom
+from sqlalchemy.types import UnicodeText
import sqlparse
from werkzeug.utils import secure_filename
@@ -400,6 +401,15 @@ class BaseEngineSpec(object):
label = cls.mutate_label(label)
return quoted_name(label, True) if cls.force_column_alias_quotes else
label
+ @classmethod
+ def get_sqla_column_type(cls, type_):
+ """
+ Return a sqlalchemy native column type that corresponds to the column
type
+ defined in the data source (optional). Needs to be overridden if
column requires
+ special handling (see MSSQL for example of NCHAR/NVARCHAR handling).
+ """
+ return None
+
@staticmethod
def mutate_label(label):
"""
@@ -1362,6 +1372,12 @@ class MssqlEngineSpec(BaseEngineSpec):
data = [[elem for elem in r] for r in data]
return data
+ @classmethod
+ def get_sqla_column_type(cls, type_):
+ if isinstance(type_, str) and re.match(r'^N(VAR){0-1}CHAR', type_):
+ return UnicodeText()
+ return None
+
class AthenaEngineSpec(BaseEngineSpec):
engine = 'awsathena'