mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-29 02:46:32 +01:00
4e02411eda
* Fix fetching event-based breakdown values with `LIMIT`
* Improve test comment
* Limit prop clauses inclusion to breakdown queries
* Address feedback partly
* Fix imports
* Remove non-3.7-compatible `Literal`
* Don't try to import `Literal`
* Fix oversight
* Always include prop filters in `get_entity_filtering_params`
* Revert "Always include prop filters in `get_entity_filtering_params`"
This reverts commit 4f61edd19a
.
* Add and test handling of actions in addition to events
* Update test_funnel.py
* Move new tests to `breakdown_cases`
27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
from typing import Any, Dict, 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 = "", *, 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)
|
|
if entity.type == TREND_FILTER_TYPE_ACTIONS:
|
|
action = entity.get_action()
|
|
action_query, action_params = format_action_filter(action, table_name=table_name)
|
|
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
|