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/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push: new 42b6347 fix: fix csv and query result type and QueryObject schema (#10312) 42b6347 is described below commit 42b6347fcad0dee76efe2c76b7b2341ed33eba04 Author: Ville Brofeldt <33317356+ville...@users.noreply.github.com> AuthorDate: Tue Jul 14 16:37:19 2020 +0300 fix: fix csv and query result type and QueryObject schema (#10312) --- superset/charts/api.py | 2 +- superset/charts/schemas.py | 2 +- tests/charts/api_tests.py | 22 ++++++++++++++++++++++ tests/charts/schema_tests.py | 30 ++++++++++++++++++++++++------ 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/superset/charts/api.py b/superset/charts/api.py index af359a4..52c2a1c 100644 --- a/superset/charts/api.py +++ b/superset/charts/api.py @@ -473,7 +473,7 @@ class ChartRestApi(BaseSupersetModelRestApi): return self.response_401() payload = query_context.get_payload() for query in payload: - if query["error"]: + if query.get("error"): return self.response_400(message=f"Error: {query['error']}") result_format = query_context.result_format if result_format == ChartDataResultFormat.CSV: diff --git a/superset/charts/schemas.py b/superset/charts/schemas.py index 9e5e663..9ccd0f2 100644 --- a/superset/charts/schemas.py +++ b/superset/charts/schemas.py @@ -702,7 +702,7 @@ class ChartDataQueryObjectSchema(Schema): timeseries_limit = fields.Integer( description="Maximum row count for timeseries queries. Default: `0`", ) - timeseries_limit_metric = fields.Integer( + timeseries_limit_metric = fields.Raw( description="Metric used to limit timeseries queries by.", allow_none=True, ) row_limit = fields.Integer( diff --git a/tests/charts/api_tests.py b/tests/charts/api_tests.py index 03a9864..909b8b1 100644 --- a/tests/charts/api_tests.py +++ b/tests/charts/api_tests.py @@ -730,6 +730,28 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin): rv = self.post_assert_metric(CHART_DATA_URI, request_payload, "data") self.assertEqual(rv.status_code, 400) + def test_chart_data_query_result_type(self): + """ + Chart data API: Test chart data with query result format + """ + self.login(username="admin") + table = self.get_table_by_name("birth_names") + request_payload = get_query_context(table.name, table.id, table.type) + request_payload["result_type"] = "query" + rv = self.post_assert_metric(CHART_DATA_URI, request_payload, "data") + self.assertEqual(rv.status_code, 200) + + def test_chart_data_csv_result_format(self): + """ + Chart data API: Test chart data with CSV result format + """ + self.login(username="admin") + table = self.get_table_by_name("birth_names") + request_payload = get_query_context(table.name, table.id, table.type) + request_payload["result_format"] = "csv" + rv = self.post_assert_metric(CHART_DATA_URI, request_payload, "data") + self.assertEqual(rv.status_code, 200) + def test_chart_data_mixed_case_filter_op(self): """ Chart data API: Ensure mixed case filter operator generates valid result diff --git a/tests/charts/schema_tests.py b/tests/charts/schema_tests.py index ecb2c97..f3a5a6f 100644 --- a/tests/charts/schema_tests.py +++ b/tests/charts/schema_tests.py @@ -26,10 +26,6 @@ from tests.base_tests import SupersetTestCase from tests.fixtures.query_context import get_query_context -def load_query_context(payload: Dict[str, Any]) -> Tuple[QueryContext, Dict[str, Any]]: - return ChartDataQueryContextSchema().load(payload) - - class TestSchema(SupersetTestCase): def test_query_context_limit_and_offset(self): self.login(username="admin") @@ -40,7 +36,7 @@ class TestSchema(SupersetTestCase): # Use defaults payload["queries"][0].pop("row_limit", None) payload["queries"][0].pop("row_offset", None) - query_context = load_query_context(payload) + query_context = ChartDataQueryContextSchema().load(payload) query_object = query_context.queries[0] self.assertEqual(query_object.row_limit, app.config["ROW_LIMIT"]) self.assertEqual(query_object.row_offset, 0) @@ -66,10 +62,32 @@ class TestSchema(SupersetTestCase): table_name = "birth_names" table = self.get_table_by_name(table_name) payload = get_query_context(table.name, table.id, table.type) - payload["queries"][0]["extras"]["time_grain_sqla"] = None _ = ChartDataQueryContextSchema().load(payload) + def test_query_context_series_limit(self): + self.login(username="admin") + table_name = "birth_names" + table = self.get_table_by_name(table_name) + payload = get_query_context(table.name, table.id, table.type) + + payload["queries"][0]["timeseries_limit"] = 2 + payload["queries"][0]["timeseries_limit_metric"] = { + "expressionType": "SIMPLE", + "column": { + "id": 334, + "column_name": "gender", + "filterable": True, + "groupby": True, + "is_dttm": False, + "type": "VARCHAR(16)", + "optionName": "_col_gender", + }, + "aggregate": "COUNT_DISTINCT", + "label": "COUNT_DISTINCT(gender)", + } + _ = ChartDataQueryContextSchema().load(payload) + def test_query_context_null_post_processing_op(self): self.login(username="admin") table_name = "birth_names"