From c82e9d160d2cfa4f45cd58601b2b7d2b8f575ecc Mon Sep 17 00:00:00 2001 From: Robbie Coomber Date: Thu, 19 Oct 2023 11:16:54 +0100 Subject: [PATCH] Use get_query_runner --- posthog/hogql_queries/apply_dashboard_filters.py | 14 ++++++-------- posthog/hogql_queries/query_runner.py | 4 ++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/posthog/hogql_queries/apply_dashboard_filters.py b/posthog/hogql_queries/apply_dashboard_filters.py index c710cc06e2b397..580735b6137c1e 100644 --- a/posthog/hogql_queries/apply_dashboard_filters.py +++ b/posthog/hogql_queries/apply_dashboard_filters.py @@ -1,3 +1,4 @@ +from posthog.hogql_queries.query_runner import get_query_runner from posthog.models import Team from posthog.schema import DashboardFilter @@ -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 diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.py index d39ed7ed91454c..afaa7534c655b3 100644 --- a/posthog/hogql_queries/query_runner.py +++ b/posthog/hogql_queries/query_runner.py @@ -25,6 +25,7 @@ EventsQuery, WebStatsTableQuery, HogQLQuery, + DashboardFilter, ) from posthog.utils import generate_cache_key, get_safe_cache @@ -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()