You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by se...@apache.org on 2022/02/28 18:28:05 UTC

[superset] branch master updated: feat(TimeTableViz): sort by first metric (#18896)

This is an automated email from the ASF dual-hosted git repository.

serena pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 760dab9  feat(TimeTableViz): sort by first metric (#18896)
760dab9 is described below

commit 760dab9abdb2199b50006e01cb1e9cc0743cf966
Author: serenajiang <se...@airbnb.com>
AuthorDate: Mon Feb 28 10:26:24 2022 -0800

    feat(TimeTableViz): sort by first metric (#18896)
---
 superset/viz.py                      | 5 +++++
 tests/integration_tests/viz_tests.py | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/superset/viz.py b/superset/viz.py
index 26c77c1..3a519bb 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -854,6 +854,11 @@ class TimeTableViz(BaseViz):
             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:
diff --git a/tests/integration_tests/viz_tests.py b/tests/integration_tests/viz_tests.py
index b9055af..465fdb2 100644
--- a/tests/integration_tests/viz_tests.py
+++ b/tests/integration_tests/viz_tests.py
@@ -1067,6 +1067,13 @@ class TestTimeSeriesTableViz(SupersetTestCase):
         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):