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: enable hogql cohorts #30426

Merged
merged 28 commits into from
Mar 26, 2025
Merged

feat: enable hogql cohorts #30426

merged 28 commits into from
Mar 26, 2025

Conversation

aspicer
Copy link
Contributor

@aspicer aspicer commented Mar 25, 2025

This PR moves cohort calculation to the new HogQL cohorts, behind a feature flag by org.

Checked loki error logs and found just a few cohorts erroring. Fixed an assortment of bugs for these and added tests.

Did a comparison of data on prod and found consistent results.

Rollout plan is to slowly increase the teams using hogql cohorts by default (starting with team 2) over the next week, and complete the switch soon. Will follow with another PR to remove and disentangle the old code.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR implements HogQL-based cohort functionality in PostHog, adding support for advanced property filtering and improving cohort recalculation performance.

  • Added IN/NOT_IN operator support in property expressions with proper list value validation in posthog/hogql/property.py
  • Introduced HogQL global settings (max_ast_elements, max_expanded_ast_elements, max_bytes_before_external_group_by) in posthog/models/cohort/util.py to prevent performance issues
  • Added temporary year-to-month conversion (multiplying by 12) in posthog/hogql_queries/hogql_cohort_query.py until proper year support is implemented
  • Enhanced test coverage in ee/clickhouse/queries/test/test_cohort_query.py with new cases for long-term filtering and array value handling

4 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@aspicer aspicer changed the title feat: hogql cohorts feat: enable hogql cohorts Mar 26, 2025
@aspicer aspicer requested review from a team March 26, 2025 07:31
Copy link
Contributor

@haacked haacked left a comment

Choose a reason for hiding this comment

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

Looks good to me! One note about test, but nothing blocking.

timestamp=datetime.now() - timedelta(days=1),
)

# Person 2: Doesn't match - has only 1 "Application Opened" event
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to add a case where the person has 2 "Application Opened" events, but one is outside of the time interval, and therefore doesn't match?

@aspicer aspicer merged commit 391e151 into master Mar 26, 2025
96 checks passed
@aspicer aspicer deleted the aspicer/cohort_switch branch March 26, 2025 19:31
@aspicer aspicer restored the aspicer/cohort_switch branch March 26, 2025 19:31
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