0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-12-01 04:12:23 +01:00
posthog/ee/clickhouse/queries/funnels/funnel_strict_persons.py
Karl-Aksel Puulmann 784c7d3b08
Related groups query refactor (#7978)
* Resolve weird SQL formatting issue

* Use a discriminated union for ActorType

* Use standard response types for related groups

* Update typing

* Always filter related actors by group type index

* Update snapshots & typing
2022-01-12 13:15:43 +02:00

29 lines
1.2 KiB
Python

from typing import List, Optional, cast
from ee.clickhouse.queries.actor_base_query import ActorBaseQuery
from ee.clickhouse.queries.funnels.funnel_strict import ClickhouseFunnelStrict
from ee.clickhouse.sql.funnels.funnel import FUNNEL_PERSONS_BY_STEP_SQL
from posthog.models.filters.filter import Filter
from posthog.models.filters.mixins.utils import cached_property
class ClickhouseFunnelStrictActors(ClickhouseFunnelStrict, ActorBaseQuery):
_filter: Filter
@cached_property
def aggregation_group_type_index(self):
return self._filter.aggregation_group_type_index
def actor_query(self, limit_actors: Optional[bool] = True, extra_fields: Optional[List[str]] = None):
extra_fields_string = ", ".join([self._get_timestamp_outer_select()] + (extra_fields or []))
return (
FUNNEL_PERSONS_BY_STEP_SQL.format(
steps_per_person_query=self.get_step_counts_query(),
persons_steps=self._get_funnel_person_step_condition(),
extra_fields=extra_fields_string,
limit="LIMIT %(limit)s" if limit_actors else "",
offset="OFFSET %(offset)s" if limit_actors else "",
),
self.params,
)