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 trends #17519

Merged
merged 28 commits into from
Sep 22, 2023
Merged

feat: hogql trends #17519

merged 28 commits into from
Sep 22, 2023

Conversation

Gilbert09
Copy link
Member

@Gilbert09 Gilbert09 commented Sep 19, 2023

Problem

We want to move insight trends backend to use HogQL as opposed to the current janky filter query

Changes

Started off this work behind the hogql_insights feature flag. Got the trends insight rendering with some basic functionality:

  • Multiple series
  • Date range filters
  • The Total Count and HogQL Expression math operators
  • Property filters (internal users flag, etc)

Still to do:

  • All other math operators
  • Breakdown
  • Sampling
  • Formulas
  • Series filtering
  • Graph display types (pie chart, cumulative line graph, etc)
  • Compare to previous period
  • Show as % of total
  • persons_urls in response obj
  • actions in response obj

(anything else I've forgotten here?)

How did you test this code?

Only been testing in the browser so far. Some testing will be required on the new backend query runner

Comment on lines 24 to 49
with self.timings.measure("trends_query"):
for series in self.query.series:
queries.append(
parse_select(
Copy link
Member Author

Choose a reason for hiding this comment

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

To support multiple series. Looks like we'll have to execute multiple queries (the current trends code does this too, but in parallel with multiple series). I had looked at using a UNION ALL over multiple queries, but we could very easily hit max query limits given a bunch of series. Are there any alternatives that can be used here with Clickhouse / HogQL?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm... Scope creep, but what about just multiple columns in the same query? E.g. select count(distinct person_id) as series1, count(id) as series_2, etc from event

The base from events query is always the same for everyone --> all events + date range + global filters.

The individual event queries filter this further. E.g. "only $pageview with filters 1, 2, 3". This could be accomplished with something like:

select 
  countIf(distinct person_id, series_1_filters) as series1, 
  countIf(id, series_2_filters) as series_2
from event
where global_filters

This might break with DAU/MAU queries, but I'm not sure right now..

The global filters could then include the common filters (e.g. event='$pageview') if there are any to speed up the process, otherwise they'd read through all events. Doing a UNION ALL query, or doing multiple queries and aggregating the results, works... but is likely slower as you need to do multiple passes over the data.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@Gilbert09 Gilbert09 changed the title WIP: Feat/hogql trends feat: hogql trends Sep 20, 2023
@Gilbert09 Gilbert09 requested a review from a team September 20, 2023 09:44
@Gilbert09 Gilbert09 marked this pull request as ready for review September 20, 2023 09:44
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

Copy link
Member

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

Seems like a good start (but is gonna need tests)

from typing import Any, Dict, List


class FormulaAST:
Copy link
Member

Choose a reason for hiding this comment

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

This deserves a small test suite of its own, so I propose adding formula support in separate PR

Copy link
Collaborator

@mariusandra mariusandra 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! Great work! Agreed re: tests though, but happy to add them in a followup.

@Gilbert09 Gilbert09 enabled auto-merge (squash) September 22, 2023 16:04
@Gilbert09 Gilbert09 merged commit 9c1e31b into master Sep 22, 2023
@Gilbert09 Gilbert09 deleted the feat/hogql-trends branch September 22, 2023 17:29
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.

4 participants