Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AAfghahi committed Aug 4, 2022
1 parent 74af5f5 commit c89a916
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 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
5 changes: 0 additions & 5 deletions superset/models/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,8 @@ def columns(self) -> List[ResultSetColumnType]:
@property
def data(self) -> Dict[str, Any]:
order_by_choices = []
<<<<<<< HEAD
for col in self.columns:
column_name = str(col.get("column_name") or "")
=======
for c in self.columns:
column_name = str(c.get("column_name") or "")
>>>>>>> f3e68482a (fix orderby on column types)
order_by_choices.append(
(json.dumps([column_name, True]), column_name + " [asc]")
)
Expand Down

0 comments on commit c89a916

Please sign in to comment.