Skip to content

Commit

Permalink
Improve query runner type names
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Sep 29, 2023
1 parent dbf41d8 commit 9fa716a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
36 changes: 29 additions & 7 deletions posthog/hogql_queries/query_runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod
from datetime import datetime
from typing import Any, Generic, List, Optional, Type, Dict, TypeVar
from typing import Any, Generic, List, Optional, Type, Dict, TypeVar, Union

from django.conf import settings
from django.core.cache import cache
Expand All @@ -14,9 +14,18 @@
from posthog.hogql.timings import HogQLTimings
from posthog.metrics import LABEL_TEAM_ID
from posthog.models import Team
from posthog.schema import QueryTiming

from posthog.types import Node
from posthog.schema import (
QueryTiming,
TrendsQuery,
FunnelsQuery,
RetentionQuery,
PathsQuery,
StickinessQuery,
LifecycleQuery,
WebTopSourcesQuery,
WebTopClicksQuery,
WebTopPagesQuery,
)
from posthog.utils import generate_cache_key, get_safe_cache

QUERY_CACHE_WRITE_COUNTER = Counter(
Expand Down Expand Up @@ -53,13 +62,26 @@ class CachedQueryResponse(QueryResponse):
next_allowed_client_refresh: str


RunnableQueryNode = Union[
TrendsQuery,
FunnelsQuery,
RetentionQuery,
PathsQuery,
StickinessQuery,
LifecycleQuery,
WebTopSourcesQuery,
WebTopClicksQuery,
WebTopPagesQuery,
]


class QueryRunner(ABC):
query: Node
query_type: Type[Node]
query: RunnableQueryNode
query_type: Type[RunnableQueryNode]
team: Team
timings: HogQLTimings

def __init__(self, query: Node | Dict[str, Any], team: Team, timings: Optional[HogQLTimings] = None):
def __init__(self, query: RunnableQueryNode | Dict[str, Any], team: Team, timings: Optional[HogQLTimings] = None):
self.team = team
self.timings = timings or HogQLTimings()
if isinstance(query, self.query_type):
Expand Down
23 changes: 0 additions & 23 deletions posthog/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,5 @@
from posthog.models.filters.path_filter import PathFilter
from posthog.models.filters.retention_filter import RetentionFilter
from posthog.models.filters.stickiness_filter import StickinessFilter
from posthog.schema import (
FunnelsQuery,
LifecycleQuery,
PathsQuery,
RetentionQuery,
StickinessQuery,
TrendsQuery,
WebTopSourcesQuery,
WebTopClicksQuery,
WebTopPagesQuery,
)

FilterType = Union[Filter, PathFilter, RetentionFilter, StickinessFilter]

Node = Union[
TrendsQuery,
FunnelsQuery,
RetentionQuery,
PathsQuery,
StickinessQuery,
LifecycleQuery,
WebTopSourcesQuery,
WebTopClicksQuery,
WebTopPagesQuery,
]

0 comments on commit 9fa716a

Please sign in to comment.