Skip to content

Commit

Permalink
fix(sqla): avoid unnecessary groupby for when no metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Feb 4, 2022
1 parent 8b0634c commit 36eceb0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion superset/charts/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
2 changes: 1 addition & 1 deletion superset/common/query_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/integration_tests/charts/data/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def test_as_samples_without_row_limit__row_count_as_default_samples_row_limit(se

# 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(
Expand Down Expand Up @@ -184,6 +185,7 @@ def test_as_samples_with_row_limit_bigger_then_sql_max_row__rowcount_as_sql_max_

# 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(
Expand All @@ -200,6 +202,7 @@ def test_with_row_limit_as_samples__rowcount_as_row_limit(self):

# 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"
Expand Down

0 comments on commit 36eceb0

Please sign in to comment.