-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(insights): Add dashboard filters to hogql insights (#18076)
* 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
- Loading branch information
Showing
11 changed files
with
240 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from posthog.hogql_queries.query_runner import get_query_runner | ||
from posthog.models import Team | ||
from posthog.schema import DashboardFilter | ||
|
||
|
||
# Apply the filters from the django-style Dashboard object | ||
def apply_dashboard_filters(query: dict, filters: dict, team: Team) -> dict: | ||
kind = query.get("kind", None) | ||
|
||
if kind == "DataTableNode": | ||
source = apply_dashboard_filters(query["source"], filters, team) | ||
return {**query, "source": source} | ||
|
||
try: | ||
query_runner = get_query_runner(query, team) | ||
except ValueError: | ||
return query | ||
try: | ||
return query_runner.apply_dashboard_filters(DashboardFilter(**filters)).dict() | ||
except NotImplementedError: | ||
# TODO when we implement apply_dashboard_filters on more query runners, we can remove the try/catch | ||
return query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters