Skip to content

Commit

Permalink
refactor TEMPORAL_TYPES
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Apr 7, 2022
1 parent 90ba057 commit b95fb1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions superset/connectors/sqla/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
from contextlib import closing
from datetime import date, datetime, time, timedelta
from typing import Callable, Dict, List, Optional, Set, TYPE_CHECKING

import sqlparse
Expand All @@ -41,7 +42,7 @@
from superset.connectors.sqla.models import SqlaTable


TEMPORAL_TYPES = {"DATETIME", "DATE", "TIME", "TIMEDELTA"}
TEMPORAL_TYPES = {date, datetime, time, timedelta}


def get_physical_table_metadata(
Expand Down Expand Up @@ -174,7 +175,7 @@ def validate_adhoc_subquery(

def is_column_type_temporal(column_type: TypeEngine) -> bool:
try:
return column_type.python_type.__name__.upper() in TEMPORAL_TYPES
return column_type.python_type in TEMPORAL_TYPES
except NotImplementedError:
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"""

import json
from datetime import date, datetime, time, timedelta
from typing import Callable, List, Optional, Set
from uuid import uuid4

Expand Down Expand Up @@ -231,12 +232,12 @@ class NewDataset(Base):
external_url = sa.Column(sa.Text, nullable=True)


TEMPORAL_TYPES = {"DATETIME", "DATE", "TIME", "TIMEDELTA"}
TEMPORAL_TYPES = {date, datetime, time, timedelta}


def is_column_type_temporal(column_type: TypeEngine) -> bool:
try:
return column_type.python_type.__name__.upper() in TEMPORAL_TYPES
return column_type.python_type in TEMPORAL_TYPES
except NotImplementedError:
return False

Expand Down

0 comments on commit b95fb1a

Please sign in to comment.