fix: is_temporal should be overridden by is_dttm value (#11429)

This commit is contained in:
Ville Brofeldt 2020-10-27 07:22:27 +02:00 committed by GitHub
parent 94e0f0cc2a
commit 8575439f48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -180,7 +180,7 @@ function ColumnCollectionTable({
control={
<TextControl
controlId="python_date_format"
placeholder="%y/%m/%d"
placeholder="%Y/%m/%d"
/>
}
/>

View File

@ -181,6 +181,9 @@ class TableColumn(Model, BaseColumn):
@property
def is_numeric(self) -> bool:
"""
Check if the column has a numeric datatype.
"""
db_engine_spec = self.table.database.db_engine_spec
return db_engine_spec.is_db_column_type_match(
self.type, utils.DbColumnType.NUMERIC
@ -188,6 +191,9 @@ class TableColumn(Model, BaseColumn):
@property
def is_string(self) -> bool:
"""
Check if the column has a string datatype.
"""
db_engine_spec = self.table.database.db_engine_spec
return db_engine_spec.is_db_column_type_match(
self.type, utils.DbColumnType.STRING
@ -195,6 +201,14 @@ class TableColumn(Model, BaseColumn):
@property
def is_temporal(self) -> bool:
"""
Check if the column has a temporal datatype. If column has been set as
temporal/non-temporal (`is_dttm` is True or False respectively), return that
value. This usually happens during initial metadata fetching or when a column
is manually set as temporal (for this `python_date_format` needs to be set).
"""
if self.is_dttm is not None:
return self.is_dttm
db_engine_spec = self.table.database.db_engine_spec
return db_engine_spec.is_db_column_type_match(
self.type, utils.DbColumnType.TEMPORAL

View File

@ -44,6 +44,18 @@ class TestDatabaseModel(SupersetTestCase):
col = TableColumn(column_name="__not_time", type="INTEGER", table=tbl)
self.assertEqual(col.is_temporal, False)
def test_temporal_varchar(self):
"""Ensure a column with is_dttm set to true evaluates to is_temporal == True"""
database = get_example_database()
tbl = SqlaTable(table_name="test_tbl", database=database)
col = TableColumn(column_name="ds", type="VARCHAR", table=tbl)
# by default, VARCHAR should not be assumed to be temporal
assert col.is_temporal is False
# changing to `is_dttm = True`, calling `is_temporal` should return True
col.is_dttm = True
assert col.is_temporal is True
def test_db_column_types(self):
test_cases: Dict[str, DbColumnType] = {
# string