Skip to content

Commit

Permalink
distinct
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Oct 2, 2024
1 parent ae514b9 commit 7000caf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions posthog/models/cohort/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,11 @@ def format_person_query(cohort: Cohort, index: int, hogql_context: HogQLContext)
def print_cohort_hogql_query(cohort: Cohort, hogql_context: HogQLContext) -> str:
from posthog.hogql_queries.query_runner import get_query_runner

source_query = cast(dict, cohort.query)

if source_query.get("kind") == "ActorsQuery":
source_query["select"] = ["id as actor_id"]
if not cohort.query:
raise ValueError("Cohort has no query")

query = get_query_runner(
source_query, team=cast(Team, cohort.team), limit_context=LimitContext.COHORT_CALCULATION
cast(dict, cohort.query), team=cast(Team, cohort.team), limit_context=LimitContext.COHORT_CALCULATION
).to_query()

select_queries: list[ast.SelectQuery] = [query] if isinstance(query, ast.SelectQuery) else query.select_queries
Expand Down
2 changes: 1 addition & 1 deletion posthog/models/person/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@

INSERT_COHORT_ALL_PEOPLE_THROUGH_PERSON_ID = """
INSERT INTO {cohort_table} SELECT generateUUIDv4(), actor_id, %(cohort_id)s, %(team_id)s, %(_timestamp)s, 0 FROM (
SELECT actor_id FROM ({query})
SELECT DISTINCT actor_id FROM ({query})
)
"""

Expand Down

0 comments on commit 7000caf

Please sign in to comment.