From 7992bc39caba65eb44f9f559b1519356f164035d Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Sat, 3 Oct 2020 09:32:48 -0700 Subject: [PATCH 1/2] draft: questioning a few lines that force an ORDER clause --- superset/connectors/sqla/models.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py index 934da17c73dc..dfe6b6a96597 100644 --- a/superset/connectors/sqla/models.py +++ b/superset/connectors/sqla/models.py @@ -1082,9 +1082,6 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma qry = qry.where(and_(*where_clause_and)) qry = qry.having(and_(*having_clause_and)) - if not orderby and ((is_sip_38 and metrics) or (not is_sip_38 and not columns)): - orderby = [(main_metric_expr, not order_desc)] - # To ensure correct handling of the ORDER BY labeling we need to reference the # metric instance if defined in the SELECT clause. metrics_exprs_by_label = { From 22aa5c911b2adaeb63ce297d68bfb6fce33a824e Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Mon, 12 Oct 2020 11:55:34 -0700 Subject: [PATCH 2/2] sorting by main metric DESC by default --- .../src/views/CRUD/data/database/DatabaseList.tsx | 2 +- superset/viz.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx index 7e28541d57e9..4b436ec3a4a6 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx @@ -180,7 +180,7 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) { Header: ( {t('DML')} diff --git a/superset/viz.py b/superset/viz.py index 515b4adca95b..8dabed663b4c 100644 --- a/superset/viz.py +++ b/superset/viz.py @@ -724,6 +724,10 @@ def query_obj(self) -> QueryObjectDict: if sort_by_label not in d["metrics"]: d["metrics"].append(sort_by) d["orderby"] = [(sort_by, not fd.get("order_desc", True))] + elif d["metrics"]: + # Legacy behavior of sorting by first metric by default + first_metric = d["metrics"][0] + d["orderby"] = [(first_metric, not fd.get("order_desc", True))] return d def get_data(self, df: pd.DataFrame) -> VizData: