Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqla): avoid unnecessary groupby in samples request #18579

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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