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

fix(piechart): 5696 breakdown #9258

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ee/clickhouse/sql/trends/breakdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@


BREAKDOWN_AGGREGATE_QUERY_SQL = """
SELECT {aggregate_operation} AS total, {breakdown_value} AS breakdown_value
SELECT {aggregate_operation} AS total, if({breakdown_value} IN %(values)s, {breakdown_value}, 'Other') AS breakdown_value
FROM events e
{person_join}
{groups_join}
{breakdown_filter}
GROUP BY breakdown_value
ORDER BY breakdown_value
"""
Expand Down
27 changes: 27 additions & 0 deletions posthog/queries/test/test_trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,33 @@ def test_breakdown_by_property_pie(self):
value_2_ids = [person["id"] for person in people]
self.assertTrue(value_2_ids == [person2.uuid] or value_2_ids == [person2.pk])

def test_breakdown_by_property_pie_other(self):
for i in range(30):
person_factory(team_id=self.team.pk, distinct_ids=[f"person{i}"])
event_factory(
team=self.team,
event="watched movie",
distinct_id=f"person{i}",
timestamp="2020-01-03T12:00:00Z",
properties={"fake_prop": f"test_{i}"},
)

with freeze_time("2020-01-04T13:01:01Z"):
data = {
"date_from": "-14d",
"breakdown": "fake_prop",
"breakdown_type": "event",
"display": "ActionsPie",
"events": [
{"id": "watched movie", "name": "watched movie", "type": "events", "order": 0, "math": "dau",}
],
}
event_response = trends().run(Filter(data=data), self.team,)
self.assertEqual(sum([res["aggregated_value"] for res in event_response]), 30)
other_item = [i for i in event_response if i["breakdown_value"] == "Other"]
self.assertEqual(len(other_item), 1)
self.assertEqual(other_item[0]["aggregated_value"], 5)

@test_with_materialized_columns(person_properties=["name"])
def test_breakdown_by_person_property_pie(self):
self._create_multiple_people()
Expand Down