Skip to content

Commit

Permalink
feat(hogql): add breakdowns for strict order funnel (#20277)
Browse files Browse the repository at this point in the history
* feat(hogql): add breakdowns for strict order funnel

* Update query snapshots

* cleanup

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
thmsobrmlr and github-actions[bot] authored Feb 13, 2024
1 parent a161d2d commit 7ea9a95
Show file tree
Hide file tree
Showing 7 changed files with 1,430 additions and 166 deletions.
8 changes: 4 additions & 4 deletions posthog/api/test/dashboards/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,13 +863,13 @@ def test_dashboard_duplication_can_duplicate_tiles(self):

def test_dashboard_duplication_can_duplicate_tiles_without_editing_name_if_there_is_none(self) -> None:
existing_dashboard = Dashboard.objects.create(team=self.team, name="existing dashboard", created_by=self.user)
insight_one_id, _ = self.dashboard_api.create_insight({"dashboards": [existing_dashboard.pk], "name": None})
_, dashboard_with_tiles = self.dashboard_api.create_text_tile(existing_dashboard.id)
self.dashboard_api.create_insight({"dashboards": [existing_dashboard.pk], "name": None})
self.dashboard_api.create_text_tile(existing_dashboard.pk)

_, duplicate_response = self.dashboard_api.create_dashboard(
{
"name": "another",
"use_dashboard": existing_dashboard.id,
"use_dashboard": existing_dashboard.pk,
"duplicate_tiles": True,
}
)
Expand Down Expand Up @@ -897,7 +897,7 @@ def test_dashboard_duplication(self):
DashboardTile.objects.create(dashboard=existing_dashboard, insight=insight1)
insight2 = Insight.objects.create(filters={"name": "test2"}, team=self.team, last_refresh=now())
DashboardTile.objects.create(dashboard=existing_dashboard, insight=insight2)
_, response = self.dashboard_api.create_dashboard({"name": "another", "use_dashboard": existing_dashboard.id})
_, response = self.dashboard_api.create_dashboard({"name": "another", "use_dashboard": existing_dashboard.pk})
self.assertEqual(response["creation_mode"], "duplicate")

self.assertEqual(len(response["tiles"]), len(existing_dashboard.insights.all()))
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/insights/funnels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def _get_inner_event_query(
# for prop in self._include_properties:
# extra_fields.append(prop)

funnel_events_query = FunnelEventQuery(context=self.context).to_query()
funnel_events_query = FunnelEventQuery(context=self.context).to_query(skip_entity_filter=skip_entity_filter)
# funnel_events_query, params = FunnelEventQuery(
# extra_fields=[*self._extra_event_fields, *extra_fields],
# extra_event_properties=self._extra_event_properties,
Expand Down
16 changes: 8 additions & 8 deletions posthog/hogql_queries/insights/funnels/funnel_strict.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@ class FunnelStrict(FunnelBase):
def get_query(self):
max_steps = self.context.max_steps

# breakdown_exprs = self._get_breakdown_prop_expr()
breakdown_exprs = self._get_breakdown_prop_expr()

select: List[ast.Expr] = [
*self._get_count_columns(max_steps),
*self._get_step_time_avgs(max_steps),
*self._get_step_time_median(max_steps),
# *breakdown_exprs,
*breakdown_exprs,
]

return ast.SelectQuery(
select=select,
select_from=ast.JoinExpr(table=self.get_step_counts_query()),
# group_by=[ast.Field(chain=["prop"])] if len(breakdown_exprs) > 0 else None,
group_by=[ast.Field(chain=["prop"])] if len(breakdown_exprs) > 0 else None,
)

def get_step_counts_query(self):
max_steps = self.context.max_steps
# breakdown_exprs = self._get_breakdown_prop_expr()
breakdown_exprs = self._get_breakdown_prop_expr()
inner_timestamps, outer_timestamps = self._get_timestamp_selects()
person_and_group_properties = self._get_person_and_group_properties()

group_by_columns: List[ast.Expr] = [
ast.Field(chain=["aggregation_target"]),
ast.Field(chain=["steps"]),
# *breakdown_exprs,
*breakdown_exprs,
]

outer_select: List[ast.Expr] = [
*group_by_columns,
*self._get_step_time_avgs(max_steps, inner_query=True),
*self._get_step_time_median(max_steps, inner_query=True),
*self._get_matching_event_arrays(max_steps),
# *breakdown_exprs,
*breakdown_exprs,
*outer_timestamps,
*person_and_group_properties,
]
Expand All @@ -55,7 +55,7 @@ def get_step_counts_query(self):
max_steps_expr,
*self._get_step_time_names(max_steps),
*self._get_matching_events(max_steps),
# *breakdown_exprs,
*breakdown_exprs,
*inner_timestamps,
*person_and_group_properties,
]
Expand All @@ -81,7 +81,7 @@ def get_step_counts_without_aggregation_query(self):
ast.Field(chain=["aggregation_target"]),
ast.Field(chain=["timestamp"]),
*self._get_partition_cols(1, max_steps),
# *self._get_breakdown_prop_expr(group_remaining=True),
*self._get_breakdown_prop_expr(group_remaining=True),
*self._get_person_and_group_properties(),
]
select_from_inner = self._get_inner_event_query(skip_entity_filter=True, skip_step_filter=True)
Expand Down
Loading

0 comments on commit 7ea9a95

Please sign in to comment.