-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Did we consider having this as a foreign key to the query table? There are probably pros/cons here. |
There was a problem hiding this 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.
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_) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would look better, yes
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 Thoughts? |
* feat: add rows and last_run info to saved queries * feat: add rows to saved query * refactor and tests * lint * fix tests
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