0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 18:26:15 +01:00
posthog/ee/clickhouse/models/entity.py
Karl-Aksel Puulmann 457e151f58
Push person predicates down (#6346)
* Refactor column_optimizer to work differently

* WIP: Use counter over set

* Handle person filters in person query

* Remove a dead argument

* Use enum over parameter for determining behavior

* Allow excluding person properties mode when handled in person query

* Fix _get_person_query type

* Use correct table for funnel_event_query

* Remove unneeded override

* Add extra typing

* Filter by entity.properties in person query for trends

* Handle error 184 due to naming clash

* Better default for prop_filter_json_extract

* Update column_optimizer tests for Counter

* Handle person_props as extra_fields

* Handle breakdowns and person property filter pushdown

* Transform values correctly

* Simplify get_entity_filtering_params

* Fix funnel correlations

* Solve caching issues in trend people queries

* Remove @skip test

* Add syrupy tests for parse_prop_clauses

Can update these via --snapshot-update

* Add snapshot tests for person queries

* Add a few notes

* Update test to avoid collision

* Kill dead code

* Handle PR comments

* Update ee/clickhouse/queries/person_query.py

Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>

Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
2021-10-13 14:00:47 +00:00

30 lines
1.0 KiB
Python

from typing import Any, Dict, Tuple
from ee.clickhouse.models.action import format_action_filter
from ee.clickhouse.models.util import PersonPropertiesMode
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_mode: PersonPropertiesMode = PersonPropertiesMode.USING_PERSON_PROPERTIES_COLUMN,
) -> Tuple[Dict, Dict]:
params: Dict[str, Any] = {}
content_sql_params: Dict[str, str]
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_mode=person_properties_mode,
)
params.update(action_params)
content_sql_params = {"entity_query": f"AND {action_query}"}
else:
params["event"] = entity.id
content_sql_params = {"entity_query": f"AND event = %(event)s"}
return params, content_sql_params