0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 18:26:15 +01:00
posthog/ee/clickhouse/queries/sessions/distribution.py
Tim Glaser 7fe96b813d
Fix error too deep recursion (#7445)
* Fix error too deep recursion

* Add space

* space no 'AND'

* update snapshots

* fix test

* fix test

* Remove team_id from prop_clause
2021-12-02 12:12:14 +01:00

42 lines
1.5 KiB
Python

from ee.clickhouse.client import sync_execute
from ee.clickhouse.models.property import parse_prop_clauses
from ee.clickhouse.queries.sessions.util import entity_query_conditions
from ee.clickhouse.queries.util import parse_timestamps
from ee.clickhouse.sql.sessions.distribution import DIST_SQL
from posthog.models import Filter, Team
class ClickhouseSessionsDist:
def calculate_dist(self, filter: Filter, team: Team):
from posthog.queries.sessions.sessions import DIST_LABELS
parsed_date_from, parsed_date_to, date_params = parse_timestamps(filter, team.pk)
filters, params = parse_prop_clauses(
filter.properties, has_person_id_joined=False, group_properties_joined=False
)
entity_conditions, entity_params = entity_query_conditions(filter, team)
if not entity_conditions:
return []
params = {**params, **entity_params}
entity_query = " OR ".join(entity_conditions)
dist_query = DIST_SQL.format(
team_id=team.pk,
date_from=parsed_date_from,
date_to=parsed_date_to,
filters=filters if filters else "",
sessions_limit="",
entity_filter=f"AND ({entity_query})",
)
params = {**params, "team_id": team.pk, **date_params}
result = sync_execute(dist_query, params)
res = [{"label": DIST_LABELS[index], "count": result[0][index]} for index in range(len(DIST_LABELS))]
return res