You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2022/02/04 08:49:41 UTC
[superset] branch master updated: fix(sqla): avoid unnecessary groupby for when no metrics (#18579)
This is an automated email from the ASF dual-hosted git repository.
villebro 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 55cd7fb fix(sqla): avoid unnecessary groupby for when no metrics (#18579)
55cd7fb is described below
commit 55cd7fb412a497b124633f596ff351358448bea9
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Fri Feb 4 10:47:47 2022 +0200
fix(sqla): avoid unnecessary groupby for when no metrics (#18579)
---
superset/charts/schemas.py | 5 ++++-
superset/common/query_actions.py | 2 +-
tests/integration_tests/charts/data/api_tests.py | 3 +++
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/superset/charts/schemas.py b/superset/charts/schemas.py
index 225410e..b25f971 100644
--- a/superset/charts/schemas.py
+++ b/superset/charts/schemas.py
@@ -598,7 +598,10 @@ class ChartDataBoxplotOptionsSchema(ChartDataPostProcessingOperationOptionsSchem
description="Aggregate expressions. Metrics can be passed as both "
"references to datasource metrics (strings), or ad-hoc metrics"
"which are defined only within the query object. See "
- "`ChartDataAdhocMetricSchema` for the structure of ad-hoc metrics.",
+ "`ChartDataAdhocMetricSchema` for the structure of ad-hoc metrics. "
+ "When metrics is undefined or null, the query is executed without a groupby. "
+ "However, when metrics is an array (length >= 0), a groupby clause is added to "
+ "the query.",
allow_none=True,
)
diff --git a/superset/common/query_actions.py b/superset/common/query_actions.py
index 6ed18d1..ecdf00d 100644
--- a/superset/common/query_actions.py
+++ b/superset/common/query_actions.py
@@ -140,7 +140,7 @@ def _get_samples(
query_obj = copy.copy(query_obj)
query_obj.is_timeseries = False
query_obj.orderby = []
- query_obj.metrics = []
+ query_obj.metrics = None
query_obj.post_processing = []
query_obj.columns = [o.column_name for o in datasource.columns]
query_obj.from_dttm = None
diff --git a/tests/integration_tests/charts/data/api_tests.py b/tests/integration_tests/charts/data/api_tests.py
index 8d9797f..d6ccd6a 100644
--- a/tests/integration_tests/charts/data/api_tests.py
+++ b/tests/integration_tests/charts/data/api_tests.py
@@ -154,6 +154,7 @@ class TestPostChartDataApi(BaseTestChartDataApi):
# assert
self.assert_row_count(rv, expected_row_count)
+ assert "GROUP BY" not in rv.json["result"][0]["query"]
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@mock.patch(
@@ -184,6 +185,7 @@ class TestPostChartDataApi(BaseTestChartDataApi):
# assert
self.assert_row_count(rv, expected_row_count)
+ assert "GROUP BY" not in rv.json["result"][0]["query"]
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@mock.patch(
@@ -200,6 +202,7 @@ class TestPostChartDataApi(BaseTestChartDataApi):
# assert
self.assert_row_count(rv, expected_row_count)
+ assert "GROUP BY" not in rv.json["result"][0]["query"]
def test_with_incorrect_result_type__400(self):
self.query_context_payload["result_type"] = "qwerty"