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

feat: Add additional information to datasets list API endpoint #9959

Closed

Conversation

willbarrett
Copy link
Member

@willbarrett willbarrett commented Jun 1, 2020

SUMMARY

Preset would like to add some more information to the new React-based Datasets list view. We're looking to add:

  • A list of owners in icon form
  • The number of charts built on the datasource
  • The number of fields in the datasource
  • The number of metrics in the datasource
  • Whether the datasource is physical or virtual (is there SQL)
    This PR adds the requested information to the API endpoint.

Changes are to support this UI

Screen Shot 2020-06-03 at 11 41 18 AM

TEST PLAN

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

Reviewers

@dpgaspar @nytai

@codecov-commenter
Copy link

codecov-commenter commented Jun 1, 2020

Codecov Report

Merging #9959 into master will increase coverage by 0.05%.
The diff coverage is 95.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9959      +/-   ##
==========================================
+ Coverage   71.34%   71.39%   +0.05%     
==========================================
  Files         585      585              
  Lines       30889    30968      +79     
  Branches     3237     3261      +24     
==========================================
+ Hits        22037    22110      +73     
- Misses       8743     8749       +6     
  Partials      109      109              
Flag Coverage Δ
#cypress 54.06% <ø> (+0.14%) ⬆️
#javascript 59.39% <ø> (-0.01%) ⬇️
#python 71.59% <95.00%> (+0.06%) ⬆️
Impacted Files Coverage Δ
superset/datasets/api.py 92.56% <ø> (ø)
superset/connectors/base/models.py 90.10% <94.44%> (+0.29%) ⬆️
superset/connectors/sqla/models.py 90.52% <100.00%> (+0.01%) ⬆️
.../src/dashboard/components/RefreshIntervalModal.jsx 90.00% <0.00%> (-10.00%) ⬇️
superset-frontend/src/explore/exploreUtils.js 81.65% <0.00%> (-1.39%) ⬇️
...erset-frontend/src/dashboard/components/Header.jsx 55.47% <0.00%> (-1.24%) ⬇️
.../src/dashboard/components/gridComponents/Chart.jsx 88.76% <0.00%> (-1.13%) ⬇️
...et-frontend/src/dashboard/components/SaveModal.jsx 81.81% <0.00%> (-1.11%) ⬇️
superset-frontend/src/explore/controlUtils.js 96.90% <0.00%> (-0.04%) ⬇️
superset/app.py 81.35% <0.00%> (ø)
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7618ee...b6901a1. Read the comment docs.

@dpgaspar dpgaspar changed the title feature: Add additional information to datasets list API endpoint feat: Add additional information to datasets list API endpoint Jun 2, 2020
@willbarrett willbarrett closed this Jun 2, 2020
@willbarrett willbarrett reopened this Jun 2, 2020
@willbarrett willbarrett marked this pull request as ready for review June 2, 2020 20:04
"default_endpoint",
"explore_url",
"kind",
"metrics.id",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required to join the metrics to get a count. Same story with columns.id and slices.id I'm looking into a FAB change to make this less hacky and more performant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @dpgaspar does that result in round trips for each entry in the page? It seems like a bad idea. Is number of cols/metrics necessary here? Do we have a wireframe for context?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not result in an N+1, given some recent work that Daniel has done. I'll update the ticket with a screenshot of the design.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, adding a count of related records is a common problem for webapps and there are performant solutions. I can see us wanting to display similar information in other places, so I recommend we find a performant way forward with FAB.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@willbarrett is preparing a PR on FAB to add the ability to define a custom SQLAlchemy query for the list endpoint, should be a great new feature

@@ -50,6 +50,9 @@
"series",
]

DATASOURCE_TYPE_VIRTUAL = "virtual"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried it out, and something is off with the backref joins from metric, columns and slices the results get truncated. I'll investigate it since your code seems correct

@willbarrett
Copy link
Member Author

I'm hoping to leverage this change in FAB: dpgaspar/Flask-AppBuilder#1386 to improve this PR.

@@ -51,6 +52,11 @@
]


class DatasourceKind(Enum):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most enums i've seen in python have been in SHOUT_CASE, should we be consistent here?

Also, I think if you have this extend str as well, then instead of returning DatasourceKind.virtual.value below you can return str(DatasourceKind.virtual). see https://github.com/apache/incubator-superset/blob/7f6dbf838e4e527e640a002ce20bf5da1abf4a98/superset/errors.py#L24

@@ -99,6 +105,17 @@ def slices(self) -> RelationshipProperty:
),
)

@property
def kind(self) -> str:
if self.sql:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe return DatasourceKind.virtual.value if self.sql else DatasourceKind.physical.value?

@@ -23,6 +23,7 @@
import yaml
from sqlalchemy.sql import func

import tests.test_app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be included here? I don't see any code that references it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this inclusion the test file fails when run in isolation.

@@ -377,7 +402,7 @@ def get_column(self, column_name: Optional[str]) -> Optional["BaseColumn"]:

@staticmethod
def get_fk_many_from_list(
object_list: List[Any], fkmany: List[Column], fkmany_class: Type, key_attr: str,
object_list: List[Any], fkmany: List[Column], fkmany_class: Type, key_attr: str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, why'd we lose the trailing comma here? Are you on the right version of black?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid digging into styling changes that pass CI.

@@ -35,6 +35,7 @@
DateTime,
desc,
ForeignKey,
func,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm somewhat perplexed why the imports have changed on this file as they don't seem to be used. Maybe this branch should be rebased against master.

@willbarrett
Copy link
Member Author

Closing this until the requried FAB change is incorporated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants