Skip to content

Commit

Permalink
revert: "feat(hogql): run filter based insights via hogql (#17611)" (#…
Browse files Browse the repository at this point in the history
…17641)

Revert "feat(hogql): run filter based insights via hogql (#17611)"

This reverts commit cb22ba7.
  • Loading branch information
thmsobrmlr authored Sep 27, 2023
1 parent 38cc449 commit ef3bcb9
Show file tree
Hide file tree
Showing 12 changed files with 5 additions and 153 deletions.
1 change: 0 additions & 1 deletion frontend/src/queries/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export function isLifecycleQuery(node?: Node | null): node is LifecycleQuery {
return node?.kind === NodeKind.LifecycleQuery
}

// sync with posthog/hogql_queries/legacy_compatibility/process_insight.py
export function isQueryWithHogQLSupport(node?: Node | null): node is LifecycleQuery {
return isLifecycleQuery(node) || isTrendsQuery(node)
}
Expand Down
7 changes: 0 additions & 7 deletions posthog/api/insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
from posthog.decorators import cached_by_filters
from posthog.helpers.multi_property_breakdown import protect_old_clients_from_multi_property_default
from posthog.hogql.errors import HogQLException
from posthog.hogql_queries.legacy_compatibility.feature_flag import hogql_insights_enabled
from posthog.hogql_queries.legacy_compatibility.process_insight import is_insight_with_hogql_support, process_insight
from posthog.kafka_client.topics import KAFKA_METRICS_TIME_TO_SEE_DATA
from posthog.models import DashboardTile, Filter, Insight, User
from posthog.models.activity_logging.activity_log import (
Expand Down Expand Up @@ -505,11 +503,6 @@ def insight_result(self, insight: Insight) -> InsightResult:
dashboard_tile = self.dashboard_tile_from_context(insight, dashboard)
target = insight if dashboard is None else dashboard_tile

if hogql_insights_enabled(self.context.get("request", None).user) and is_insight_with_hogql_support(
target or insight
):
return process_insight(target or insight, insight.team)

is_shared = self.context.get("is_shared", False)
refresh_insight_now, refresh_frequency = should_refresh_insight(
insight, dashboard_tile, request=self.context["request"], is_shared=is_shared
Expand Down
13 changes: 2 additions & 11 deletions posthog/api/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,11 @@ def _unwrap_pydantic_dict(response: Any) -> Dict:


def process_query(
team: Team,
query_json: Dict,
default_limit: Optional[int] = None,
request: Optional[Request] = None,
team: Team, query_json: Dict, default_limit: Optional[int] = None, request: Optional[Request] = None
) -> Dict:
# query_json has been parsed by QuerySchemaParser
# it _should_ be impossible to end up in here with a "bad" query
if isinstance(query_json, dict):
query_kind = query_json.get("kind")
else:
# we can have a pydantic model for a query as well
# this isn't typed accordingly, as type narrowing
# below would get complicated
query_kind = query_json.kind # type: ignore
query_kind = query_json.get("kind")

tag_queries(query=query_json)

Expand Down
24 changes: 0 additions & 24 deletions posthog/api/test/test_insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -2680,27 +2680,3 @@ def test_insight_retention_hogql(self) -> None:
).json()
self.assertEqual(len(response["result"]), 11)
self.assertEqual(response["result"][0]["values"][0]["count"], 1)

@override_settings(HOGQL_INSIGHTS_OVERRIDE=True)
def test_insight_with_filters_via_hogql(self) -> None:
filter_dict = {"insight": "LIFECYCLE", "events": [{"id": "$pageview"}]}

Insight.objects.create(
filters=Filter(data=filter_dict).to_dict(),
team=self.team,
short_id="xyz123",
)

# fresh response
response = self.client.get(f"/api/projects/{self.team.id}/insights/?short_id=xyz123")
self.assertEqual(response.status_code, status.HTTP_200_OK)

self.assertEqual(len(response.json()["results"]), 1)
self.assertEqual(response.json()["results"][0]["result"][0]["data"], [0, 0, 0, 0, 0, 0, 0, 0])

# cached response
response = self.client.get(f"/api/projects/{self.team.id}/insights/?short_id=xyz123")
self.assertEqual(response.status_code, status.HTTP_200_OK)

self.assertEqual(len(response.json()["results"]), 1)
self.assertEqual(response.json()["results"][0]["result"][0]["data"], [0, 0, 0, 0, 0, 0, 0, 0])
4 changes: 1 addition & 3 deletions posthog/caching/fetch_from_cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from datetime import datetime, timedelta
from typing import Any, List, Optional, Union
from typing import Any, Optional, Union

from django.utils.timezone import now
from prometheus_client import Counter
Expand All @@ -9,7 +9,6 @@
from posthog.caching.insight_cache import update_cached_state
from posthog.models import DashboardTile, Insight
from posthog.models.dashboard import Dashboard
from posthog.schema import QueryTiming
from posthog.utils import get_safe_cache

insight_cache_read_counter = Counter(
Expand All @@ -25,7 +24,6 @@ class InsightResult:
is_cached: bool
timezone: Optional[str]
next_allowed_client_refresh: Optional[datetime] = None
timings: Optional[List[QueryTiming]] = None


@dataclass(frozen=True)
Expand Down
21 changes: 0 additions & 21 deletions posthog/hogql_queries/legacy_compatibility/feature_flag.py

This file was deleted.

8 changes: 2 additions & 6 deletions posthog/hogql_queries/legacy_compatibility/filter_to_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@


def entity_to_node(entity: BackendEntity) -> EventsNode | ActionsNode:
properties = entity._data.get("properties", None)
if isinstance(properties, dict) and len(properties) == 0:
properties = None

shared = {
"name": entity.name,
"custom_name": entity.custom_name,
"properties": properties,
"properties": entity._data.get("properties", None),
"math": entity.math,
"math_property": entity.math_property,
"math_hogql": entity.math_hogql,
Expand Down Expand Up @@ -81,7 +77,7 @@ def _interval(filter: AnyInsightFilter):
def _series(filter: AnyInsightFilter):
if filter.insight == "RETENTION" or filter.insight == "PATHS":
return {}
return {"series": list(map(entity_to_node, filter.entities))}
return {"series": map(entity_to_node, filter.entities)}


def _sampling_factor(filter: AnyInsightFilter):
Expand Down
42 changes: 0 additions & 42 deletions posthog/hogql_queries/legacy_compatibility/process_insight.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -299,30 +299,6 @@
"funnel_viz_type": "steps",
"filter_test_accounts": True,
}
insight_18 = {
"events": [
{
"id": "$pageview",
"math": None,
"name": "$pageview",
"type": "events",
"order": None,
"math_hogql": None,
"properties": {},
"custom_name": None,
"math_property": None,
"math_group_type_index": None,
}
],
"display": "ActionsLineGraph",
"insight": "LIFECYCLE",
"interval": "day",
"date_from": "-7d",
"sampling_factor": "",
"smoothing_intervals": 1,
"breakdown_normalize_url": False,
"breakdown_attribution_type": "first_touch",
}

test_insights = [
insight_0,
Expand All @@ -343,7 +319,6 @@
insight_15,
insight_16,
insight_17,
insight_18,
]


Expand Down
4 changes: 0 additions & 4 deletions posthog/hogql_queries/query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class CachedQueryResponse(QueryResponse):
is_cached: bool
last_refresh: str
next_allowed_client_refresh: str
cache_key: str
timezone: str


class QueryRunner(ABC):
Expand Down Expand Up @@ -92,8 +90,6 @@ def run(self, refresh_requested: bool) -> CachedQueryResponse:
fresh_response_dict["next_allowed_client_refresh"] = (datetime.now() + self._refresh_frequency()).strftime(
"%Y-%m-%dT%H:%M:%SZ"
)
fresh_response_dict["cache_key"] = cache_key
fresh_response_dict["timezone"] = self.team.timezone
fresh_response = CachedQueryResponse(**fresh_response_dict)
cache.set(cache_key, fresh_response, settings.CACHED_RESULTS_TTL)
QUERY_CACHE_WRITE_COUNTER.labels(team_id=self.team.pk).inc()
Expand Down
3 changes: 0 additions & 3 deletions posthog/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@
# Only written in specific scripts - do not use outside of them.
PERSON_ON_EVENTS_V2_OVERRIDE = get_from_env("PERSON_ON_EVENTS_V2_OVERRIDE", optional=True, type_cast=str_to_bool)

# Wether to use insight queries converted to HogQL.
HOGQL_INSIGHTS_OVERRIDE = get_from_env("HOGQL_INSIGHTS_OVERRIDE", optional=True, type_cast=str_to_bool)

HOOK_EVENTS: Dict[str, str] = {}

# Support creating multiple organizations in a single instance. Requires a premium license.
Expand Down
6 changes: 0 additions & 6 deletions posthog/settings/dynamic_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
"Whether to use query path using person_id and person_properties on events or the old query",
bool,
),
"HOGQL_INSIGHTS_OVERRIDE": (
get_from_env("HOGQL_INSIGHTS_OVERRIDE", False, type_cast=str_to_bool),
"Whether to use insight queries converted to use hogql internally or the old queries",
bool,
),
"GROUPS_ON_EVENTS_ENABLED": (
get_from_env("GROUPS_ON_EVENTS_ENABLED", False, type_cast=str_to_bool),
"Whether to use query path using group_properties on events or the old query",
Expand Down Expand Up @@ -212,7 +207,6 @@
"ASYNC_MIGRATIONS_OPT_OUT_EMAILS",
"PERSON_ON_EVENTS_ENABLED",
"PERSON_ON_EVENTS_V2_ENABLED",
"HOGQL_INSIGHTS_OVERRIDE",
"GROUPS_ON_EVENTS_ENABLED",
"STRICT_CACHING_TEAMS",
"SLACK_APP_CLIENT_ID",
Expand Down

0 comments on commit ef3bcb9

Please sign in to comment.