Skip to content
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(hogql): cohort filter #14600

Merged
merged 16 commits into from
Mar 9, 2023
Merged

feat(hogql): cohort filter #14600

merged 16 commits into from
Mar 9, 2023

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Mar 7, 2023

Problem

One of the things blocking the new event explorer is lack of cohort filters PostHog/meta#81

Changes

Implements cohort filters in a similar way I saw insights and the events table implement cohort filters.

if cohort.is_static:
    sql = "person_id in (SELECT person_id FROM static_cohort_people WHERE cohort_id = {cohort_id})"
else:
    sql = "person_id in (SELECT person_id FROM cohort_people WHERE cohort_id = {cohort_id} GROUP BY person_id, cohort_id, version HAVING sum(sign) > 0)"

Also makes it possible to query from cohort tables
image
image

How did you test this code?

Added tests.

@mariusandra mariusandra marked this pull request as ready for review March 7, 2023 21:48
@mariusandra mariusandra requested a review from a team March 7, 2023 21:49
Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

I can query for cohorts

@@ -278,6 +278,35 @@ def hogql_table(self):
return "session_recording_events"


class CohortPeople(Table):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tangential to this PR but I wonder what stops these definitions and the actual table definitions from diverging other than people being careful

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

People are always careful :).

Good question. Noting really. I added "Lock down" tables for HogQL. Make sure we don't change something users might query on. Expose only what we deem relevant. as a point to the list of all lists.

@mariusandra mariusandra merged commit 260efe1 into master Mar 9, 2023
@mariusandra mariusandra deleted the hogql-cohort-filters branch March 9, 2023 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants