New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add group support to the lifecycle insight #21876
Conversation
📸 UI snapshots have been updated4 snapshot changes in total. 0 added, 4 modified, 0 deleted:
Triggered by this commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is off to a very solid start 👍. I left some comments inline and answered the questions.
event_filters = [self.event_filter] | ||
|
||
if self.group_type_index is not None: | ||
group_index = int(self.group_type_index) | ||
if 0 <= group_index <= 4: | ||
target_field = f"$group_{group_index}" | ||
|
||
event_filters.append( | ||
ast.Not( | ||
expr=ast.Call( | ||
name="has", | ||
args=[ | ||
ast.Array(exprs=[ast.Constant(value="")]), | ||
ast.Field(chain=["events", f"$group_{self.group_type_index}"]), | ||
], | ||
), | ||
), | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should go directly into the self.event_filter()
property. Something else could also access this property on the query runner to get the same event set, and would then get inconsistent results.
@@ -95,6 +95,7 @@ def to_query(self) -> ast.SelectQuery | ast.SelectUnionQuery: | |||
def to_actors_query( | |||
self, day: Optional[str] = None, status: Optional[str] = None | |||
) -> ast.SelectQuery | ast.SelectUnionQuery: | |||
# should I update this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could see this being a followup PR, however yes, somebody one day should. This is the query that opens when you click on one of the bars on the chart. I don't think it's that many extra steps to get this working.
) | ||
) | ||
for timestamp, groups in timestamps_and_groups: | ||
# not sure this is right, this maybe should put groups in directly? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly. Many other tests do this:
posthog/ee/clickhouse/views/test/funnel/test_clickhouse_funnel.py
Lines 27 to 41 in 5513be7
GroupTypeMapping.objects.create(team=self.team, group_type="organization", group_type_index=0) | |
GroupTypeMapping.objects.create(team=self.team, group_type="company", group_type_index=1) | |
create_group( | |
team_id=self.team.pk, | |
group_type_index=0, | |
group_key="org:5", | |
properties={"industry": "finance"}, | |
) | |
create_group( | |
team_id=self.team.pk, | |
group_type_index=0, | |
group_key="org:6", | |
properties={"industry": "technology"}, | |
) |
@@ -36,6 +36,544 @@ def create_action(**kwargs): | |||
return action | |||
|
|||
|
|||
class TestLifecycleQueryRetentionGroupAggregation(ClickhouseTestMixin, APIBaseTest): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: We've usually been pretty lazy and adding all tests inside one large class. This can make it easier to "run all" in PyCharm, but we use that almost never, and I'm not against splitting it up. However might be good to move the new stuff to the end of the file.
Annoyingly I couldn't run it locally yet. I'm still having some trouble with the billing service... 🙈 |
📸 UI snapshots have been updated2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
Triggered by this commit. |
📸 UI snapshots have been updated2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
Triggered by this commit. |
… into aspicer/lifecycle_groups
📸 UI snapshots have been updated1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
Triggered by this commit. |
Size Change: 0 B Total Size: 1.05 MB ℹ️ View Unchanged
|
📸 UI snapshots have been updated1 snapshot changes in total. 0 added, 1 modified, 0 deleted:
Triggered by this commit. |
Problem
Lifecycle insights (like others) should support groups for paid users.
Changes
Does this work well for both Cloud and self-hosted?
Yes
How did you test this code?