Skip to content

Commit

Permalink
Use get_query_runner
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Oct 19, 2023
1 parent d426451 commit c82e9d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 6 additions & 8 deletions posthog/hogql_queries/apply_dashboard_filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from posthog.hogql_queries.query_runner import get_query_runner
from posthog.models import Team
from posthog.schema import DashboardFilter

Expand All @@ -10,12 +11,9 @@ def apply_dashboard_filters(query: dict, filters: dict, team: Team) -> dict:
source = apply_dashboard_filters(query["source"], filters, team)
return {**query, "source": source}

dashboard_filter = DashboardFilter(**filters)

if kind == "HogQLQuery":
from posthog.hogql_queries.hogql_query_runner import HogQLQueryRunner

query_runner = HogQLQueryRunner(query, team)
return query_runner.apply_dashboard_filters(dashboard_filter).dict()
else:
query_runner = get_query_runner(query, team)
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
4 changes: 4 additions & 0 deletions posthog/hogql_queries/query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
EventsQuery,
WebStatsTableQuery,
HogQLQuery,
DashboardFilter,
)
from posthog.utils import generate_cache_key, get_safe_cache

Expand Down Expand Up @@ -240,3 +241,6 @@ def _is_stale(self, cached_result_package):
@abstractmethod
def _refresh_frequency(self):
raise NotImplementedError()

def apply_dashboard_filters(self, dashboard_filter: DashboardFilter) -> RunnableQueryNode:
raise NotImplementedError()

0 comments on commit c82e9d1

Please sign in to comment.