-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(insights): Add dashboard filters to hogql insights #18076
Conversation
2a88714
to
2e37b3b
Compare
03ef6f6
to
c851102
Compare
8b3e185
to
5fc6527
Compare
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.
Some comments, though nothing that seems blocking right now. Might be worth removing the query mutation though, as I'm always afraid of odd side effects with these things..
def apply_dashboard_filters(self, dashboard_filter: DashboardFilter) -> HogQLQuery: | ||
self.query.filters = self.query.filters or HogQLFilters() | ||
self.query.filters.dateRange = self.query.filters.dateRange or DateRange() | ||
|
||
if dashboard_filter.date_to or dashboard_filter.date_from: | ||
self.query.filters.dateRange.date_to = dashboard_filter.date_to | ||
self.query.filters.dateRange.date_from = dashboard_filter.date_from | ||
|
||
if dashboard_filter.properties: | ||
self.query.filters.properties = (self.query.filters.properties or []) + dashboard_filter.properties | ||
|
||
return self.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.
I wonder if we actually should mutate self.query
here. It could be an object that's passed to the runner without any expectation that it's going to change.
Perhaps it's thus "cleaner" to save the filters to self._dashboard_filter = dashboard_filter
, and merge it on the fly in to_query
?
Alternatively, we could just store this instance variable in a generic function query_runner.py
, and expose something like get_dashboard_filters
, which each query runner calls at the right time to fetch them down, if any... 🤔
529872e
to
7b6fcfe
Compare
* WIP * Kinda sorta working * Add dashboard filters to cache key * Make mypy happy * Add support for properties * Use get_query_runner * Add tests for dashboard_query * Add tests for merging of filters * Add test for hash when dashboard filters are applied * Silently accept having no valid query runner * Remove index type from DashboardFilter * Fix type of dashboard_query * Fix test typing
* WIP * Kinda sorta working * Add dashboard filters to cache key * Make mypy happy * Add support for properties * Use get_query_runner * Add tests for dashboard_query * Add tests for merging of filters * Add test for hash when dashboard filters are applied * Silently accept having no valid query runner * Remove index type from DashboardFilter * Fix type of dashboard_query * Fix test typing
Hi @robbie-c ! Sorry for referencing an old thread and apologies for being a noob. I can see that you added a fix to the issue of not being able to apply dashboard filters to HogQL insights. However, I can't figure out how to adjust my queries so that this works for me. Any chance you might be able to give me some guidance?? |
Hey @zakbenney, you can use |
Hi @thmsobrmlr . Thanks so much! That works perfectly. Apologies again for my lack of expertise! |
No worries. Glad I could help. |
Status: it works!
Problem
#18065
Changes
apply_dashboard_filters
to the hogql query runnerapply_dashboard_filters
function which can route query nodes into the correct runnerto_representation
inInsightSerializer
, and intogenerate_insight_cache_key
How did you test this code?