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: saved queries with execution info #11391

Merged
merged 5 commits into from
Oct 26, 2020

Conversation

dpgaspar
Copy link
Member

@dpgaspar dpgaspar commented Oct 22, 2020

SUMMARY

Propagates the number of retrieved rows and timestamps to a "related" saved query when a SQLLab query executes.
This is a nice to have UI/UX information for a future home screen on Superset

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

@codecov-io
Copy link

codecov-io commented Oct 22, 2020

Codecov Report

Merging #11391 into master will decrease coverage by 4.12%.
The diff coverage is 67.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11391      +/-   ##
==========================================
- Coverage   65.75%   61.62%   -4.13%     
==========================================
  Files         838      839       +1     
  Lines       39714    39940     +226     
  Branches     3613     3662      +49     
==========================================
- Hits        26115    24615    -1500     
- Misses      13498    15144    +1646     
- Partials      101      181      +80     
Flag Coverage Δ
#cypress ?
#javascript 62.67% <ø> (+0.06%) ⬆️
#python 61.00% <67.50%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ons/585b0b1a7b18_add_exec_info_to_saved_queries.py 0.00% <0.00%> (ø)
superset/queries/saved_queries/api.py 96.29% <ø> (ø)
superset/views/core.py 74.57% <75.00%> (+0.10%) ⬆️
superset/models/sql_lab.py 90.84% <92.30%> (+0.14%) ⬆️
superset/queries/dao.py 100.00% <100.00%> (+100.00%) ⬆️
superset-frontend/src/SqlLab/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/explore/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/dashboard/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/explore/index.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/dashboard/index.jsx 0.00% <0.00%> (-100.00%) ⬇️
... and 197 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 7369039...6c176c3. Read the comment docs.

@dpgaspar dpgaspar marked this pull request as ready for review October 22, 2020 15:11
@mistercrunch
Copy link
Member

Did we consider having this as a foreign key to the query table? There are probably pros/cons here.

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM with minor naming comment.

Comment on lines +84 to +101
saved_query = SavedQuery(db_id=examples_db_id, sql=sql_statement)
db.session.add(saved_query)
db.session.commit()

with freeze_time("2020-01-01T00:00:00Z"):
self.run_sql(sql_statement, "1")
saved_query_ = (
db.session.query(SavedQuery)
.filter(
SavedQuery.db_id == examples_db_id, SavedQuery.sql == sql_statement
)
.one_or_none()
)
assert saved_query_.rows is not None
assert saved_query_.last_run == datetime.now()

# Rollback changes
db.session.delete(saved_query_)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I wonder if it were cleaner to just do db.session.add(SavedQuery(db_id=examples_db_id, sql=sql_statement)) in the beginning, and later name the the queried SavedQuery without the trailing underscore, as the original saved_query isn't really reused.

Copy link
Member Author

Choose a reason for hiding this comment

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

Would look better, yes

@dpgaspar
Copy link
Member Author

Did we consider having this as a foreign key to the query table? There are probably pros/cons here.

@mistercrunch

I have considered using a custom SQLAlchemy relation on SavedQuery, but I think is not clean since there is no relation between savedqueries and queries, this is kind of an best effort. But more importantly using a relation on savedquery to join query is expensive (since query table grows a lot and we are joining by sql text field).
I think that this write approach is light and not too "evasive"

Thoughts?

@willbarrett willbarrett merged commit 144b279 into apache:master Oct 26, 2020
@dpgaspar dpgaspar deleted the feat/saved-query-rows branch October 27, 2020 09:01
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
* feat: add rows and last_run info to saved queries

* feat: add rows to saved query

* refactor and tests

* lint

* fix tests
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.0.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants