2021-08-26 20:00:49 +02:00
|
|
|
from typing import Any, Dict, Optional, Tuple
|
2021-08-20 16:48:00 +02:00
|
|
|
|
|
|
|
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(
|
2021-08-26 20:00:49 +02:00
|
|
|
entity: Entity,
|
|
|
|
team_id: int,
|
|
|
|
table_name: str = "",
|
|
|
|
*,
|
2021-09-07 08:05:13 +02:00
|
|
|
person_properties_column: str,
|
2021-08-26 20:00:49 +02:00
|
|
|
with_prop_filters: bool = False,
|
2021-08-20 16:48:00 +02:00
|
|
|
) -> Tuple[Dict, Dict]:
|
|
|
|
params: Dict[str, Any] = {}
|
|
|
|
content_sql_params: Dict[str, str]
|
|
|
|
prop_filters = ""
|
|
|
|
if with_prop_filters:
|
2021-08-26 20:00:49 +02:00
|
|
|
prop_filters, params = parse_prop_clauses(
|
2021-09-07 12:36:14 +02:00
|
|
|
entity.properties,
|
|
|
|
team_id,
|
|
|
|
table_name=table_name,
|
|
|
|
person_properties_column=person_properties_column,
|
|
|
|
prepend=f"entity",
|
2021-08-26 20:00:49 +02:00
|
|
|
)
|
2021-08-20 16:48:00 +02:00
|
|
|
if entity.type == TREND_FILTER_TYPE_ACTIONS:
|
|
|
|
action = entity.get_action()
|
2021-08-26 20:00:49 +02:00
|
|
|
action_query, action_params = format_action_filter(
|
|
|
|
action, table_name=table_name, person_properties_column=person_properties_column
|
|
|
|
)
|
2021-08-20 16:48:00 +02:00
|
|
|
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
|