Skip to content

Commit

Permalink
fix: is_temporal should be overridden by is_dttm value
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Oct 26, 2020
1 parent ac498dd commit 578f9a6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion superset-frontend/src/datasource/DatasourceEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function ColumnCollectionTable({
control={
<TextControl
controlId="python_date_format"
placeholder="%y/%m/%d"
placeholder="%Y/%m/%d"
/>
}
/>
Expand Down
14 changes: 14 additions & 0 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,34 @@ 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
)

@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
)

@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
Expand Down
12 changes: 12 additions & 0 deletions tests/sqla_models_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ def test_is_time_druid_time_col(self):
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
Expand Down

0 comments on commit 578f9a6

Please sign in to comment.