-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(persons): no duplicate distinct_ids (#20152)
- Loading branch information
1 parent
8a4c7d8
commit 337b7e7
Showing
4 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,13 +74,14 @@ def run_query(self, query): | |
runner = RetentionQueryRunner(team=self.team, query=query) | ||
return runner.calculate().model_dump()["results"] | ||
|
||
def run_actors_query(self, interval, query, select=None): | ||
def run_actors_query(self, interval, query, select=None, search=None): | ||
query["kind"] = "RetentionQuery" | ||
if not query.get("retentionFilter"): | ||
query["retentionFilter"] = {} | ||
runner = ActorsQueryRunner( | ||
team=self.team, | ||
query={ | ||
"search": search, | ||
"select": ["person", "appearances", *(select or [])], | ||
"orderBy": ["length(appearances) DESC", "actor_id"], | ||
"source": { | ||
|
@@ -874,6 +875,44 @@ def test_retention_people_in_period(self): | |
self.assertEqual(result[1][0]["id"], person1.uuid) | ||
self.assertCountEqual(result[1][1], [0, 3, 4]) | ||
|
||
def test_retention_people_search(self): | ||
_create_person( | ||
team_id=self.team.pk, | ||
distinct_ids=["person1", "alias1"], | ||
properties={"email": "[email protected]"}, | ||
) | ||
_create_person( | ||
team_id=self.team.pk, | ||
distinct_ids=["person2"], | ||
properties={"email": "[email protected]"}, | ||
) | ||
|
||
_create_events( | ||
self.team, | ||
[ | ||
("person1", _date(0)), | ||
("person1", _date(1)), | ||
("person1", _date(2)), | ||
("person1", _date(5)), | ||
("alias1", _date(5, 9)), | ||
("person1", _date(6)), | ||
("person2", _date(1)), | ||
("person2", _date(2)), | ||
("person2", _date(3)), | ||
("person2", _date(6)), | ||
("person2", _date(7)), | ||
], | ||
) | ||
|
||
result = self.run_actors_query( | ||
interval=2, | ||
query={ | ||
"dateRange": {"date_to": _date(10, hour=6)}, | ||
}, | ||
search="test", | ||
) | ||
self.assertEqual(len(result), 2) | ||
|
||
def test_retention_people_in_period_first_time(self): | ||
p1, p2, p3, p4 = self._create_first_time_retention_events() | ||
# even if set to hour 6 it should default to beginning of day and include all pageviews above | ||
|
13 changes: 13 additions & 0 deletions
13
posthog/hogql_queries/test/__snapshots__/test_actors_query_runner.ambr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# serializer version: 1 | ||
# name: TestActorsQueryRunner.test_persons_query_search_snapshot | ||
''' | ||
|
||
SELECT id, id, created_at, 1 | ||
FROM persons | ||
WHERE or(ilike(properties.email, '%SEARCHSTRING%'), ilike(properties.name, '%SEARCHSTRING%'), ilike(toString(id), '%SEARCHSTRING%'), in(id, ( | ||
SELECT person_id | ||
FROM person_distinct_ids | ||
WHERE ilike(distinct_id, '%SEARCHSTRING%')))) ORDER BY created_at DESC | ||
LIMIT 10000 | ||
''' | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters