Skip to content

Commit

Permalink
Handle multiple same events in the funnel (#4863)
Browse files Browse the repository at this point in the history
* dedup + tests

* deep equality. Tests to come

* write test for entity equality

* finish testing funnels

* clean up comments
  • Loading branch information
neilkakkar authored Jun 25, 2021
1 parent 49f8c92 commit 716e8af
Show file tree
Hide file tree
Showing 5 changed files with 675 additions and 5 deletions.
7 changes: 5 additions & 2 deletions ee/clickhouse/queries/funnels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ def get_partition_cols(self, level_index: int, max_steps: int):
if i < level_index:
cols.append(f"latest_{i}")
else:
duplicate_event = 0
if i > 0 and self._filter.entities[i].equals(self._filter.entities[i - 1]):
duplicate_event = 1
cols.append(
f"min(latest_{i}) over (PARTITION by person_id ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) latest_{i}"
f"min(latest_{i}) over (PARTITION by person_id ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND {duplicate_event} PRECEDING) latest_{i}"
)
return ", ".join(cols)

Expand Down Expand Up @@ -169,7 +172,7 @@ def _get_sorting_condition(self, curr_index: int, max_steps: int):

conditions: List[str] = []
for i in range(1, curr_index):
conditions.append(f"latest_{i - 1} <= latest_{i }")
conditions.append(f"latest_{i - 1} < latest_{i }")
conditions.append(f"latest_{i} <= latest_0 + INTERVAL {self._filter.funnel_window_days} DAY")

return f"if({' AND '.join(conditions)}, {curr_index}, {self._get_sorting_condition(curr_index - 1, max_steps)})"
Expand Down
Empty file.
Loading

0 comments on commit 716e8af

Please sign in to comment.