Skip to content

Commit

Permalink
feat(api): add featured datatypes to dashboard dataset ep (apache#15188)
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro authored Jun 16, 2021
1 parent 3bf5324 commit 33eee48
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
17 changes: 11 additions & 6 deletions superset/connectors/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import json
from datetime import datetime
from enum import Enum
from typing import Any, Dict, Hashable, List, Optional, Type, Union
from typing import Any, Dict, Hashable, List, Optional, Set, Type, Union

from flask_appbuilder.security.sqla.models import User
from sqlalchemy import and_, Boolean, Column, Integer, String, Text
Expand All @@ -30,6 +30,7 @@
from superset.models.slice import Slice
from superset.typing import FilterValue, FilterValues, QueryObjectDict
from superset.utils import core as utils
from superset.utils.core import GenericDataType

METRIC_FORM_DATA_PARAMS = [
"metric",
Expand Down Expand Up @@ -306,12 +307,16 @@ def data_for_slices(self, slices: List[Slice]) -> Dict[str, Any]:
if metric["metric_name"] in metric_names
]

filtered_columns = [
column
for column in data["columns"]
if column["column_name"] in column_names
]
filtered_columns: List[Column] = []
column_types: Set[GenericDataType] = set()
for column in data["columns"]:
generic_type = column["type_generic"]
if generic_type is not None:
column_types.add(generic_type)
if column["column_name"] in column_names:
filtered_columns.append(column)

data["column_types"] = list(column_types)
del data["description"]
data.update({"metrics": filtered_metrics})
data.update({"columns": filtered_columns})
Expand Down
1 change: 1 addition & 0 deletions superset/dashboards/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class DashboardDatasetSchema(Schema):
template_params = fields.Str()
owners = fields.List(fields.Int())
columns = fields.List(fields.Dict())
column_types = fields.List(fields.Int())
metrics = fields.List(fields.Dict())
order_by_choices = fields.List(fields.List(fields.Str()))
verbose_map = fields.Dict(fields.Str(), fields.Str())
Expand Down
4 changes: 3 additions & 1 deletion tests/dashboards/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ def test_get_dashboard_datasets(self):
data = json.loads(response.data.decode("utf-8"))
dashboard = Dashboard.get("world_health")
expected_dataset_ids = set([s.datasource_id for s in dashboard.slices])
actual_dataset_ids = set([dataset["id"] for dataset in data["result"]])
result = data["result"]
actual_dataset_ids = set([dataset["id"] for dataset in result])
self.assertEqual(actual_dataset_ids, expected_dataset_ids)
self.assertEqual(result[0]["column_types"], [0, 1, 2])

@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
def test_get_dashboard_datasets_not_found(self):
Expand Down

0 comments on commit 33eee48

Please sign in to comment.