Skip to content

Commit

Permalink
fix: series limit solution for source is query (apache#20977)
Browse files Browse the repository at this point in the history
* fix

* save

* integrate type casting for engiines

* fix orderby on column types

* fixes

Co-authored-by: Hugh A. Miles II <hughmil3s@gmail.com>
  • Loading branch information
AAfghahi and hughhhh committed Aug 4, 2022
1 parent d42cf4e commit e350823
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,14 +888,26 @@ def _normalize_prequery_result_type(
column_ = columns_by_name[dimension]
db_extra: Dict[str, Any] = self.database.get_extra() # type: ignore

if column_.type and column_.is_temporal and isinstance(value, str):
sql = self.db_engine_spec.convert_dttm(
column_.type, dateutil.parser.parse(value), db_extra=db_extra
)
if isinstance(column_, dict):
if (
column_.get("type")
and column_.get("is_temporal")
and isinstance(value, str)
):
sql = self.db_engine_spec.convert_dttm(
column_.get("type"), dateutil.parser.parse(value), db_extra=None
)

if sql:
value = self.text(sql)
if sql:
value = self.db_engine_spec.get_text_clause(sql)
else:
if column_.type and column_.is_temporal and isinstance(value, str):
sql = self.db_engine_spec.convert_dttm(
column_.type, dateutil.parser.parse(value), db_extra=db_extra
)

if sql:
value = self.text(sql)
return value

def make_orderby_compatible(
Expand Down Expand Up @@ -1827,12 +1839,22 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
inner_time_filter = []

if dttm_col and not db_engine_spec.time_groupby_inline:
inner_time_filter = [
dttm_col.get_time_filter(
inner_from_dttm or from_dttm,
inner_to_dttm or to_dttm,
)
]
if isinstance(dttm_col, dict):
inner_time_filter = [
self.get_time_filter(
dttm_col,
inner_from_dttm or from_dttm,
inner_to_dttm or to_dttm,
)
]
else:
inner_time_filter = [
dttm_col.get_time_filter(
inner_from_dttm or from_dttm,
inner_to_dttm or to_dttm,
)
]

subq = subq.where(and_(*(where_clause_and + inner_time_filter)))
subq = subq.group_by(*inner_groupby_exprs)

Expand Down Expand Up @@ -1866,8 +1888,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
"columns": columns,
"order_desc": True,
}

result = self.query(prequery_obj) # type: ignore
result = self.exc_query(prequery_obj)
prequeries.append(result.query)
dimensions = [
c
Expand Down

0 comments on commit e350823

Please sign in to comment.