Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(funnels): use hogql for legacy insight funnels api #27420

Draft
wants to merge 3 commits into
base: legacy-api-use-hogql-trends
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions posthog/api/insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,12 @@
timings = HogQLTimings()
try:
with timings.measure("calculate"):
funnel = self.calculate_funnel(request)
query_method = get_query_method(request=request, team=self.team)
if query_method == "hogql":
funnel = self.calculate_funnel_hogql(request)
else:
funnel = self.calculate_funnel(request)

except ExposedHogQLError as e:
raise ValidationError(str(e))

Expand All @@ -1112,7 +1117,7 @@

return Response(funnel)

@cached_by_filters
# @cached_by_filters
def calculate_funnel(self, request: request.Request) -> dict[str, Any]:
team = self.team
filter = Filter(request=request, data={"insight": INSIGHT_FUNNELS}, team=self.team)
Expand All @@ -1134,6 +1139,20 @@
"timezone": team.timezone,
}

# @cached_by_filters
def calculate_funnel_hogql(self, request: request.Request) -> dict[str, Any]:
team = self.team
filter = Filter(request=request, team=team)
filter = filter.shallow_clone(overrides={"insight": "FUNNELS"})
query = filter_to_query(filter.to_dict())
query_runner = get_query_runner(query, team, limit_context=None)

# we use the legacy caching mechanism (@cached_by_filters decorator), no need to cache in the query runner
result = query_runner.run(execution_mode=ExecutionMode.CALCULATE_BLOCKING_ALWAYS)
# assert isinstance(result, schema.CachedFunnelsQueryResponse)

return {"result": result.results, "timezone": team.timezone}

Check failure on line 1154 in posthog/api/insight.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "CacheMissResponse" of "Any | CacheMissResponse | QueryStatusResponse" has no attribute "results"

Check failure on line 1154 in posthog/api/insight.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Item "QueryStatusResponse" of "Any | CacheMissResponse | QueryStatusResponse" has no attribute "results"

# ******************************************
# /projects/:id/insights/retention
# params:
Expand Down
1 change: 1 addition & 0 deletions posthog/api/test/test_insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -3055,6 +3055,7 @@ def test_insight_funnels_hogql_local_filters(self) -> None:

@snapshot_clickhouse_queries
@also_test_with_materialized_columns(event_properties=["int_value"], person_properties=["fish"])
@override_settings(PERSON_ON_EVENTS_OVERRIDE=False, PERSON_ON_EVENTS_V2_OVERRIDE=False)
def test_insight_funnels_hogql_breakdown(self) -> None:
with freeze_time("2012-01-15T04:01:34.000Z"):
_create_person(
Expand Down
Loading
Loading