Skip to content

Commit

Permalink
fix(sqla): copy temporal range logic to helper (#22405)
Browse files Browse the repository at this point in the history
Co-authored-by: Ville Brofeldt <ville.brofeldt@apple.com>
  • Loading branch information
villebro and villebro committed Dec 14, 2022
1 parent 92fc304 commit 1014a32
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
from superset import app, is_feature_enabled, security_manager
from superset.advanced_data_type.types import AdvancedDataTypeResponse
from superset.common.db_query_status import QueryStatus
from superset.common.utils.time_range_utils import get_since_until_from_time_range
from superset.constants import EMPTY_STRING, NULL_STRING
from superset.db_engine_specs.base import TimestampExpression
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
Expand Down Expand Up @@ -1236,8 +1237,8 @@ def dttm_sql_literal(self, dttm: sa.DateTime, col_type: Optional[str]) -> str:
def get_time_filter(
self,
time_col: Dict[str, Any],
start_dttm: sa.DateTime,
end_dttm: sa.DateTime,
start_dttm: Optional[sa.DateTime],
end_dttm: Optional[sa.DateTime],
) -> ColumnElement:
label = "__time"
col = time_col.get("column_name")
Expand Down Expand Up @@ -1779,6 +1780,23 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
where_clause_and.append(sqla_col.like(eq))
elif op == utils.FilterOperator.ILIKE.value:
where_clause_and.append(sqla_col.ilike(eq))
elif (
op == utils.FilterOperator.TEMPORAL_RANGE.value
and isinstance(eq, str)
and col_obj is not None
):
_since, _until = get_since_until_from_time_range(
time_range=eq,
time_shift=time_shift,
extras=extras,
)
where_clause_and.append(
self.get_time_filter(
time_col=col_obj,
start_dttm=_since,
end_dttm=_until,
)
)
else:
raise QueryObjectValidationError(
_("Invalid filter operation type: %(op)s", op=op)
Expand Down

0 comments on commit 1014a32

Please sign in to comment.