You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2020/02/26 05:34:46 UTC

[incubator-superset] branch master updated: [Bug Fix] Returning timeseries_limit_metric in table viz get_data (#9196)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4f73f8a  [Bug Fix] Returning timeseries_limit_metric in table viz get_data (#9196)
4f73f8a is described below

commit 4f73f8a1f9fec7f15ec760d6d98617bbe04f4023
Author: michellethomas <mi...@gmail.com>
AuthorDate: Tue Feb 25 21:34:36 2020 -0800

    [Bug Fix] Returning timeseries_limit_metric in table viz get_data (#9196)
    
    * Returning timeseries_limit_metric in table viz get_data
    
    * Fixing issue with include_time field
    
    * Reformatting and adding a test
    
    * Changing if/else structure
    
    * Reformatting
---
 superset/viz.py    | 25 ++++++++++++++++++++-----
 tests/viz_tests.py | 26 ++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/superset/viz.py b/superset/viz.py
index 8391f18..d7299ae 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -575,15 +575,30 @@ class TableViz(BaseViz):
         the percent metrics have yet to be transformed.
         """
 
-        if not self.should_be_timeseries() and DTTM_ALIAS in df:
-            del df[DTTM_ALIAS]
-
+        non_percent_metric_columns = []
         # Transform the data frame to adhere to the UI ordering of the columns and
         # metrics whilst simultaneously computing the percentages (via normalization)
         # for the percent metrics.
-        non_percent_metric_columns = (
+
+        if DTTM_ALIAS in df:
+            if self.should_be_timeseries():
+                non_percent_metric_columns.append(DTTM_ALIAS)
+            else:
+                del df[DTTM_ALIAS]
+
+        non_percent_metric_columns.extend(
             self.form_data.get("all_columns") or self.form_data.get("groupby") or []
-        ) + utils.get_metric_names(self.form_data.get("metrics") or [])
+        )
+
+        non_percent_metric_columns.extend(
+            utils.get_metric_names(self.form_data.get("metrics") or [])
+        )
+
+        timeseries_limit_metric = utils.get_metric_name(
+            self.form_data.get("timeseries_limit_metric")
+        )
+        if timeseries_limit_metric:
+            non_percent_metric_columns.append(timeseries_limit_metric)
 
         percent_metric_columns = utils.get_metric_names(
             self.form_data.get("percent_metrics") or []
diff --git a/tests/viz_tests.py b/tests/viz_tests.py
index a86b2a8..6f23c6a 100644
--- a/tests/viz_tests.py
+++ b/tests/viz_tests.py
@@ -407,6 +407,32 @@ class TableVizTestCase(SupersetTestCase):
         with self.assertRaises(Exception):
             test_viz.should_be_timeseries()
 
+    def test_adhoc_metric_with_sortby(self):
+        metrics = [
+            {
+                "expressionType": "SIMPLE",
+                "aggregate": "SUM",
+                "label": "sum_value",
+                "column": {"column_name": "value1", "type": "DOUBLE"},
+            }
+        ]
+        form_data = {
+            "metrics": metrics,
+            "timeseries_limit_metric": {
+                "expressionType": "SIMPLE",
+                "aggregate": "SUM",
+                "label": "SUM(value1)",
+                "column": {"column_name": "value1", "type": "DOUBLE"},
+            },
+            "order_desc": False,
+        }
+
+        df = pd.DataFrame({"SUM(value1)": [15], "sum_value": [15]})
+        datasource = self.get_datasource_mock()
+        test_viz = viz.TableViz(datasource, form_data)
+        data = test_viz.get_data(df)
+        self.assertEqual(["sum_value", "SUM(value1)"], data["columns"])
+
 
 class DistBarVizTestCase(SupersetTestCase):
     def test_groupby_nulls(self):