mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-30 19:41:46 +01:00
2d60a5b670
* working date filter * frontend for period * remove period * add params * add period * period working * add test for period * merge master * fix test * add dropdowns for period date filtering * pass params and handle properly * fix labels and readjust tests * test split for retentino period * make insight retention test just test for response * add condition * feature flag the frontend and bring back ff for the ch endpoint * fix cohort filtering * fix cohort querying * remove init * remove feature flag * add back featureflag * block person modal on retention page if clickhouse enabled * use distinct_id instead of joining for person_id
30 lines
1.4 KiB
Python
30 lines
1.4 KiB
Python
from typing import Any, Dict, Tuple
|
|
|
|
from ee.clickhouse.models.action import format_action_filter
|
|
from ee.clickhouse.sql.cohort import CALCULATE_COHORT_PEOPLE_SQL, PERSON_PROPERTY_FILTER_SQL
|
|
from posthog.models import Action, Cohort, Filter
|
|
|
|
|
|
def format_filter_query(cohort: Cohort) -> Tuple[str, Dict]:
|
|
filters = []
|
|
params: Dict[str, Any] = {}
|
|
for group in cohort.groups:
|
|
if group.get("action_id"):
|
|
action = Action.objects.get(pk=group["action_id"], team_id=cohort.team.pk)
|
|
action_filter_query, action_params = format_action_filter(action)
|
|
extract_person = "SELECT distinct_id FROM events WHERE uuid IN ({query})".format(query=action_filter_query)
|
|
params = {**params, **action_params}
|
|
filters.append("(" + extract_person + ")")
|
|
elif group.get("properties"):
|
|
filter = Filter(data=group)
|
|
prop_filter = filter.format_ch(team_id=cohort.team.pk)
|
|
extract_distinct_id = "SELECT distinct_id FROM person_distinct_id WHERE person_id IN ({query})".format(
|
|
query=PERSON_PROPERTY_FILTER_SQL.format(filters=prop_filter)
|
|
)
|
|
filters.append("(" + extract_distinct_id + ")")
|
|
|
|
separator = " OR distinct_id IN "
|
|
joined_filter = separator.join(filters)
|
|
person_id_query = CALCULATE_COHORT_PEOPLE_SQL.format(query=joined_filter)
|
|
return person_id_query, params
|