2021-10-13 16:00:47 +02:00
|
|
|
from typing import Any, Dict, Tuple
|
2021-08-20 16:48:00 +02:00
|
|
|
|
|
|
|
from ee.clickhouse.models.action import format_action_filter
|
2021-10-13 16:00:47 +02:00
|
|
|
from ee.clickhouse.models.util import PersonPropertiesMode
|
2021-08-20 16:48:00 +02:00
|
|
|
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-10-13 16:00:47 +02:00
|
|
|
person_properties_mode: PersonPropertiesMode = PersonPropertiesMode.USING_PERSON_PROPERTIES_COLUMN,
|
2021-08-20 16:48:00 +02:00
|
|
|
) -> Tuple[Dict, Dict]:
|
|
|
|
params: Dict[str, Any] = {}
|
|
|
|
content_sql_params: Dict[str, str]
|
|
|
|
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(
|
2021-10-13 16:00:47 +02:00
|
|
|
action, table_name=table_name, person_properties_mode=person_properties_mode,
|
2021-08-26 20:00:49 +02:00
|
|
|
)
|
2021-08-20 16:48:00 +02:00
|
|
|
params.update(action_params)
|
2021-10-13 16:00:47 +02:00
|
|
|
content_sql_params = {"entity_query": f"AND {action_query}"}
|
2021-08-20 16:48:00 +02:00
|
|
|
else:
|
|
|
|
params["event"] = entity.id
|
2021-10-13 16:00:47 +02:00
|
|
|
content_sql_params = {"entity_query": f"AND event = %(event)s"}
|
2021-08-20 16:48:00 +02:00
|
|
|
|
|
|
|
return params, content_sql_params
|