mirror of
https://github.com/apache/superset.git
synced 2026-04-20 08:34:37 +00:00
refactor: rename DbColumnType to GenericDataType (#12617)
This commit is contained in:
@@ -20,7 +20,7 @@ from sqlalchemy.dialects import mysql
|
||||
from sqlalchemy.dialects.mysql import DATE, NVARCHAR, TEXT, VARCHAR
|
||||
|
||||
from superset.db_engine_specs.mysql import MySQLEngineSpec
|
||||
from superset.utils.core import DbColumnType
|
||||
from superset.utils.core import GenericDataType
|
||||
from tests.db_engine_specs.base_tests import TestDbEngineSpec
|
||||
|
||||
|
||||
@@ -67,40 +67,40 @@ class TestMySQLEngineSpecsDbEngineSpec(TestDbEngineSpec):
|
||||
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),
|
||||
("TINYINT", GenericDataType.NUMERIC),
|
||||
("SMALLINT", GenericDataType.NUMERIC),
|
||||
("MEDIUMINT", GenericDataType.NUMERIC),
|
||||
("INT", GenericDataType.NUMERIC),
|
||||
("BIGINT", GenericDataType.NUMERIC),
|
||||
("DECIMAL", GenericDataType.NUMERIC),
|
||||
("FLOAT", GenericDataType.NUMERIC),
|
||||
("DOUBLE", GenericDataType.NUMERIC),
|
||||
("BIT", GenericDataType.NUMERIC),
|
||||
# String
|
||||
("CHAR", DbColumnType.STRING),
|
||||
("VARCHAR", DbColumnType.STRING),
|
||||
("TINYTEXT", DbColumnType.STRING),
|
||||
("MEDIUMTEXT", DbColumnType.STRING),
|
||||
("LONGTEXT", DbColumnType.STRING),
|
||||
("CHAR", GenericDataType.STRING),
|
||||
("VARCHAR", GenericDataType.STRING),
|
||||
("TINYTEXT", GenericDataType.STRING),
|
||||
("MEDIUMTEXT", GenericDataType.STRING),
|
||||
("LONGTEXT", GenericDataType.STRING),
|
||||
# Temporal
|
||||
("DATE", DbColumnType.TEMPORAL),
|
||||
("DATETIME", DbColumnType.TEMPORAL),
|
||||
("TIMESTAMP", DbColumnType.TEMPORAL),
|
||||
("TIME", DbColumnType.TEMPORAL),
|
||||
("DATE", GenericDataType.TEMPORAL),
|
||||
("DATETIME", GenericDataType.TEMPORAL),
|
||||
("TIMESTAMP", GenericDataType.TEMPORAL),
|
||||
("TIME", GenericDataType.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)
|
||||
type_str, GenericDataType.NUMERIC
|
||||
) is (col_type == GenericDataType.NUMERIC)
|
||||
assert MySQLEngineSpec.is_db_column_type_match(
|
||||
type_str, DbColumnType.STRING
|
||||
) is (col_type == DbColumnType.STRING)
|
||||
type_str, GenericDataType.STRING
|
||||
) is (col_type == GenericDataType.STRING)
|
||||
assert MySQLEngineSpec.is_db_column_type_match(
|
||||
type_str, DbColumnType.TEMPORAL
|
||||
) is (col_type == DbColumnType.TEMPORAL)
|
||||
type_str, GenericDataType.TEMPORAL
|
||||
) is (col_type == GenericDataType.TEMPORAL)
|
||||
|
||||
def test_extract_error_message(self):
|
||||
from MySQLdb._exceptions import OperationalError
|
||||
|
||||
@@ -26,7 +26,7 @@ from superset.connectors.sqla.models import SqlaTable, TableColumn
|
||||
from superset.db_engine_specs.druid import DruidEngineSpec
|
||||
from superset.exceptions import QueryObjectValidationError
|
||||
from superset.models.core import Database
|
||||
from superset.utils.core import DbColumnType, get_example_database, FilterOperator
|
||||
from superset.utils.core import GenericDataType, get_example_database, FilterOperator
|
||||
from tests.fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices
|
||||
|
||||
from .base_tests import SupersetTestCase
|
||||
@@ -76,33 +76,33 @@ class TestDatabaseModel(SupersetTestCase):
|
||||
assert col.is_temporal is True
|
||||
|
||||
def test_db_column_types(self):
|
||||
test_cases: Dict[str, DbColumnType] = {
|
||||
test_cases: Dict[str, GenericDataType] = {
|
||||
# string
|
||||
"CHAR": DbColumnType.STRING,
|
||||
"VARCHAR": DbColumnType.STRING,
|
||||
"NVARCHAR": DbColumnType.STRING,
|
||||
"STRING": DbColumnType.STRING,
|
||||
"TEXT": DbColumnType.STRING,
|
||||
"NTEXT": DbColumnType.STRING,
|
||||
"CHAR": GenericDataType.STRING,
|
||||
"VARCHAR": GenericDataType.STRING,
|
||||
"NVARCHAR": GenericDataType.STRING,
|
||||
"STRING": GenericDataType.STRING,
|
||||
"TEXT": GenericDataType.STRING,
|
||||
"NTEXT": GenericDataType.STRING,
|
||||
# numeric
|
||||
"INT": DbColumnType.NUMERIC,
|
||||
"BIGINT": DbColumnType.NUMERIC,
|
||||
"FLOAT": DbColumnType.NUMERIC,
|
||||
"DECIMAL": DbColumnType.NUMERIC,
|
||||
"MONEY": DbColumnType.NUMERIC,
|
||||
"INT": GenericDataType.NUMERIC,
|
||||
"BIGINT": GenericDataType.NUMERIC,
|
||||
"FLOAT": GenericDataType.NUMERIC,
|
||||
"DECIMAL": GenericDataType.NUMERIC,
|
||||
"MONEY": GenericDataType.NUMERIC,
|
||||
# temporal
|
||||
"DATE": DbColumnType.TEMPORAL,
|
||||
"DATETIME": DbColumnType.TEMPORAL,
|
||||
"TIME": DbColumnType.TEMPORAL,
|
||||
"TIMESTAMP": DbColumnType.TEMPORAL,
|
||||
"DATE": GenericDataType.TEMPORAL,
|
||||
"DATETIME": GenericDataType.TEMPORAL,
|
||||
"TIME": GenericDataType.TEMPORAL,
|
||||
"TIMESTAMP": GenericDataType.TEMPORAL,
|
||||
}
|
||||
|
||||
tbl = SqlaTable(table_name="col_type_test_tbl", database=get_example_database())
|
||||
for str_type, db_col_type in test_cases.items():
|
||||
col = TableColumn(column_name="foo", type=str_type, table=tbl)
|
||||
self.assertEqual(col.is_temporal, db_col_type == DbColumnType.TEMPORAL)
|
||||
self.assertEqual(col.is_numeric, db_col_type == DbColumnType.NUMERIC)
|
||||
self.assertEqual(col.is_string, db_col_type == DbColumnType.STRING)
|
||||
self.assertEqual(col.is_temporal, db_col_type == GenericDataType.TEMPORAL)
|
||||
self.assertEqual(col.is_numeric, db_col_type == GenericDataType.NUMERIC)
|
||||
self.assertEqual(col.is_string, db_col_type == GenericDataType.STRING)
|
||||
|
||||
@patch("superset.jinja_context.g")
|
||||
def test_extra_cache_keys(self, flask_g):
|
||||
|
||||
Reference in New Issue
Block a user