Skip to content

Commit

Permalink
fix: hogql cohort queries (#27811)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
aspicer and github-actions[bot] authored Feb 20, 2025
1 parent 0f3e6fb commit 0ead186
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 428 deletions.
68 changes: 34 additions & 34 deletions ee/clickhouse/models/test/__snapshots__/test_cohort.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@
HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))) AS persons
WHERE ifNull(equals(persons.`properties___$some_prop`, 'something'), 0)
ORDER BY persons.id ASC
LIMIT 100 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto')) INTERSECT (
(SELECT persons.id AS id
FROM
(SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$another_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$another_prop`,
person.id AS id
FROM person
WHERE and(equals(person.team_id, 99999), in(id,
(SELECT where_optimization.id AS id
FROM person AS where_optimization
WHERE and(equals(where_optimization.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(where_optimization.properties, '$another_prop'), ''), 'null'), '^"|"$', ''), 'something'), 0)))))
GROUP BY person.id
HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))) AS persons
WHERE ifNull(equals(persons.`properties___$another_prop`, 'something'), 0)
ORDER BY persons.id ASC
LIMIT 100 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto')))) as person SETTINGS optimize_aggregation_in_order = 1,
join_algorithm = 'auto'
LIMIT 1000000000 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto')) INTERSECT (
(SELECT persons.id AS id
FROM
(SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$another_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$another_prop`,
person.id AS id
FROM person
WHERE and(equals(person.team_id, 99999), in(id,
(SELECT where_optimization.id AS id
FROM person AS where_optimization
WHERE and(equals(where_optimization.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(where_optimization.properties, '$another_prop'), ''), 'null'), '^"|"$', ''), 'something'), 0)))))
GROUP BY person.id
HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))) AS persons
WHERE ifNull(equals(persons.`properties___$another_prop`, 'something'), 0)
ORDER BY persons.id ASC
LIMIT 1000000000 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto')))) as person SETTINGS optimize_aggregation_in_order = 1,
join_algorithm = 'auto'
'''
# ---
# name: TestCohort.test_cohortpeople_with_not_in_cohort_operator
Expand Down Expand Up @@ -137,9 +137,9 @@
HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))) AS persons
WHERE ifNull(equals(persons.`properties___$some_prop`, 'something1'), 0)
ORDER BY persons.id ASC
LIMIT 100 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto')) as person SETTINGS optimize_aggregation_in_order = 1,
join_algorithm = 'auto'
LIMIT 1000000000 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto')) as person SETTINGS optimize_aggregation_in_order = 1,
join_algorithm = 'auto'
'''
# ---
# name: TestCohort.test_cohortpeople_with_not_in_cohort_operator.2
Expand Down Expand Up @@ -236,8 +236,8 @@
WHERE and(equals(e.team_id, 99999), greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp.000000', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp.999999', 6, 'UTC')), equals(e.event, '$pageview')))
GROUP BY actor_id) AS source
ORDER BY source.id ASC
LIMIT 100 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto'))
LIMIT 1000000000 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto'))
EXCEPT (((
(SELECT persons.id AS id
FROM
Expand All @@ -252,9 +252,9 @@
HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))) AS persons
WHERE ifNull(equals(persons.`properties___$some_prop`, 'something1'), 0)
ORDER BY persons.id ASC
LIMIT 100 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto'))))) as person SETTINGS optimize_aggregation_in_order = 1,
join_algorithm = 'auto'
LIMIT 1000000000 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto'))))) as person SETTINGS optimize_aggregation_in_order = 1,
join_algorithm = 'auto'
'''
# ---
# name: TestCohort.test_cohortpeople_with_not_in_cohort_operator_and_no_precalculation
Expand Down Expand Up @@ -393,9 +393,9 @@
or isNotNull(fromUnixTimestamp(0)))))
GROUP BY actor_id) AS source
ORDER BY source.id ASC
LIMIT 100 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto')) as person SETTINGS optimize_aggregation_in_order = 1,
join_algorithm = 'auto'
LIMIT 1000000000 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto')) as person SETTINGS optimize_aggregation_in_order = 1,
join_algorithm = 'auto'
'''
# ---
# name: TestCohort.test_cohortpeople_with_not_in_cohort_operator_for_behavioural_cohorts.2
Expand Down Expand Up @@ -478,8 +478,8 @@
WHERE and(equals(e.team_id, 99999), greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp.000000', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp.999999', 6, 'UTC')), equals(e.event, '$pageview')))
GROUP BY actor_id) AS source
ORDER BY source.id ASC
LIMIT 100 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto'))
LIMIT 1000000000 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto'))
EXCEPT (((
(SELECT source.id AS id
FROM
Expand Down Expand Up @@ -508,9 +508,9 @@
or isNotNull(fromUnixTimestamp(0)))))
GROUP BY actor_id) AS source
ORDER BY source.id ASC
LIMIT 100 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto'))))) as person SETTINGS optimize_aggregation_in_order = 1,
join_algorithm = 'auto'
LIMIT 1000000000 SETTINGS optimize_aggregation_in_order=1,
join_algorithm='auto'))))) as person SETTINGS optimize_aggregation_in_order = 1,
join_algorithm = 'auto'
'''
# ---
# name: TestCohort.test_static_cohort_precalculated
Expand Down
Loading

0 comments on commit 0ead186

Please sign in to comment.