0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-12-01 04:12:23 +01:00
posthog/ee/clickhouse/models/entity.py
Karl-Aksel Puulmann 4306444c2e
Fix issue with person breakdowns and clashing params (#5815)
* Fix issue with person breakdowns and clashing params

Closes https://github.com/PostHog/posthog/issues/5814

Another PR https://github.com/PostHog/posthog/pull/5807 also fixes this
(incidentally) but this fix won't hurt it + adds a regression test.

* Autoimport Property into shell_plus to speed up debugging

* Remove index
2021-09-07 13:36:14 +03:00

40 lines
1.3 KiB
Python

from typing import Any, Dict, Optional, Tuple
from ee.clickhouse.models.action import format_action_filter
from ee.clickhouse.models.property import parse_prop_clauses
from posthog.constants import TREND_FILTER_TYPE_ACTIONS
from posthog.models.entity import Entity
def get_entity_filtering_params(
entity: Entity,
team_id: int,
table_name: str = "",
*,
person_properties_column: str,
with_prop_filters: bool = False,
) -> Tuple[Dict, Dict]:
params: Dict[str, Any] = {}
content_sql_params: Dict[str, str]
prop_filters = ""
if with_prop_filters:
prop_filters, params = parse_prop_clauses(
entity.properties,
team_id,
table_name=table_name,
person_properties_column=person_properties_column,
prepend=f"entity",
)
if entity.type == TREND_FILTER_TYPE_ACTIONS:
action = entity.get_action()
action_query, action_params = format_action_filter(
action, table_name=table_name, person_properties_column=person_properties_column
)
params.update(action_params)
content_sql_params = {"entity_query": f"AND {action_query} {prop_filters}"}
else:
params["event"] = entity.id
content_sql_params = {"entity_query": f"AND event = %(event)s {prop_filters}"}
return params, content_sql_params