def _determine_should_join_persons(self) -> None: for prop in self._filter.properties: if prop.type == "person": self._should_join_distinct_ids = True self._should_join_persons = True return if prop.type == "cohort" and self._does_cohort_need_persons(prop): self._should_join_distinct_ids = True self._should_join_persons = True return for prop in self._entity.properties: if prop.type == "person": self._should_join_distinct_ids = True self._should_join_persons = True return if self._filter.breakdown_type == "person": self._should_join_distinct_ids = True self._should_join_persons = True if self._filter.filter_test_accounts: test_account_filters = Team.objects.only("test_account_filters").get(id=self._team_id).test_account_filters test_filter_props = [Property(**prop) for prop in test_account_filters] for prop in test_filter_props: if prop.type == "person": self._should_join_distinct_ids = True self._should_join_persons = True return
def _group_set_property(self, group_type_index: int) -> "Property": from posthog.models.property import Property return Property( key=f"$group_{group_type_index}", value="", operator="is_not", )
def _get_props(self, filters: List[Property], allow_denormalized_props: bool = False) -> Tuple[str, Dict]: filter_test_accounts = self._filter.filter_test_accounts team_id = self._team_id table_name = f"{self.EVENT_TABLE_ALIAS}." prepend = "global" final = [] params: Dict[str, Any] = {} if filter_test_accounts: test_account_filters = Team.objects.only( "test_account_filters").get(id=team_id).test_account_filters filters.extend([Property(**prop) for prop in test_account_filters]) for idx, prop in enumerate(filters): if prop.type == "cohort": person_id_query, cohort_filter_params = self._get_cohort_subquery( prop) params = {**params, **cohort_filter_params} final.append(f"AND {person_id_query}") elif prop.type == "person": filter_query, filter_params = prop_filter_json_extract( prop, idx, "{}person".format(prepend), allow_denormalized_props=allow_denormalized_props, prop_var=self._PERSON_PROPERTIES_ALIAS, ) final.append(filter_query) params.update(filter_params) elif prop.type == "element": query, filter_params = filter_element( {prop.key: prop.value}, prepend="{}_".format(idx)) final.append("AND {}".format(query[0])) params.update(filter_params) else: filter_query, filter_params = prop_filter_json_extract( prop, idx, prepend, prop_var="properties", allow_denormalized_props=allow_denormalized_props, ) final.append(filter_query) params.update(filter_params) return " ".join(final), params