Skip to content

Commit

Permalink
feat(TimeTableViz): sort by first metric (#18896)
Browse files Browse the repository at this point in the history
  • Loading branch information
serenajiang committed Feb 28, 2022
1 parent eafe0cf commit 760dab9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,11 @@ def query_obj(self) -> QueryObjectDict:
raise QueryObjectValidationError(
_("When using 'Group By' you are limited to use a single metric")
)

sort_by = utils.get_first_metric_name(query_obj["metrics"])
is_asc = not query_obj.get("order_desc")
query_obj["orderby"] = [(sort_by, is_asc)]

return query_obj

def get_data(self, df: pd.DataFrame) -> VizData:
Expand Down
7 changes: 7 additions & 0 deletions tests/integration_tests/viz_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,13 @@ def test_query_obj_throws_metrics_and_groupby(self, super_query_obj):
with self.assertRaises(Exception):
test_viz.query_obj()

def test_query_obj_order_by(self):
test_viz = viz.TimeTableViz(
self.get_datasource_mock(), {"metrics": ["sum__A", "count"], "groupby": []}
)
query_obj = test_viz.query_obj()
self.assertEqual(query_obj["orderby"], [("sum__A", False)])


class TestBaseDeckGLViz(SupersetTestCase):
def test_get_metrics(self):
Expand Down

0 comments on commit 760dab9

Please sign in to comment.