Skip to content

Commit

Permalink
add hogql funnel calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Jan 9, 2025
1 parent b37a29a commit ac5e370
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion posthog/api/insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,12 @@ def funnel(self, request: request.Request, *args: Any, **kwargs: Any) -> Respons
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 Down Expand Up @@ -1134,6 +1139,19 @@ def calculate_funnel(self, request: request.Request) -> dict[str, Any]:
"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)
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 1153 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 1153 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

0 comments on commit ac5e370

Please sign in to comment.