Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(db_engine_specs): mysql longtext type should not be numeric #10661

Merged
merged 1 commit into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion superset/db_engine_specs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,12 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
# default matching patterns for identifying column types
db_column_types: Dict[utils.DbColumnType, Tuple[Pattern[Any], ...]] = {
utils.DbColumnType.NUMERIC: (
re.compile(r"BIT", re.IGNORECASE),
re.compile(r".*DOUBLE.*", re.IGNORECASE),
re.compile(r".*FLOAT.*", re.IGNORECASE),
re.compile(r".*INT.*", re.IGNORECASE),
re.compile(r".*NUMBER.*", re.IGNORECASE),
re.compile(r".*LONG.*", re.IGNORECASE),
re.compile(r".*LONG$", re.IGNORECASE),
re.compile(r".*REAL.*", re.IGNORECASE),
re.compile(r".*NUMERIC.*", re.IGNORECASE),
re.compile(r".*DECIMAL.*", re.IGNORECASE),
Expand Down
39 changes: 39 additions & 0 deletions tests/db_engine_specs/mysql_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from sqlalchemy.dialects.mysql import DATE, NVARCHAR, TEXT, VARCHAR

from superset.db_engine_specs.mysql import MySQLEngineSpec
from superset.utils.core import DbColumnType
from tests.db_engine_specs.base_tests import TestDbEngineSpec


Expand Down Expand Up @@ -62,3 +63,41 @@ def test_column_datatype_to_string(self):
original, mysql.dialect()
)
self.assertEqual(actual, expected)

def test_is_db_column_type_match(self):
type_expectations = (
# Numeric
("TINYINT", DbColumnType.NUMERIC),
("SMALLINT", DbColumnType.NUMERIC),
("MEDIUMINT", DbColumnType.NUMERIC),
("INT", DbColumnType.NUMERIC),
("BIGINT", DbColumnType.NUMERIC),
("DECIMAL", DbColumnType.NUMERIC),
("FLOAT", DbColumnType.NUMERIC),
("DOUBLE", DbColumnType.NUMERIC),
("BIT", DbColumnType.NUMERIC),
# String
("CHAR", DbColumnType.STRING),
("VARCHAR", DbColumnType.STRING),
("TINYTEXT", DbColumnType.STRING),
("MEDIUMTEXT", DbColumnType.STRING),
("LONGTEXT", DbColumnType.STRING),
# Temporal
("DATE", DbColumnType.TEMPORAL),
("DATETIME", DbColumnType.TEMPORAL),
("TIMESTAMP", DbColumnType.TEMPORAL),
("TIME", DbColumnType.TEMPORAL),
)

for type_expectation in type_expectations:
type_str = type_expectation[0]
col_type = type_expectation[1]
assert MySQLEngineSpec.is_db_column_type_match(
type_str, DbColumnType.NUMERIC
) is (col_type == DbColumnType.NUMERIC)
assert MySQLEngineSpec.is_db_column_type_match(
type_str, DbColumnType.STRING
) is (col_type == DbColumnType.STRING)
assert MySQLEngineSpec.is_db_column_type_match(
type_str, DbColumnType.TEMPORAL
) is (col_type == DbColumnType.TEMPORAL)