Skip to content

Commit ec3a8bb

Browse files
committed
upgrade start point functionality
1 parent d07b7e7 commit ec3a8bb

File tree

3 files changed

+9
-78
lines changed

3 files changed

+9
-78
lines changed

ee/clickhouse/queries/paths/paths.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ def get_query(self) -> Tuple[str, dict]:
6262
def get_start_point_filter(self) -> Tuple[str, Dict]:
6363

6464
if not self._filter.start_point:
65-
return "", {}
65+
return "", {"start_point": None}
6666

67-
return "WHERE arrayElement(compact_path, 1) = %(start_point)s", {"start_point": self._filter.start_point}
67+
return "WHERE arrayElement(limited_path, 1) = %(start_point)s", {"start_point": self._filter.start_point}

ee/clickhouse/queries/test/test_paths.py

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -45,77 +45,3 @@ def test_denormalized_properties(self):
4545
self.assertNotIn("json", query.lower())
4646

4747
self.test_current_url_paths_and_logic()
48-
49-
def test_paths_start(self):
50-
Person.objects.create(team_id=self.team.pk, distinct_ids=["person_1"])
51-
_create_event(
52-
properties={"$current_url": "/"}, distinct_id="person_1", event="$pageview", team=self.team,
53-
)
54-
_create_event(
55-
properties={"$current_url": "/about"}, distinct_id="person_1", event="$pageview", team=self.team,
56-
)
57-
58-
Person.objects.create(team_id=self.team.pk, distinct_ids=["person_2"])
59-
_create_event(
60-
properties={"$current_url": "/"}, distinct_id="person_2", event="$pageview", team=self.team,
61-
)
62-
_create_event(
63-
properties={"$current_url": "/pricing"}, distinct_id="person_2", event="$pageview", team=self.team,
64-
)
65-
_create_event(
66-
properties={"$current_url": "/about"}, distinct_id="person_2", event="$pageview", team=self.team,
67-
)
68-
69-
Person.objects.create(team_id=self.team.pk, distinct_ids=["person_3"])
70-
_create_event(
71-
properties={"$current_url": "/pricing"}, distinct_id="person_3", event="$pageview", team=self.team,
72-
)
73-
_create_event(
74-
properties={"$current_url": "/"}, distinct_id="person_3", event="$pageview", team=self.team,
75-
)
76-
_create_event(
77-
properties={"$current_url": "/about"}, distinct_id="person_3", event="$pageview", team=self.team,
78-
)
79-
80-
Person.objects.create(team_id=self.team.pk, distinct_ids=["person_4"])
81-
_create_event(
82-
properties={"$current_url": "/"}, distinct_id="person_4", event="$pageview", team=self.team,
83-
)
84-
_create_event(
85-
properties={"$current_url": "/pricing"}, distinct_id="person_4", event="$pageview", team=self.team,
86-
)
87-
88-
Person.objects.create(team_id=self.team.pk, distinct_ids=["person_5a", "person_5b"])
89-
_create_event(
90-
properties={"$current_url": "/pricing"}, distinct_id="person_5a", event="$pageview", team=self.team,
91-
)
92-
_create_event(
93-
properties={"$current_url": "/about"}, distinct_id="person_5b", event="$pageview", team=self.team,
94-
)
95-
_create_event(
96-
properties={"$current_url": "/pricing"}, distinct_id="person_5a", event="$pageview", team=self.team,
97-
)
98-
_create_event(
99-
properties={"$current_url": "/help"}, distinct_id="person_5b", event="$pageview", team=self.team,
100-
)
101-
102-
response = self.client.get("/api/insight/path/?type=%24pageview&start=%2Fpricing").json()
103-
104-
filter = PathFilter(data={"path_type": "$pageview", "start_point": "/pricing"})
105-
response = ClickhousePathsNew(team=self.team, filter=filter).run(team=self.team, filter=filter,)
106-
107-
self.assertEqual(len(response), 5)
108-
109-
self.assertTrue(response[0].items() == {"source": "1_/pricing", "target": "2_/", "value": 1}.items())
110-
self.assertTrue(response[1].items() == {"source": "1_/pricing", "target": "2_/about", "value": 1}.items())
111-
self.assertTrue(response[2].items() == {"source": "2_/", "target": "3_/about", "value": 1}.items())
112-
self.assertTrue(response[3].items() == {"source": "2_/about", "target": "3_/pricing", "value": 1}.items())
113-
self.assertTrue(response[4].items() == {"source": "3_/pricing", "target": "4_/help", "value": 1}.items())
114-
115-
filter = PathFilter(data={"path_type": "$pageview", "start_point": "/"})
116-
response = ClickhousePathsNew(team=self.team, filter=filter).run(team=self.team, filter=filter,)
117-
118-
self.assertEqual(len(response), 3)
119-
self.assertTrue(response[0].items() == {"source": "1_/", "target": "2_/pricing", "value": 2}.items())
120-
self.assertTrue(response[1].items() == {"source": "1_/", "target": "2_/about", "value": 1}.items())
121-
self.assertTrue(response[2].items() == {"source": "2_/pricing", "target": "3_/about", "value": 1}.items())

ee/clickhouse/sql/paths/path.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,12 @@
162162
, arrayPopFront(arrayPushBack(path_basic, '')) as path_basic_0
163163
, arrayMap((x,y) -> if(x=y, 0, 1), path_basic, path_basic_0) as mapping
164164
, arrayFilter((x,y) -> y, time, mapping) as timings
165-
, arraySlice(arrayFilter((x,y)->y, path_basic, mapping), 1, %(event_in_session_limit)s) as compact_path
165+
, arrayFilter((x,y)->y, path_basic, mapping) as compact_path
166+
, indexOf(compact_path, %(start_point)s) as start_index
167+
, if(start_index > 0, arraySlice(compact_path, start_index), compact_path) as filtered_path
168+
, if(start_index > 0, arraySlice(timings, start_index), timings) as filtered_timings
169+
, arraySlice(filtered_path, 1, %(event_in_session_limit)s) as limited_path
170+
, arraySlice(filtered_timings, 1, %(event_in_session_limit)s) as limited_timings
166171
FROM (
167172
SELECT person_id
168173
, path_time_tuple.1 as path_basic
@@ -182,7 +187,7 @@
182187
/* this array join splits paths for a single personID per session */
183188
ARRAY JOIN session_paths AS path_time_tuple, arrayEnumerate(session_paths) AS session_index
184189
)
185-
ARRAY JOIN compact_path AS joined_path_item, arrayEnumerate(compact_path) AS event_in_session_index
190+
ARRAY JOIN limited_path AS joined_path_item, arrayEnumerate(limited_path) AS event_in_session_index
186191
{boundary_event_filter}
187192
ORDER BY person_id, session_index
188193
)

0 commit comments

Comments
 (0)