diff --git a/ee/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_filters.ambr b/ee/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_filters.ambr index fa34233a68fc6..2a88759e116ee 100644 --- a/ee/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_filters.ambr +++ b/ee/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_filters.ambr @@ -59,18 +59,12 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_7)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___rgInternal + (SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_7)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___rgInternal, person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_8)s), ''), 'null'), '^"|"$', ''), %(hogql_val_9)s), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_10)s), ''), 'null'), '^"|"$', ''), %(hogql_val_11)s), 0)) + WHERE equals(person.team_id, 2) GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_12)s), person.version), plus(now64(6, %(hogql_val_13)s), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) - WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_14)s), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_15)s), now64(6, %(hogql_val_16)s)), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_17)s), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_18)s), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), ifNull(equals(events__person.properties___rgInternal, %(hogql_val_19)s), 0)) + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_8)s), person.version), plus(now64(6, %(hogql_val_9)s), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_10)s), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_11)s), now64(6, %(hogql_val_12)s)), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_13)s), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_14)s), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), ifNull(equals(events__person.properties___rgInternal, %(hogql_val_15)s), 0)) GROUP BY events.`$session_id` HAVING 1))) GROUP BY s.session_id @@ -108,18 +102,12 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_7)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___rgInternal + (SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_7)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___rgInternal, person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_8)s), ''), 'null'), '^"|"$', ''), %(hogql_val_9)s), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_10)s), ''), 'null'), '^"|"$', ''), %(hogql_val_11)s), 0)) + WHERE equals(person.team_id, 2) GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_12)s), person.version), plus(now64(6, %(hogql_val_13)s), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) - WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_14)s), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_15)s), now64(6, %(hogql_val_16)s)), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_17)s), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_18)s), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), ifNull(equals(events__person.properties___rgInternal, %(hogql_val_19)s), 0)) + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_8)s), person.version), plus(now64(6, %(hogql_val_9)s), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_10)s), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_11)s), now64(6, %(hogql_val_12)s)), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_13)s), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_14)s), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), ifNull(equals(events__person.properties___rgInternal, %(hogql_val_15)s), 0)) GROUP BY events.`$session_id` HAVING 1))) GROUP BY s.session_id @@ -536,17 +524,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.pmat_email, ''), 'null'), person.version) AS properties___email + (SELECT person.id AS id, nullIf(nullIf(person.pmat_email, ''), 'null') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 0)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING 1))) @@ -625,17 +610,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.pmat_email, ''), 'null'), person.version) AS properties___email + (SELECT person.id AS id, nullIf(nullIf(person.pmat_email, ''), 'null') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 0)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING 1))) @@ -714,17 +696,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.pmat_email, ''), 'null'), person.version) AS properties___email + (SELECT person.id AS id, nullIf(nullIf(person.pmat_email, ''), 'null') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 0)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING 1))) @@ -803,17 +782,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.pmat_email, ''), 'null'), person.version) AS properties___email + (SELECT person.id AS id, nullIf(nullIf(person.pmat_email, ''), 'null') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 0)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING 1))) diff --git a/frontend/__snapshots__/exporter-exporter--trends-line-insight-detailed--dark.png b/frontend/__snapshots__/exporter-exporter--trends-line-insight-detailed--dark.png index b54d4facb0bfe..e3e93b3dd9678 100644 Binary files a/frontend/__snapshots__/exporter-exporter--trends-line-insight-detailed--dark.png and b/frontend/__snapshots__/exporter-exporter--trends-line-insight-detailed--dark.png differ diff --git a/frontend/__snapshots__/exporter-exporter--trends-line-insight-detailed--light.png b/frontend/__snapshots__/exporter-exporter--trends-line-insight-detailed--light.png index 332ea24ce3084..d4377362d9270 100644 Binary files a/frontend/__snapshots__/exporter-exporter--trends-line-insight-detailed--light.png and b/frontend/__snapshots__/exporter-exporter--trends-line-insight-detailed--light.png differ diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json index 07b8daf0c7461..a9dc7be1bf476 100644 --- a/frontend/src/queries/schema.json +++ b/frontend/src/queries/schema.json @@ -6533,6 +6533,13 @@ "enum": ["auto", "legacy_null_as_string", "legacy_null_as_null", "disabled"], "type": "string" }, + "optimizeJoinedFilters": { + "type": "boolean" + }, + "personsArgMaxVersion": { + "enum": ["auto", "v1", "v2"], + "type": "string" + }, "personsJoinMode": { "enum": ["inner", "left"], "type": "string" diff --git a/frontend/src/queries/schema.ts b/frontend/src/queries/schema.ts index dd64349b5f830..1887f57ee0f96 100644 --- a/frontend/src/queries/schema.ts +++ b/frontend/src/queries/schema.ts @@ -227,8 +227,10 @@ export interface HogQLQueryModifiers { | 'person_id_no_override_properties_on_events' | 'person_id_override_properties_on_events' | 'person_id_override_properties_joined' + personsArgMaxVersion?: 'auto' | 'v1' | 'v2' inCohortVia?: 'auto' | 'leftjoin' | 'subquery' | 'leftjoin_conjoined' materializationMode?: 'auto' | 'legacy_null_as_string' | 'legacy_null_as_null' | 'disabled' + optimizeJoinedFilters?: boolean dataWarehouseEventsModifiers?: DataWarehouseEventsModifier[] debug?: boolean s3TableUseInvalidColumns?: boolean diff --git a/frontend/src/scenes/debug/Modifiers.tsx b/frontend/src/scenes/debug/Modifiers.tsx index b75c4a185a087..ee4f0175a724c 100644 --- a/frontend/src/scenes/debug/Modifiers.tsx +++ b/frontend/src/scenes/debug/Modifiers.tsx @@ -47,7 +47,22 @@ export function Modifiers; modifiers? value={query.modifiers?.personsOnEventsMode ?? response?.modifiers?.personsOnEventsMode} /> - + +
Persons ArgMax:
+ + setQuery({ + ...query, + modifiers: { ...query.modifiers, personsArgMaxVersion: value }, + }) + } + value={query.modifiers?.personsArgMaxVersion ?? response?.modifiers?.personsArgMaxVersion} + /> +
In Cohort Via:
; modifiers? value={query.modifiers?.materializationMode ?? response?.modifiers?.materializationMode} />
+ +
Optimize joined filters:
+ + setQuery({ + ...query, + modifiers: { ...query.modifiers, optimizeJoinedFilters: value }, + }) + } + value={query.modifiers?.optimizeJoinedFilters ?? response?.modifiers?.optimizeJoinedFilters} + /> +
Property Groups:
Self: return self def lazy_select(self, table_to_add: LazyTableToAdd, context, node): - # assume that if the select_from is not persons table we're doing a join - try: - is_join = not isinstance(node.select_from.type.table, PersonsTable) - except AttributeError: - is_join = False if self.filter is not None: - return select_from_persons_table( - table_to_add, context, node, filter=clone_expr(self.filter, True), is_join=is_join - ) - return select_from_persons_table(table_to_add, context, node, is_join=is_join) + return select_from_persons_table(table_to_add, context, node, filter=clone_expr(self.filter, True)) + return select_from_persons_table(table_to_add, context, node) def to_printed_clickhouse(self, context): return "person" diff --git a/posthog/hogql/database/schema/test/__snapshots__/test_persons.ambr b/posthog/hogql/database/schema/test/__snapshots__/test_persons.ambr deleted file mode 100644 index a9cbd922cad3b..0000000000000 --- a/posthog/hogql/database/schema/test/__snapshots__/test_persons.ambr +++ /dev/null @@ -1,407 +0,0 @@ -# serializer version: 1 -# name: TestPersonOptimization.test_alias - ''' - SELECT an_alias.id AS id, - an_alias.properties___email AS email - FROM - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` - FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS an_alias - WHERE ifNull(equals(an_alias.`properties___$some_prop`, 'something'), 0) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_events_filter - ''' - SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'email'), ''), 'null'), '^"|"$', '') AS email - FROM events - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, - person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) - LEFT JOIN - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` - FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), 'something'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) - WHERE and(equals(events.team_id, 2), ifNull(equals(events__person.`properties___$some_prop`, 'something'), 0)) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_join - ''' - SELECT persons.id AS id, - persons.properties___email AS email - FROM - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop`, - argMax(person.id, person.version) AS persons___id - FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), 'something'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_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)) SETTINGS optimize_aggregation_in_order=1) AS persons - LEFT JOIN - (SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, - person_distinct_id2.distinct_id AS distinct_id - FROM person_distinct_id2 - WHERE equals(person_distinct_id2.team_id, 2) - GROUP BY person_distinct_id2.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons__pdi ON equals(persons.persons___id, persons__pdi.person_id) - WHERE and(ifNull(equals(persons.`properties___$some_prop`, 'something'), 0), ifNull(equals(persons__pdi.distinct_id, '1'), 0)) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_join.1 - ''' - SELECT persons.id AS id, - persons.properties___email AS email - FROM - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop`, - argMax(person.id, person.version) AS persons___id - FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), 'something'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), 'whatevs'), 0))))), or(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), 'something'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), 'whatevs'), 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)) SETTINGS optimize_aggregation_in_order=1) AS persons - LEFT JOIN - (SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, - person_distinct_id2.distinct_id AS distinct_id - FROM person_distinct_id2 - WHERE equals(person_distinct_id2.team_id, 2) - GROUP BY person_distinct_id2.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons__pdi ON equals(persons.persons___id, persons__pdi.person_id) - WHERE or(and(ifNull(equals(persons.`properties___$some_prop`, 'something'), 0), ifNull(equals(persons__pdi.distinct_id, '1'), 0)), ifNull(equals(persons.`properties___$some_prop`, 'whatevs'), 0)) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_left_join_with_negation - ''' - SELECT persons.id AS id, - persons.`properties___$some_prop` AS `$some_prop` - FROM events - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, - person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) - LEFT JOIN - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` - FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), persons.id) - WHERE and(equals(events.team_id, 2), ifNull(notEquals(persons.`properties___$some_prop`, 'something'), 1)) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_left_join_with_negation.1 - ''' - SELECT persons.id AS id, - persons.`properties___$some_prop` AS `$some_prop` - FROM events - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, - person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) - LEFT JOIN - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` - FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), persons.id) - WHERE and(equals(events.team_id, 2), ifNull(notEquals(persons.`properties___$some_prop`, 'something'), 1)) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_left_join_with_negation.2 - ''' - SELECT persons.id AS id, - persons.`properties___$some_prop` AS `$some_prop` - FROM events - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, - person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) - LEFT JOIN - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` - FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), persons.id) - WHERE and(equals(events.team_id, 2), ifNull(not(match(persons.`properties___$some_prop`, '^something$')), isNotNull(persons.`properties___$some_prop`) - or isNotNull('^something$'))) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_left_join_with_negation.3 - ''' - SELECT persons.id AS id, - persons.`properties___$some_prop` AS `$some_prop` - FROM events - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, - person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) - LEFT JOIN - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` - FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), persons.id) - WHERE and(equals(events.team_id, 2), not(ifNull(equals(persons.`properties___$some_prop`, 'something'), 0))) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_left_join_with_negation.4 - ''' - SELECT persons.id AS id, - persons.`properties___$some_prop` AS `$some_prop` - FROM events - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, - person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) - LEFT JOIN - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` - FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), persons.id) - WHERE and(equals(events.team_id, 2), not(ifNull(equals(persons.`properties___$some_prop`, 'something'), 0))) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_limit_and_order_by - ''' - SELECT persons.id AS id, - persons.`properties___$some_prop` AS `$some_prop` - FROM - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop`, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at - FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons - ORDER BY persons.created_at ASC - LIMIT 3 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_limit_and_order_by.1 - ''' - SELECT persons.id AS id, - persons.`properties___$some_prop` AS `$some_prop` - FROM - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop`, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at - FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons - ORDER BY persons.created_at ASC - LIMIT 2 - OFFSET 1 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_simple_filter - ''' - SELECT persons.id AS id, - persons.`properties___$some_prop` AS `$some_prop` - FROM - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` - FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), 'something'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_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)) SETTINGS optimize_aggregation_in_order=1) AS persons - WHERE ifNull(equals(persons.`properties___$some_prop`, 'something'), 0) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_subquery_alias - ''' - SELECT source.person_id AS person_id, - persons.id AS id - FROM - (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id - FROM events - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, - person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) - WHERE equals(events.team_id, 2)) AS source - INNER JOIN - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` - FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), 'something'), 1)))), ifNull(notEquals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), 'something'), 1)) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(source.person_id, persons.id) - WHERE ifNull(notEquals(persons.`properties___$some_prop`, 'something'), 1) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestPersonOptimization.test_versions_handled_correctly - ''' - SELECT persons.id AS id, - persons.`properties___$some_prop` AS `$some_prop` - FROM - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop`, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at - FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons - ORDER BY persons.created_at ASC - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- diff --git a/posthog/hogql/database/schema/test/__snapshots__/test_session_replay_events.ambr b/posthog/hogql/database/schema/test/__snapshots__/test_session_replay_events.ambr index ebf144085fd45..aa990fe2c7b66 100644 --- a/posthog/hogql/database/schema/test/__snapshots__/test_session_replay_events.ambr +++ b/posthog/hogql/database/schema/test/__snapshots__/test_session_replay_events.ambr @@ -188,17 +188,14 @@ WHERE equals(events.team_id, 2)) AS raw_session_replay_events__events ON equals(session_replay_events.session_id, raw_session_replay_events__events.`$session_id`) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'person_property'), ''), 'null'), '^"|"$', ''), person.version) AS properties___person_property + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'person_property'), ''), 'null'), '^"|"$', '') AS properties___person_property FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'person_property'), ''), 'null'), '^"|"$', ''), 'false'), 'true'), 0)))), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'person_property'), ''), 'null'), '^"|"$', ''), 'false'), 'true'), 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)) SETTINGS optimize_aggregation_in_order=1) AS raw_session_replay_events__events__person ON equals(raw_session_replay_events__events.raw_session_replay_events__events___person_id, raw_session_replay_events__events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS raw_session_replay_events__events__person ON equals(raw_session_replay_events__events.raw_session_replay_events__events___person_id, raw_session_replay_events__events__person.id) WHERE and(equals(session_replay_events.team_id, 2), ifNull(equals(ifNull(raw_session_replay_events__events__person.properties___person_property, 'false'), 'true'), 0)) ORDER BY session_replay_events.session_id ASC LIMIT 100 SETTINGS readonly=2, @@ -247,13 +244,7 @@ LEFT JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), equals(person.id, toUUIDOrNull('00000000-0000-4000-8000-000000000000'))))), equals(person.id, toUUIDOrNull('00000000-0000-4000-8000-000000000000'))) + WHERE equals(person.team_id, 2) 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)) SETTINGS optimize_aggregation_in_order=1) AS raw_session_replay_events__pdi__person ON equals(raw_session_replay_events__pdi.raw_session_replay_events__pdi___person_id, raw_session_replay_events__pdi__person.id) WHERE and(equals(session_replay_events.team_id, 2), ifNull(equals(raw_session_replay_events__pdi__person.id, toUUIDOrNull('00000000-0000-4000-8000-000000000000')), 0)) @@ -282,11 +273,14 @@ HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS raw_session_replay_events__pdi ON equals(session_replay_events.distinct_id, raw_session_replay_events__pdi.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'person_property'), ''), 'null'), '^"|"$', ''), person.version) AS properties___person_property + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'person_property'), ''), 'null'), '^"|"$', '') AS properties___person_property FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS raw_session_replay_events__pdi__person ON equals(raw_session_replay_events__pdi.raw_session_replay_events__pdi___person_id, raw_session_replay_events__pdi__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS raw_session_replay_events__pdi__person ON equals(raw_session_replay_events__pdi.raw_session_replay_events__pdi___person_id, raw_session_replay_events__pdi__person.id) WHERE equals(session_replay_events.team_id, 2) GROUP BY session_replay_events.session_id ORDER BY session_replay_events.session_id ASC @@ -314,17 +308,14 @@ HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS raw_session_replay_events__pdi ON equals(session_replay_events.distinct_id, raw_session_replay_events__pdi.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'person_property'), ''), 'null'), '^"|"$', ''), person.version) AS properties___person_property + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'person_property'), ''), 'null'), '^"|"$', '') AS properties___person_property FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'person_property'), ''), 'null'), '^"|"$', ''), 'true'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'person_property'), ''), 'null'), '^"|"$', ''), 'true'), 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)) SETTINGS optimize_aggregation_in_order=1) AS raw_session_replay_events__pdi__person ON equals(raw_session_replay_events__pdi.raw_session_replay_events__pdi___person_id, raw_session_replay_events__pdi__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'person_property'), ''), 'null'), '^"|"$', ''), 'true'), 0)) SETTINGS optimize_aggregation_in_order=1) AS raw_session_replay_events__pdi__person ON equals(raw_session_replay_events__pdi.raw_session_replay_events__pdi___person_id, raw_session_replay_events__pdi__person.id) WHERE and(equals(session_replay_events.team_id, 2), ifNull(equals(raw_session_replay_events__pdi__person.properties___person_property, 'true'), 0)) GROUP BY session_replay_events.session_id ORDER BY session_replay_events.session_id ASC diff --git a/posthog/hogql/database/schema/test/test_persons.py b/posthog/hogql/database/schema/test/test_persons.py deleted file mode 100644 index 83b45f314cc72..0000000000000 --- a/posthog/hogql/database/schema/test/test_persons.py +++ /dev/null @@ -1,200 +0,0 @@ -from posthog.hogql.parser import parse_select -from posthog.hogql.query import execute_hogql_query -from posthog.test.base import ( - APIBaseTest, - ClickhouseTestMixin, - _create_person, - _create_event, - snapshot_clickhouse_queries, -) -from posthog.models.person.util import create_person -from datetime import datetime - - -class TestPersonOptimization(ClickhouseTestMixin, APIBaseTest): - """ - Mostly tests for the optimization of pre-filtering before aggregating. See https://github.com/PostHog/posthog/pull/25604 - """ - - def setUp(self): - super().setUp() - self.first_person = _create_person( - team_id=self.team.pk, - distinct_ids=["1"], - properties={"$some_prop": "something", "$another_prop": "something1"}, - created_at=datetime(2024, 1, 1, 12), - ) - self.second_person = _create_person( - team_id=self.team.pk, - properties={"$some_prop": "ifwematcholdversionsthiswillmatch", "$another_prop": "something2"}, - distinct_ids=["2"], - version=1, - created_at=datetime(2024, 1, 1, 13), - ) - # update second_person with the correct prop - create_person( - team_id=self.team.pk, - uuid=str(self.second_person.uuid), - properties={"$some_prop": "something", "$another_prop": "something2"}, - created_at=datetime(2024, 1, 1, 13), - version=2, - ) - self.third_person = _create_person( - team_id=self.team.pk, - distinct_ids=["3"], - properties={"$some_prop": "not something", "$another_prop": "something3"}, - created_at=datetime(2024, 1, 1, 14), - ) - # deleted - self.deleted_person = _create_person( - team_id=self.team.pk, - properties={"$some_prop": "ifwematcholdversionsthiswillmatch", "$another_prop": "something2"}, - distinct_ids=["deleted"], - created_at=datetime(2024, 1, 1, 13), - version=1, - ) - create_person(team_id=self.team.pk, uuid=str(self.deleted_person.uuid), version=2, is_deleted=True) - - @snapshot_clickhouse_queries - def test_simple_filter(self): - response = execute_hogql_query( - parse_select("select id, properties.$some_prop from persons where properties.$some_prop = 'something'"), - self.team, - ) - assert len(response.results) == 2 - - @snapshot_clickhouse_queries - def test_alias(self): - # This isn't supported by the WhereClauseExtractor yet - response = execute_hogql_query( - parse_select( - "select id, an_alias.properties.email from persons as an_alias where an_alias.properties.$some_prop = 'something'" - ), - self.team, - ) - assert len(response.results) == 2 - - @snapshot_clickhouse_queries - def test_subquery_alias(self): - _create_event(event="$pageview", distinct_id="3", team=self.team) - response = execute_hogql_query( - parse_select( - """ - select person_id, persons.id from ( - select - person_id - from events - ) as source - inner join persons ON (source.person_id=persons.id) - where notEquals(persons.properties.$some_prop, 'something') - """ - ), - self.team, - ) - assert len(response.results) == 1 - - @snapshot_clickhouse_queries - def test_join(self): - response = execute_hogql_query( - parse_select( - "select id, properties.email from persons where properties.$some_prop = 'something' and pdi.distinct_id = '1'" - ), - self.team, - ) - assert len(response.results) == 1 - - # more complex query - response = execute_hogql_query( - parse_select(""" - select id, properties.email from persons where - (properties.$some_prop = 'something' and pdi.distinct_id = '1') OR - (properties.$some_prop = 'whatevs') - """), - self.team, - ) - assert len(response.results) == 1 - - @snapshot_clickhouse_queries - def test_events_filter(self): - _create_event(event="$pageview", distinct_id="1", team=self.team) - response = execute_hogql_query( - parse_select("select properties.email from events where person.properties.$some_prop = 'something'"), - self.team, - ) - assert len(response.results) == 1 - - @snapshot_clickhouse_queries - def test_versions_handled_correctly(self): - # Tests whether we correctly grab $some_prop from the person with the highest version - response = execute_hogql_query( - parse_select("select id, properties.$some_prop from persons ORDER BY created_at limit 100"), - self.team, - ) - assert len(response.results) == 3 - - @snapshot_clickhouse_queries - def test_left_join_with_negation(self): - _create_event(event="$pageview", distinct_id="1", team=self.team) - _create_event(event="$pageview", distinct_id="2", team=self.team) - _create_event(event="$pageview", distinct_id="3", team=self.team) - response = execute_hogql_query( - parse_select( - "select id, persons.properties.$some_prop from events left join persons ON (events.person_id=persons.id) where notEquals(persons.properties.$some_prop, 'something')" - ), - self.team, - ) - assert len(response.results) == 1 - assert [x[0] for x in response.results] == [ - self.third_person.uuid, - ] - response = execute_hogql_query( - parse_select( - "select id, persons.properties.$some_prop from events left join persons ON (events.person_id=persons.id) where persons.properties.$some_prop != 'something'" - ), - self.team, - ) - assert len(response.results) == 1 - - response = execute_hogql_query( - parse_select( - "select id, persons.properties.$some_prop from events left join persons ON (events.person_id=persons.id) where persons.properties.$some_prop !~ '^something$'" - ), - self.team, - ) - assert len(response.results) == 1 - - response = execute_hogql_query( - parse_select( - "select id, persons.properties.$some_prop from events left join persons ON (events.person_id=persons.id) where not (persons.properties.$some_prop = 'something')" - ), - self.team, - ) - assert len(response.results) == 1 - - response = execute_hogql_query( - parse_select( - "select id, persons.properties.$some_prop from events left join persons ON (events.person_id=persons.id) where not persons.properties.$some_prop = 'something'" - ), - self.team, - ) - assert len(response.results) == 1 - - @snapshot_clickhouse_queries - def test_limit_and_order_by(self): - response = execute_hogql_query( - parse_select("select id, properties.$some_prop from persons ORDER BY created_at limit 3"), - self.team, - ) - assert len(response.results) == 3 - assert [x[0] for x in response.results] == [ - self.first_person.uuid, - self.second_person.uuid, - self.third_person.uuid, - ] - - response = execute_hogql_query( - parse_select("select id, properties.$some_prop from persons ORDER BY created_at limit 2, 1"), - self.team, - ) - assert len(response.results) == 2 - assert [x[0] for x in response.results] == [self.second_person.uuid, self.third_person.uuid] diff --git a/posthog/hogql/database/schema/test/test_session_replay_events.py b/posthog/hogql/database/schema/test/test_session_replay_events.py index 8b396a3b44691..cf74a0f66d182 100644 --- a/posthog/hogql/database/schema/test/test_session_replay_events.py +++ b/posthog/hogql/database/schema/test/test_session_replay_events.py @@ -9,6 +9,7 @@ from posthog.hogql.query import execute_hogql_query from posthog.models.event.sql import TRUNCATE_EVENTS_TABLE_SQL from posthog.models.utils import uuid7 +from posthog.schema import HogQLQueryModifiers from posthog.session_recordings.queries.test.session_replay_sql import produce_replay_summary from posthog.session_recordings.sql.session_replay_event_sql import TRUNCATE_SESSION_REPLAY_EVENTS_TABLE_SQL from posthog.test.base import ( @@ -350,6 +351,25 @@ def test_select_person_property(self): ("session_with_person_with_person_property", "true"), ] + @snapshot_clickhouse_queries + def test_select_where_person_property_without_join_optimization(self): + response = execute_hogql_query( + parse_select( + """ + select session_id, any(person.properties.person_property) + from raw_session_replay_events + where person.properties.person_property = 'true' + group by session_id order by session_id asc + """, + ), + self.team, + modifiers=HogQLQueryModifiers(optimizeJoinedFilters=False), + ) + + assert response.results == [ + ("session_with_person_with_person_property", "true"), + ] + @snapshot_clickhouse_queries def test_select_where_person_property_with_join_optimization(self): response = execute_hogql_query( @@ -362,6 +382,7 @@ def test_select_where_person_property_with_join_optimization(self): """, ), self.team, + modifiers=HogQLQueryModifiers(optimizeJoinedFilters=True), ) assert response.results == [ diff --git a/posthog/hogql/database/schema/util/test/test_person_where_clause_extractor.py b/posthog/hogql/database/schema/util/test/test_person_where_clause_extractor.py index b9c3df237bb52..252382d545b40 100644 --- a/posthog/hogql/database/schema/util/test/test_person_where_clause_extractor.py +++ b/posthog/hogql/database/schema/util/test/test_person_where_clause_extractor.py @@ -7,7 +7,7 @@ from posthog.hogql.printer import prepare_ast_for_printing, print_ast from posthog.hogql.visitor import clone_expr, CloningVisitor from posthog.models import PropertyDefinition -from posthog.schema import PersonsOnEventsMode +from posthog.schema import PersonsOnEventsMode, PersonsArgMaxVersion from posthog.test.base import ClickhouseTestMixin, APIBaseTest @@ -40,7 +40,9 @@ class TestPersonWhereClauseExtractor(ClickhouseTestMixin, APIBaseTest): def prep_context(self): team = self.team modifiers = create_default_modifiers_for_team(team) + modifiers.optimizeJoinedFilters = True modifiers.personsOnEventsMode = PersonsOnEventsMode.DISABLED + modifiers.personsArgMaxVersion = PersonsArgMaxVersion.V1 return HogQLContext( team_id=team.pk, team=team, @@ -77,12 +79,12 @@ def print_query(self, query: str): def test_person_properties(self): actual = self.get_clause("SELECT * FROM events WHERE person.properties.email = 'jimmy@posthog.com'") expected = _expr("properties.email = 'jimmy@posthog.com'") - assert expected in actual.exprs + assert actual == expected def test_person_properties_andor_1(self): actual = self.get_clause("SELECT * FROM events WHERE person.properties.email = 'jimmy@posthog.com' or false") expected = _expr("properties.email = 'jimmy@posthog.com'") - assert expected in actual.exprs + assert actual == expected def test_person_properties_andor_2(self): actual = self.get_clause("SELECT * FROM events WHERE person.properties.email = 'jimmy@posthog.com' and false") @@ -93,28 +95,28 @@ def test_person_properties_andor_3(self): "SELECT * FROM events WHERE person.properties.email = 'jimmy@posthog.com' and person.properties.email = 'timmy@posthog.com'" ) expected = _expr("properties.email = 'jimmy@posthog.com' and properties.email = 'timmy@posthog.com'") - assert expected in actual.exprs + assert actual == expected def test_person_properties_andor_4(self): actual = self.get_clause( "SELECT * FROM events WHERE person.properties.email = 'jimmy@posthog.com' or person.properties.email = 'timmy@posthog.com'" ) expected = _expr("properties.email = 'jimmy@posthog.com' or properties.email = 'timmy@posthog.com'") - assert expected in actual.exprs + assert actual == expected def test_person_properties_andor_5(self): actual = self.get_clause( "SELECT * FROM events WHERE person.properties.email = 'jimmy@posthog.com' or (1 and person.properties.email = 'timmy@posthog.com')" ) expected = _expr("properties.email = 'jimmy@posthog.com' or properties.email = 'timmy@posthog.com'") - assert expected in actual.exprs + assert actual == expected def test_person_properties_andor_6(self): actual = self.get_clause( "SELECT * FROM events WHERE person.properties.email = 'jimmy@posthog.com' or (0 or person.properties.email = 'timmy@posthog.com')" ) expected = _expr("properties.email = 'jimmy@posthog.com' or properties.email = 'timmy@posthog.com'") - assert expected in actual.exprs + assert actual == expected def test_person_properties_andor_7(self): actual = self.get_clause( @@ -127,7 +129,7 @@ def test_person_properties_andor_8(self): "SELECT * FROM events WHERE event == '$pageview' and person.properties.email = 'jimmy@posthog.com'" ) expected = _expr("properties.email = 'jimmy@posthog.com'") - assert expected in actual.exprs + assert actual == expected def test_person_properties_andor_9(self): actual = self.get_clause( @@ -146,21 +148,21 @@ def test_person_properties_andor_11(self): "SELECT * FROM events WHERE properties.email = 'bla@posthog.com' and person.properties.email = 'jimmy@posthog.com'" ) expected = _expr("properties.email = 'jimmy@posthog.com'") - assert expected in actual.exprs + assert actual == expected def test_person_properties_function_calls(self): actual = self.get_clause( "SELECT * FROM events WHERE properties.email = 'bla@posthog.com' and toString(person.properties.email) = 'jimmy@posthog.com'" ) expected = _expr("toString(properties.email) = 'jimmy@posthog.com'") - assert expected in actual.exprs + assert actual == expected def test_person_properties_function_call_args(self): actual = self.get_clause( "SELECT * FROM events WHERE properties.email = 'bla@posthog.com' and substring(person.properties.email, 10) = 'jimmy@posthog.com'" ) expected = _expr("substring(properties.email, 10) = 'jimmy@posthog.com'") - assert expected in actual.exprs + assert actual == expected def test_person_properties_function_call_args_complex(self): actual = self.get_clause( @@ -177,12 +179,6 @@ def test_boolean(self): ) actual = self.print_query("SELECT * FROM events WHERE person.properties.person_boolean = false") assert ( - f"ifNull(equals(transform(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties" + f"FROM person WHERE and(equals(person.team_id, {self.team.id}), ifNull(equals(transform(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties" in actual ) - - def test_id_in(self): - actual = self.get_clause( - "SELECT * FROM events WHERE in(person.id, (SELECT person_id FROM (SELECT argMax(raw_person_distinct_ids.person_id, raw_person_distinct_ids.version) AS person_id, raw_person_distinct_ids.distinct_id AS distinct_id FROM raw_person_distinct_ids GROUP BY raw_person_distinct_ids.distinct_id HAVING equals(argMax(raw_person_distinct_ids.is_deleted, raw_person_distinct_ids.version), 0)) AS person_distinct_ids WHERE ilike(distinct_id, '%test%')))" - ) - assert actual is None diff --git a/posthog/hogql/database/schema/util/where_clause_extractor.py b/posthog/hogql/database/schema/util/where_clause_extractor.py index d18497fb44bda..9ed7be296f483 100644 --- a/posthog/hogql/database/schema/util/where_clause_extractor.py +++ b/posthog/hogql/database/schema/util/where_clause_extractor.py @@ -6,8 +6,7 @@ from posthog.hogql.ast import CompareOperationOp, ArithmeticOperationOp from posthog.hogql.context import HogQLContext from posthog.hogql.database.models import DatabaseField, LazyJoinToAdd, LazyTableToAdd -from posthog.hogql.errors import NotImplementedError, QueryError -from posthog.hogql.functions.mapping import HOGQL_COMPARISON_MAPPING +from posthog.hogql.errors import NotImplementedError from posthog.hogql.visitor import clone_expr, CloningVisitor, Visitor, TraversingVisitor @@ -44,15 +43,13 @@ class WhereClauseExtractor(CloningVisitor): clear_types: bool = False clear_locations: bool = False capture_timestamp_comparisons: bool = False # implement handle_timestamp_comparison if setting this to True - is_join: bool = False tracked_tables: list[ast.LazyTable | ast.LazyJoin] tombstone_string: str - def __init__(self, context: HogQLContext, is_join: Optional[bool] = False): + def __init__(self, context: HogQLContext): super().__init__() self.context = context self.tracked_tables = [] - self.is_join = is_join or False # A constant with this string will be used to escape early if we can't handle the query self.tombstone_string = ( "__TOMBSTONE__" + ("".join(random.choices(string.ascii_uppercase + string.digits, k=10))) + "__" @@ -113,18 +110,10 @@ def visit_compare_operation(self, node: ast.CompareOperation) -> ast.Expr: if result: return result - # if the comparison is negative and it's a join, we don't want to filter down as the outer query needs to be able to filter down results - if self.is_join and node.op in ast.NEGATED_COMPARE_OPS: - return ast.Constant(value=True) - # Check if any of the fields are a field on our requested table if len(self.tracked_tables) > 0: left = self.visit(node.left) right = self.visit(node.right) - - # Too complicated - if isinstance(node.right, ast.SelectQuery): - return ast.Constant(value=True) if has_tombstone(left, self.tombstone_string) or has_tombstone(right, self.tombstone_string): return ast.Constant(value=self.tombstone_string) return ast.CompareOperation(op=node.op, left=left, right=right) @@ -140,8 +129,6 @@ def visit_arithmetic_operation(self, node: ast.ArithmeticOperation) -> ast.Expr: return ast.Constant(value=True) def visit_not(self, node: ast.Not) -> ast.Expr: - if self.is_join: - return ast.Constant(value=True) response = self.visit(node.expr) if has_tombstone(response, self.tombstone_string): return ast.Constant(value=self.tombstone_string) @@ -152,25 +139,43 @@ def visit_call(self, node: ast.Call) -> ast.Expr: return self.visit_and(ast.And(exprs=node.args)) elif node.name == "or": return self.visit_or(ast.Or(exprs=node.args)) - elif node.name == "not": - if self.is_join: - return ast.Constant(value=True) - - elif node.name in HOGQL_COMPARISON_MAPPING: - op = HOGQL_COMPARISON_MAPPING[node.name] - if len(node.args) != 2: - raise QueryError(f"Comparison '{node.name}' requires exactly two arguments") - # We do "cleverer" logic with nullable types in visit_compare_operation + elif node.name == "greaterOrEquals": return self.visit_compare_operation( - ast.CompareOperation( - left=node.args[0], - right=node.args[1], - op=op, - ) + ast.CompareOperation(op=CompareOperationOp.GtEq, left=node.args[0], right=node.args[1]) + ) + elif node.name == "greater": + return self.visit_compare_operation( + ast.CompareOperation(op=CompareOperationOp.Gt, left=node.args[0], right=node.args[1]) + ) + elif node.name == "lessOrEquals": + return self.visit_compare_operation( + ast.CompareOperation(op=CompareOperationOp.LtEq, left=node.args[0], right=node.args[1]) + ) + elif node.name == "less": + return self.visit_compare_operation( + ast.CompareOperation(op=CompareOperationOp.Lt, left=node.args[0], right=node.args[1]) + ) + elif node.name == "equals": + return self.visit_compare_operation( + ast.CompareOperation(op=CompareOperationOp.Eq, left=node.args[0], right=node.args[1]) + ) + elif node.name == "like": + return self.visit_compare_operation( + ast.CompareOperation(op=CompareOperationOp.Like, left=node.args[0], right=node.args[1]) + ) + elif node.name == "notLike": + return self.visit_compare_operation( + ast.CompareOperation(op=CompareOperationOp.NotLike, left=node.args[0], right=node.args[1]) + ) + elif node.name == "ilike": + return self.visit_compare_operation( + ast.CompareOperation(op=CompareOperationOp.ILike, left=node.args[0], right=node.args[1]) + ) + elif node.name == "notIlike": + return self.visit_compare_operation( + ast.CompareOperation(op=CompareOperationOp.NotILike, left=node.args[0], right=node.args[1]) ) - args = [self.visit(arg) for arg in node.args] - if any(has_tombstone(arg, self.tombstone_string) for arg in args): return ast.Constant(value=self.tombstone_string) return ast.Call(name=node.name, args=args) diff --git a/posthog/hogql/modifiers.py b/posthog/hogql/modifiers.py index 710a3b3b5befb..42cb7f2f04433 100644 --- a/posthog/hogql/modifiers.py +++ b/posthog/hogql/modifiers.py @@ -7,6 +7,7 @@ HogQLQueryModifiers, InCohortVia, MaterializationMode, + PersonsArgMaxVersion, BounceRatePageViewMode, PropertyGroupsMode, SessionTableVersion, @@ -60,12 +61,18 @@ def set_default_modifier_values(modifiers: HogQLQueryModifiers, team: "Team"): if modifiers.personsOnEventsMode is None: modifiers.personsOnEventsMode = team.person_on_events_mode_flag_based_default + if modifiers.personsArgMaxVersion is None: + modifiers.personsArgMaxVersion = PersonsArgMaxVersion.AUTO + if modifiers.inCohortVia is None: modifiers.inCohortVia = InCohortVia.AUTO if modifiers.materializationMode is None or modifiers.materializationMode == MaterializationMode.AUTO: modifiers.materializationMode = MaterializationMode.LEGACY_NULL_AS_NULL + if modifiers.optimizeJoinedFilters is None: + modifiers.optimizeJoinedFilters = False + if modifiers.bounceRatePageViewMode is None: modifiers.bounceRatePageViewMode = BounceRatePageViewMode.COUNT_PAGEVIEWS diff --git a/posthog/hogql/query.py b/posthog/hogql/query.py index a979444f8c919..2516d8007d815 100644 --- a/posthog/hogql/query.py +++ b/posthog/hogql/query.py @@ -200,10 +200,6 @@ def execute_hogql_query( modifiers={k: v for k, v in modifiers.model_dump().items() if v is not None} if modifiers else {}, ) - # Uncomment to print clickhouse SQL - # from posthog.clickhouse.client.escape import substitute_params - # print(substitute_params(clickhouse_sql, clickhouse_context.values)) - try: results, types = sync_execute( clickhouse_sql, diff --git a/posthog/hogql/test/__snapshots__/test_query.ambr b/posthog/hogql/test/__snapshots__/test_query.ambr index e2b279007f210..96bfad37a5a50 100644 --- a/posthog/hogql/test/__snapshots__/test_query.ambr +++ b/posthog/hogql/test/__snapshots__/test_query.ambr @@ -459,19 +459,16 @@ SELECT DISTINCT persons.properties___sneaky_mail AS sneaky_mail FROM ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___sneaky_mail, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___random_uuid + SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', '') AS properties___random_uuid FROM person - WHERE and(equals(person.team_id, 420), in(person.id, ( - SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 420), notIn(person.id, ( - SELECT person.id AS id + WHERE and(equals(person.team_id, 420), ifNull(in(tuple(person.id, person.version), ( + SELECT person.id AS id, max(person.version) AS version FROM person - WHERE and(equals(person.team_id, 420), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_2)s), ''), 'null'), '^"|"$', ''), %(hogql_val_3)s), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_4)s), ''), 'null'), '^"|"$', ''), %(hogql_val_5)s), 0)) + WHERE equals(person.team_id, 420) GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_6)s), person.version), plus(now64(6, %(hogql_val_7)s), toIntervalDay(1))), 0)) + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_2)s), person.version), plus(now64(6, %(hogql_val_3)s), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons - WHERE ifNull(equals(persons.properties___random_uuid, %(hogql_val_8)s), 0) + WHERE ifNull(equals(persons.properties___random_uuid, %(hogql_val_4)s), 0) LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, format_csv_allow_double_quotes=0, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0 @@ -541,11 +538,14 @@ GROUP BY person_distinct_id2.distinct_id HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__pdi ON equals(e.distinct_id, e__pdi.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___sneaky_mail + SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail + FROM person + WHERE and(equals(person.team_id, 420), ifNull(in(tuple(person.id, person.version), ( + SELECT person.id AS id, max(person.version) AS version FROM person WHERE equals(person.team_id, 420) GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)) + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__pdi__person ON equals(e__pdi.e__pdi___person_id, e__pdi__person.id) WHERE equals(e.team_id, 420) LIMIT 10 @@ -599,11 +599,14 @@ GROUP BY person_distinct_id2.distinct_id HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___sneaky_mail + SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail + FROM person + WHERE and(equals(person.team_id, 420), ifNull(in(tuple(person.id, person.version), ( + SELECT person.id AS id, max(person.version) AS version FROM person WHERE equals(person.team_id, 420) GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)) + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__pdi__person ON equals(events__pdi.events__pdi___person_id, events__pdi__person.id) WHERE equals(events.team_id, 420) LIMIT 10 @@ -628,11 +631,14 @@ GROUP BY person_distinct_id2.distinct_id HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__pdi ON equals(e.distinct_id, e__pdi.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___sneaky_mail + SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail + FROM person + WHERE and(equals(person.team_id, 420), ifNull(in(tuple(person.id, person.version), ( + SELECT person.id AS id, max(person.version) AS version FROM person WHERE equals(person.team_id, 420) GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)) + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__pdi__person ON equals(e__pdi.e__pdi___person_id, e__pdi__person.id) WHERE equals(e.team_id, 420) LIMIT 10 @@ -657,11 +663,14 @@ GROUP BY person_distinct_id2.distinct_id HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS s__pdi ON equals(s.distinct_id, s__pdi.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___sneaky_mail + SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail + FROM person + WHERE and(equals(person.team_id, 420), ifNull(in(tuple(person.id, person.version), ( + SELECT person.id AS id, max(person.version) AS version FROM person WHERE equals(person.team_id, 420) GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)) + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS s__pdi__person ON equals(s__pdi.s__pdi___person_id, s__pdi__person.id) WHERE equals(s.team_id, 420) GROUP BY s__pdi__person.properties___sneaky_mail @@ -714,11 +723,14 @@ GROUP BY person_distinct_id2.distinct_id HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS pdi LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___sneaky_mail + SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail + FROM person + WHERE and(equals(person.team_id, 420), ifNull(in(tuple(person.id, person.version), ( + SELECT person.id AS id, max(person.version) AS version FROM person WHERE equals(person.team_id, 420) GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)) + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS pdi__person ON equals(pdi.pdi___person_id, pdi__person.id) LIMIT 10 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, format_csv_allow_double_quotes=0, max_ast_elements=4000000, max_expanded_ast_elements=4000000, max_bytes_before_external_group_by=0 @@ -742,7 +754,7 @@ GROUP BY person_distinct_id2.distinct_id HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS pdi LEFT JOIN ( - SELECT person.id AS id, argMax(toTimeZone(person.created_at, %(hogql_val_0)s), person.version) AS created_at + SELECT argMax(toTimeZone(person.created_at, %(hogql_val_0)s), person.version) AS created_at, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id @@ -770,11 +782,14 @@ GROUP BY person_distinct_id2.distinct_id HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS pdi ON equals(pdi.distinct_id, e.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___sneaky_mail + SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail + FROM person + WHERE and(equals(person.team_id, 420), ifNull(in(tuple(person.id, person.version), ( + SELECT person.id AS id, max(person.version) AS version FROM person WHERE equals(person.team_id, 420) GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)) + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS p ON equals(p.id, pdi.person_id) WHERE equals(e.team_id, 420) LIMIT 100 @@ -821,11 +836,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___sneaky_mail + SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___sneaky_mail + FROM person + WHERE and(equals(person.team_id, 420), ifNull(in(tuple(person.id, person.version), ( + SELECT person.id AS id, max(person.version) AS version FROM person WHERE equals(person.team_id, 420) GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)) + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_1)s), person.version), plus(now64(6, %(hogql_val_2)s), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE equals(events.team_id, 420) LIMIT 10 diff --git a/posthog/hogql/test/test_modifiers.py b/posthog/hogql/test/test_modifiers.py index 83c0e72572b11..5c4f235d49080 100644 --- a/posthog/hogql/test/test_modifiers.py +++ b/posthog/hogql/test/test_modifiers.py @@ -5,6 +5,7 @@ from posthog.models import Cohort from posthog.schema import ( HogQLQueryModifiers, + PersonsArgMaxVersion, PersonsOnEventsMode, MaterializationMode, ) @@ -154,6 +155,50 @@ class TestCase(NamedTuple): for value in test_case.other_expected_values: assert value in clickhouse_query + def test_modifiers_persons_argmax_version_v2(self): + query = "SELECT * FROM persons" + + # Control (v1) + response = execute_hogql_query( + query, + team=self.team, + modifiers=HogQLQueryModifiers(personsArgMaxVersion=PersonsArgMaxVersion.V1), + ) + assert "in(tuple(person.id, person.version)" not in response.clickhouse + + # Test (v2) + response = execute_hogql_query( + query, + team=self.team, + modifiers=HogQLQueryModifiers(personsArgMaxVersion=PersonsArgMaxVersion.V2), + ) + assert "in(tuple(person.id, person.version)" in response.clickhouse + + def test_modifiers_persons_argmax_version_auto(self): + # Use the v2 query when selecting properties.x + response = execute_hogql_query( + "SELECT id, properties.$browser, is_identified FROM persons", + team=self.team, + modifiers=HogQLQueryModifiers(personsArgMaxVersion=PersonsArgMaxVersion.AUTO), + ) + assert "in(tuple(person.id, person.version)" in response.clickhouse + + # Use the v2 query when selecting properties + response = execute_hogql_query( + "SELECT id, properties FROM persons", + team=self.team, + modifiers=HogQLQueryModifiers(personsArgMaxVersion=PersonsArgMaxVersion.AUTO), + ) + assert "in(tuple(person.id, person.version)" in response.clickhouse + + # Use the v1 query when not selecting any properties + response = execute_hogql_query( + "SELECT id, is_identified FROM persons", + team=self.team, + modifiers=HogQLQueryModifiers(personsArgMaxVersion=PersonsArgMaxVersion.AUTO), + ) + assert "in(tuple(person.id, person.version)" not in response.clickhouse + def test_modifiers_in_cohort_join(self): cohort = Cohort.objects.create(team=self.team, name="test") response = execute_hogql_query( @@ -218,3 +263,26 @@ def test_modifiers_materialization_mode(self): "SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^\"|\"$', '') AS `$browser` FROM events" in response.clickhouse ) + + def test_optimize_joined_filters(self): + # no optimizations + response = execute_hogql_query( + f"select event from events where person.properties.$browser ilike '%Chrome%'", + team=self.team, + modifiers=HogQLQueryModifiers(optimizeJoinedFilters=False), + ) + # "ilike" shows up once in the response + assert response is not None + assert response.clickhouse is not None + assert response.clickhouse.count("ilike") == 1 + + # with optimizations + response = execute_hogql_query( + f"select event from events where person.properties.$browser ilike '%Chrome%'", + team=self.team, + modifiers=HogQLQueryModifiers(optimizeJoinedFilters=True), + ) + # "ilike" shows up twice in the response + assert response is not None + assert response.clickhouse is not None + assert response.clickhouse.count("ilike") == 2 diff --git a/posthog/hogql/test/test_printer.py b/posthog/hogql/test/test_printer.py index 4eb13c3ef64e4..021dee3bcf947 100644 --- a/posthog/hogql/test/test_printer.py +++ b/posthog/hogql/test/test_printer.py @@ -20,6 +20,7 @@ from posthog.schema import ( HogQLQueryModifiers, MaterializationMode, + PersonsArgMaxVersion, PersonsOnEventsMode, PropertyGroupsMode, ) @@ -1106,24 +1107,94 @@ def test_select_sample(self): context = HogQLContext( team_id=self.team.pk, enable_select_queries=True, + modifiers=HogQLQueryModifiers(personsArgMaxVersion=PersonsArgMaxVersion.V2), ) query = self._select( "SELECT events.event FROM events SAMPLE 2/78 OFFSET 999 JOIN persons ON persons.id=events.person_id", context, ) - self.assertIn("FROM events SAMPLE 2/78 OFFSET 999", query) + self.assertEqual( + query, + f"SELECT events.event AS event FROM events SAMPLE 2/78 OFFSET 999 LEFT OUTER JOIN (SELECT " + "argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, " + "person_distinct_id_overrides.distinct_id AS distinct_id FROM person_distinct_id_overrides WHERE " + f"equals(person_distinct_id_overrides.team_id, {self.team.pk}) GROUP BY person_distinct_id_overrides.distinct_id " + "HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) " + "SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) " + f"JOIN (SELECT person.id AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), " + "ifNull(in(tuple(person.id, person.version), (SELECT person.id AS id, max(person.version) AS version " + f"FROM person WHERE equals(person.team_id, {self.team.pk}) GROUP BY person.id " + "HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), " + "ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_0)s), person.version), " + "plus(now64(6, %(hogql_val_1)s), toIntervalDay(1))), 0)))), 0)) " + "SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, if(not(empty(events__override.distinct_id)), " + f"events__override.person_id, events.person_id)) WHERE equals(events.team_id, {self.team.pk}) LIMIT {MAX_SELECT_RETURNED_ROWS}", + ) context = HogQLContext( team_id=self.team.pk, enable_select_queries=True, + modifiers=HogQLQueryModifiers(personsArgMaxVersion=PersonsArgMaxVersion.V2), ) - query = self._select( - "SELECT events.event FROM events SAMPLE 2/78 OFFSET 999 JOIN persons SAMPLE 0.1 ON persons.id=events.person_id", + self.assertEqual( + self._select( + "SELECT events.event FROM events SAMPLE 2/78 OFFSET 999 JOIN persons SAMPLE 0.1 ON persons.id=events.person_id", + context, + ), + f"SELECT events.event AS event FROM events SAMPLE 2/78 OFFSET 999 LEFT OUTER JOIN (SELECT " + "argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, " + "person_distinct_id_overrides.distinct_id AS distinct_id FROM person_distinct_id_overrides WHERE " + f"equals(person_distinct_id_overrides.team_id, {self.team.pk}) GROUP BY person_distinct_id_overrides.distinct_id " + "HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) " + "SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) " + f"JOIN (SELECT person.id AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), " + "ifNull(in(tuple(person.id, person.version), (SELECT person.id AS id, max(person.version) AS version " + f"FROM person WHERE equals(person.team_id, {self.team.pk}) GROUP BY person.id " + "HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), " + "ifNull(less(argMax(toTimeZone(person.created_at, %(hogql_val_0)s), person.version), " + "plus(now64(6, %(hogql_val_1)s), toIntervalDay(1))), 0)))), 0)) " + "SETTINGS optimize_aggregation_in_order=1) AS persons SAMPLE 0.1 ON equals(persons.id, if(not(empty(events__override.distinct_id)), " + f"events__override.person_id, events.person_id)) WHERE equals(events.team_id, {self.team.pk}) LIMIT {MAX_SELECT_RETURNED_ROWS}", + ) + + with override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=False): + context = HogQLContext( + team_id=self.team.pk, + enable_select_queries=True, + modifiers=HogQLQueryModifiers(personsArgMaxVersion=PersonsArgMaxVersion.V2), + ) + expected = self._select( + "SELECT events.event FROM events SAMPLE 2/78 OFFSET 999 JOIN persons ON persons.id=events.person_id", context, ) + self.assertEqual( + expected, + f"SELECT events.event AS event FROM events SAMPLE 2/78 OFFSET 999 JOIN (SELECT person.id AS id FROM person WHERE " + f"and(equals(person.team_id, {self.team.pk}), ifNull(in(tuple(person.id, person.version), (SELECT person.id AS id, " + f"max(person.version) AS version FROM person WHERE equals(person.team_id, {self.team.pk}) GROUP BY person.id " + f"HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, " + f"%(hogql_val_0)s), person.version), plus(now64(6, %(hogql_val_1)s), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) " + f"AS persons ON equals(persons.id, events.person_id) WHERE equals(events.team_id, {self.team.pk}) LIMIT {MAX_SELECT_RETURNED_ROWS}", + ) - self.assertIn("FROM events SAMPLE 2/78 OFFSET 999", query) - self.assertIn("AS persons SAMPLE 0.1 ON", query) + context = HogQLContext( + team_id=self.team.pk, + enable_select_queries=True, + modifiers=HogQLQueryModifiers(personsArgMaxVersion=PersonsArgMaxVersion.V2), + ) + expected = self._select( + "SELECT events.event FROM events SAMPLE 2/78 OFFSET 999 JOIN persons SAMPLE 0.1 ON persons.id=events.person_id", + context, + ) + self.assertEqual( + expected, + f"SELECT events.event AS event FROM events SAMPLE 2/78 OFFSET 999 JOIN (SELECT person.id AS id FROM person WHERE " + f"and(equals(person.team_id, {self.team.pk}), ifNull(in(tuple(person.id, person.version), (SELECT person.id AS id, " + f"max(person.version) AS version FROM person WHERE equals(person.team_id, {self.team.pk}) GROUP BY person.id " + f"HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, " + f"%(hogql_val_0)s), person.version), plus(now64(6, %(hogql_val_1)s), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) " + f"AS persons SAMPLE 0.1 ON equals(persons.id, events.person_id) WHERE equals(events.team_id, {self.team.pk}) LIMIT {MAX_SELECT_RETURNED_ROWS}", + ) def test_count_distinct(self): self.assertEqual( @@ -1895,10 +1966,7 @@ def test_inline_persons(self): dialect="clickhouse", settings=HogQLGlobalSettings(max_execution_time=10), ) - assert ( - f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(person.id, tuple(1, 2, 3)))" - in printed - ) + assert f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(id, tuple(1, 2, 3)))" in printed def test_dont_inline_persons(self): query = parse_select( @@ -1925,10 +1993,7 @@ def test_inline_persons_alias(self): dialect="clickhouse", settings=HogQLGlobalSettings(max_execution_time=10), ) - assert ( - f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(person.id, tuple(1, 2, 3)))" - in printed - ) + assert f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(id, tuple(1, 2, 3)))" in printed def test_two_joins(self): query = parse_select( @@ -1944,14 +2009,8 @@ def test_two_joins(self): dialect="clickhouse", settings=HogQLGlobalSettings(max_execution_time=10), ) - assert ( - f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(person.id, tuple(1, 2, 3)))" - in printed - ) - assert ( - f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(person.id, tuple(4, 5, 6)))" - in printed - ) + assert f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(id, tuple(1, 2, 3)))" in printed + assert f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(id, tuple(4, 5, 6)))" in printed def test_two_clauses(self): query = parse_select( @@ -1968,10 +2027,7 @@ def test_two_clauses(self): settings=HogQLGlobalSettings(max_execution_time=10), ) assert ( - f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(person.id, tuple(7, 8, 9)), in(person.id, tuple(1, 2, 3)))" - in printed - ) - assert ( - f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(person.id, tuple(4, 5, 6)))" + f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(id, tuple(7, 8, 9)), in(id, tuple(1, 2, 3)))" in printed ) + assert f"AS id FROM person WHERE and(equals(person.team_id, {self.team.pk}), in(id, tuple(4, 5, 6)))" in printed diff --git a/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr b/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr index eaf024ade223b..a447055b84d04 100644 --- a/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr +++ b/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr @@ -23,7 +23,7 @@ SELECT persons__events.event AS event FROM ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS persons___properties___email + SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS persons___properties___email, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id @@ -45,7 +45,7 @@ WHERE and(equals(cohortpeople.team_id, 420), 0)) AS cohort_people LEFT JOIN ( SELECT persons.id AS id, persons.properties___email AS cohort_people__new_person___properties___email FROM ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id @@ -59,7 +59,7 @@ SELECT persons.id AS id, persons.properties___email AS email, persons.`properties___$browser` AS `$browser` FROM ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser`, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id @@ -79,7 +79,7 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id @@ -100,7 +100,7 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(person.properties, person.version) AS properties + SELECT argMax(person.properties, person.version) AS properties, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id @@ -157,7 +157,7 @@ GROUP BY person_distinct_id2.distinct_id HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS person_distinct_ids LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser`, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id @@ -177,7 +177,7 @@ GROUP BY person_distinct_id2.distinct_id HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS person_distinct_ids LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s, %(hogql_val_1)s, %(hogql_val_2)s), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser___in___json` + SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s, %(hogql_val_1)s, %(hogql_val_2)s), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser___in___json`, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id @@ -233,7 +233,7 @@ GROUP BY person_distinct_id2.distinct_id HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser`, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id @@ -254,7 +254,7 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___name, argMax(person.properties, person.version) AS properties + SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___name, argMax(person.properties, person.version) AS properties, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id diff --git a/posthog/hogql/transforms/test/__snapshots__/test_property_types.ambr b/posthog/hogql/transforms/test/__snapshots__/test_property_types.ambr index 1f89a22c1d04a..c0c2e1a610370 100644 --- a/posthog/hogql/transforms/test/__snapshots__/test_property_types.ambr +++ b/posthog/hogql/transforms/test/__snapshots__/test_property_types.ambr @@ -4,7 +4,7 @@ SELECT persons__extended_properties.string_prop AS string_prop, persons__extended_properties.int_prop AS int_prop, transform(toString(persons__extended_properties.bool_prop), %(hogql_val_8)s, %(hogql_val_9)s, NULL) AS bool_prop FROM ( - SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS persons___properties___email + SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS persons___properties___email, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id @@ -53,7 +53,7 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s), person.version) AS properties___tickets + SELECT argMax(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s), person.version) AS properties___tickets, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id @@ -83,7 +83,7 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN ( - SELECT person.id AS id, argMax(parseDateTime64BestEffortOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), 6, %(hogql_val_1)s), person.version) AS properties___provided_timestamp + SELECT argMax(parseDateTime64BestEffortOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), 6, %(hogql_val_1)s), person.version) AS properties___provided_timestamp, person.id AS id FROM person WHERE equals(person.team_id, 420) GROUP BY person.id diff --git a/posthog/hogql_queries/ai/test/__snapshots__/test_actors_property_taxonomy_query_runner.ambr b/posthog/hogql_queries/ai/test/__snapshots__/test_actors_property_taxonomy_query_runner.ambr index 11f10398b6ae2..a0724393e1fe3 100644 --- a/posthog/hogql_queries/ai/test/__snapshots__/test_actors_property_taxonomy_query_runner.ambr +++ b/posthog/hogql_queries/ai/test/__snapshots__/test_actors_property_taxonomy_query_runner.ambr @@ -81,12 +81,15 @@ (SELECT DISTINCT persons.properties___email AS prop FROM (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, + toTimeZone(person.created_at, 'UTC') AS created_at FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons WHERE isNotNull(prop) ORDER BY persons.created_at DESC) LIMIT 100 SETTINGS readonly=2, @@ -105,12 +108,15 @@ (SELECT DISTINCT persons.`properties___does not exist` AS prop FROM (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'does not exist'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___does not exist`, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'does not exist'), ''), 'null'), '^"|"$', '') AS `properties___does not exist`, + toTimeZone(person.created_at, 'UTC') AS created_at FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons WHERE isNotNull(prop) ORDER BY persons.created_at DESC) LIMIT 100 SETTINGS readonly=2, @@ -129,12 +135,15 @@ (SELECT DISTINCT persons.properties___age AS prop FROM (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), person.version) AS properties___age, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age, + toTimeZone(person.created_at, 'UTC') AS created_at FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons WHERE isNotNull(prop) ORDER BY persons.created_at DESC) LIMIT 100 SETTINGS readonly=2, diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr index 546c9edd4fd68..8c5b1b85d1b2e 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr @@ -185,8 +185,8 @@ WHERE ifNull(in(steps, [2, 3]), 0) ORDER BY aggregation_target ASC) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id @@ -479,18 +479,15 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), person.version) AS properties___age + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0))))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-07-01 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(e__person.properties___email, '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(e__person.properties___email, '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0))))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -589,18 +586,15 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), person.version) AS properties___age + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0))))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-07-01 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(e__person.properties___email, '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(e__person.properties___email, '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0))))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -610,8 +604,8 @@ WHERE ifNull(in(steps, [1, 2, 3]), 0) ORDER BY aggregation_target ASC) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id @@ -710,18 +704,15 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), person.version) AS properties___age + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0))))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-07-01 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(e__person.properties___email, '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(e__person.properties___email, '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0))))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -731,8 +722,8 @@ WHERE ifNull(in(steps, [2, 3]), 0) ORDER BY aggregation_target ASC) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id @@ -831,18 +822,15 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), person.version) AS properties___age + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0))))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-07-01 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(e__person.properties___email, '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(e__person.properties___email, '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0))))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -852,8 +840,8 @@ WHERE ifNull(in(steps, [3]), 0) ORDER BY aggregation_target ASC) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr index f5652ab2d049d..be8b077d2fca2 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr @@ -228,11 +228,14 @@ persons.properties AS person_props FROM (SELECT person.id AS id, - argMax(person.properties, person.version) AS properties + person.properties AS properties FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons) AS persons ON equals(persons.id, funnel_actors.actor_id)) AS aggregation_target_with_props + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons) AS persons ON equals(persons.id, funnel_actors.actor_id)) AS aggregation_target_with_props GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2 HAVING ifNull(notIn((aggregation_target_with_props.prop).1, []), 0) LIMIT 100 @@ -407,17 +410,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -432,7 +432,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -460,17 +460,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, steps @@ -604,17 +601,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -629,7 +623,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -657,17 +651,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, steps @@ -801,17 +792,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -826,7 +814,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -854,17 +842,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, steps @@ -998,17 +983,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -1023,7 +1005,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -1051,17 +1033,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, steps @@ -1175,11 +1154,14 @@ persons.properties AS person_props FROM (SELECT person.id AS id, - argMax(person.properties, person.version) AS properties + person.properties AS properties FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons) AS persons ON equals(persons.id, funnel_actors.actor_id)) AS aggregation_target_with_props + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons) AS persons ON equals(persons.id, funnel_actors.actor_id)) AS aggregation_target_with_props GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2 HAVING ifNull(notIn((aggregation_target_with_props.prop).1, []), 0) LIMIT 100 @@ -1354,17 +1336,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -1379,7 +1358,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -1407,17 +1386,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + (SELECT person.id AS id, nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, steps @@ -1551,17 +1527,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -1576,7 +1549,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -1604,17 +1577,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + (SELECT person.id AS id, nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, steps @@ -1748,17 +1718,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -1773,7 +1740,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -1801,17 +1768,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + (SELECT person.id AS id, nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, steps @@ -1945,17 +1909,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -1970,7 +1931,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -1998,17 +1959,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + (SELECT person.id AS id, nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, steps diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr index 03308491d73db..46d4cbd700ebb 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors.ambr @@ -115,7 +115,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -368,7 +368,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -547,17 +547,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), person.version) AS properties___foo + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-08 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'insight analyzed')), ifNull(equals(e__person.properties___foo, 'bar'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -572,7 +569,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -600,17 +597,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), person.version) AS properties___foo + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-08 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'insight analyzed')), ifNull(equals(e__person.properties___foo, 'bar'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0))))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, steps @@ -745,17 +739,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), person.version) AS properties___foo + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-08 23:59:59.999999', 6, 'UTC'))), ifNull(equals(e__person.properties___foo, 'bar'), 0)))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -770,7 +761,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -798,17 +789,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), person.version) AS properties___foo + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-08 23:59:59.999999', 6, 'UTC'))), ifNull(equals(e__person.properties___foo, 'bar'), 0)))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, steps @@ -942,17 +930,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), person.version) AS properties___foo + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-08 23:59:59.999999', 6, 'UTC'))), ifNull(equals(e__person.properties___foo, 'bar'), 0)))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, @@ -967,7 +952,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -995,17 +980,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), person.version) AS properties___foo + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-08 23:59:59.999999', 6, 'UTC'))), ifNull(equals(e__person.properties___foo, 'bar'), 0)))) WHERE ifNull(equals(step_0, 1), 0))) GROUP BY aggregation_target, steps diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors_udf.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors_udf.ambr index ab0cfd71fd183..3a16355324cb4 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors_udf.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_actors_udf.ambr @@ -67,7 +67,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -199,7 +199,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -313,17 +313,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), person.version) AS properties___foo + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-08 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'insight analyzed')), ifNull(equals(e__person.properties___foo, 'bar'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -335,7 +332,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -357,17 +354,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), person.version) AS properties___foo + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', ''), 'bar'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-08 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'insight analyzed')), ifNull(equals(e__person.properties___foo, 'bar'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -403,3 +397,205 @@ max_bytes_before_external_group_by=0 ''' # --- +# name: TestFunnelCorrelationsActorsUDF.test_strict_funnel_correlation_with_recordings + ''' + SELECT sum(step_1) AS step_1, + sum(step_2) AS step_2, + arrayMap(x -> if(isNaN(x), NULL, x), [avgArrayOrNull(step_1_conversion_times)])[1] AS step_1_average_conversion_time, + arrayMap(x -> if(isNaN(x), NULL, x), [medianArrayOrNull(step_1_conversion_times)])[1] AS step_1_median_conversion_time, + groupArray(row_number) AS row_number, + final_prop AS final_prop + FROM + (SELECT countIf(ifNull(ifNull(equals(step_reached, 0), 0), 0)) AS step_1, + countIf(ifNull(ifNull(equals(step_reached, 1), 0), 0)) AS step_2, + groupArrayIf(timings[1], ifNull(greater(timings[1], 0), 0)) AS step_1_conversion_times, + rowNumberInBlock() AS row_number, + breakdown AS final_prop + FROM + (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, [], arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, + arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'strict', [[]], arrayFilter((x, x2) -> not(and(empty(x.4), empty(x2.4), ifNull(equals(x.3, x2.3), isNull(x.3) + and isNull(x2.3)), ifNull(greater(x.1, x2.1), 0))), events_array, arrayRotateRight(events_array, 1)))) AS af_tuple, + af_tuple.1 AS step_reached, + plus(af_tuple.1, 1) AS steps, + af_tuple.2 AS breakdown, + af_tuple.3 AS timings, + aggregation_target AS aggregation_target + FROM + (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, + if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target, + e.uuid AS uuid, + e.`$session_id` AS `$session_id`, + e.`$window_id` AS `$window_id`, + if(equals(e.event, '$pageview'), 1, 0) AS step_0, + if(equals(e.event, 'insight analyzed'), 1, 0) AS step_1 + FROM events AS e + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, + person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 2) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) + WHERE and(equals(e.team_id, 2), and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-08 23:59:59.999999', 6, 'UTC'))))) + GROUP BY aggregation_target + HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) + GROUP BY breakdown + ORDER BY step_2 DESC, step_1 DESC) + GROUP BY final_prop + LIMIT 100 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=23622320128, + allow_experimental_analyzer=1 + ''' +# --- +# name: TestFunnelCorrelationsActorsUDF.test_strict_funnel_correlation_with_recordings.1 + ''' + SELECT DISTINCT session_replay_events.session_id AS session_id + FROM session_replay_events + WHERE and(equals(session_replay_events.team_id, 2), ifNull(greaterOrEquals(toTimeZone(session_replay_events.min_first_timestamp, 'UTC'), minus(toDateTime64('2021-01-02 00:00:00.000000', 6, 'UTC'), toIntervalDay(21))), 0), in(session_replay_events.session_id, ['s2'])) + LIMIT 100 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 + ''' +# --- +# name: TestFunnelCorrelationsActorsUDF.test_strict_funnel_correlation_with_recordings.2 + ''' + SELECT persons.id, + persons.id AS id, + source.matching_events AS matching_events + FROM + (SELECT funnel_actors.actor_id AS actor_id, + any(funnel_actors.matching_events) AS matching_events + FROM + (SELECT aggregation_target AS actor_id, + matched_events_array[plus(step_reached, 1)] AS matching_events, + (matched_events_array[1][1]).1 AS timestamp, + nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, + (matched_events_array[1][1]).1 AS first_timestamp, + steps AS steps, + final_timestamp, + first_timestamp + FROM + (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, [], arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, + arrayJoin(aggregate_funnel_array_v1(2, 1209600, 'first_touch', 'strict', [[]], arrayFilter((x, x2) -> not(and(empty(x.4), empty(x2.4), ifNull(equals(x.3, x2.3), isNull(x.3) + and isNull(x2.3)), ifNull(greater(x.1, x2.1), 0))), events_array, arrayRotateRight(events_array, 1)))) AS af_tuple, + arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'strict', [[]], arrayFilter((x, x2) -> not(and(empty(x.4), empty(x2.4), ifNull(equals(x.3, x2.3), isNull(x.3) + and isNull(x2.3)), ifNull(greater(x.1, x2.1), 0))), events_array, arrayRotateRight(events_array, 1)))) AS af_tuple, + af_tuple.1 AS step_reached, + plus(af_tuple.1, 1) AS steps, + af_tuple.2 AS breakdown, + af_tuple.3 AS timings, + af_tuple.4 AS matched_event_uuids_array_array, + groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, + mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, + arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, + aggregation_target AS aggregation_target + FROM + (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, + if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target, + e.uuid AS uuid, + e.`$session_id` AS `$session_id`, + e.`$window_id` AS `$window_id`, + if(equals(e.event, '$pageview'), 1, 0) AS step_0, + if(equals(e.event, 'insight analyzed'), 1, 0) AS step_1 + FROM events AS e + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, + person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 2) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) + LEFT JOIN + (SELECT person.id AS id, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo + FROM person + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(e.team_id, 2), and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-08 23:59:59.999999', 6, 'UTC'))), ifNull(equals(e__person.properties___foo, 'bar'), 0))) + GROUP BY aggregation_target + HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) + WHERE ifNull(greaterOrEquals(step_reached, 0), 0) + ORDER BY aggregation_target ASC) AS funnel_actors + WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) + GROUP BY funnel_actors.actor_id + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE and(equals(person.team_id, 2), in(id, + (SELECT source.actor_id AS actor_id + FROM + (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events + FROM + (SELECT aggregation_target AS actor_id, matched_events_array[plus(step_reached, 1)] AS matching_events, (matched_events_array[1][1]).1 AS timestamp, nullIf((matched_events_array[2][1]).1, 0) AS final_timestamp, (matched_events_array[1][1]).1 AS first_timestamp, steps AS steps, final_timestamp, first_timestamp + FROM + (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, [], arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, arrayJoin(aggregate_funnel_array_v1(2, 1209600, 'first_touch', 'strict', [[]], arrayFilter((x, x2) -> not(and(empty(x.4), empty(x2.4), ifNull(equals(x.3, x2.3), isNull(x.3) + and isNull(x2.3)), ifNull(greater(x.1, x2.1), 0))), events_array, arrayRotateRight(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, aggregation_target AS aggregation_target + (SELECT arraySort(t -> t.1, groupArray(tuple(accurateCastOrNull(timestamp, 'Float64'), uuid, [], arrayFilter(x -> ifNull(notEquals(x, 0), 1), [multiply(1, step_0), multiply(2, step_1)])))) AS events_array, arrayJoin(aggregate_funnel_array(2, 1209600, 'first_touch', 'strict', [[]], arrayFilter((x, x2) -> not(and(empty(x.4), empty(x2.4), ifNull(equals(x.3, x2.3), isNull(x.3) + and isNull(x2.3)), ifNull(greater(x.1, x2.1), 0))), events_array, arrayRotateRight(events_array, 1)))) AS af_tuple, af_tuple.1 AS step_reached, plus(af_tuple.1, 1) AS steps, af_tuple.2 AS breakdown, af_tuple.3 AS timings, af_tuple.4 AS matched_event_uuids_array_array, groupArray(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS user_events, mapFromArrays(arrayMap(x -> x.2, user_events), user_events) AS user_events_map, arrayMap(matched_event_uuids_array -> arrayMap(event_uuid -> user_events_map[event_uuid], arrayDistinct(matched_event_uuids_array)), matched_event_uuids_array_array) AS matched_events_array, aggregation_target AS aggregation_target + FROM + (SELECT toTimeZone(e.timestamp, 'UTC') AS timestamp, if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target, e.uuid AS uuid, e.`$session_id` AS `$session_id`, e.`$window_id` AS `$window_id`, if(equals(e.event, '$pageview'), 1, 0) AS step_0, if(equals(e.event, 'insight analyzed'), 1, 0) AS step_1 + FROM events AS e + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 2) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) + LEFT JOIN + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'foo'), ''), 'null'), '^"|"$', '') AS properties___foo + FROM person + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(e.team_id, 2), and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2021-01-08 23:59:59.999999', 6, 'UTC'))), ifNull(equals(e__person.properties___foo, 'bar'), 0))) + GROUP BY aggregation_target + HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) + WHERE ifNull(greaterOrEquals(step_reached, 0), 0) + ORDER BY aggregation_target ASC) AS funnel_actors + WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) + GROUP BY funnel_actors.actor_id + ORDER BY funnel_actors.actor_id ASC) AS source))) + 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)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) + ORDER BY persons.id ASC + LIMIT 101 + OFFSET 0 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 + ''' +# --- +# name: TestFunnelCorrelationsActorsUDF.test_strict_funnel_correlation_with_recordings.3 + ''' + SELECT DISTINCT session_replay_events.session_id AS session_id + FROM session_replay_events + WHERE and(equals(session_replay_events.team_id, 2), ifNull(greaterOrEquals(toTimeZone(session_replay_events.min_first_timestamp, 'UTC'), minus(toDateTime64('2021-01-02 00:00:00.000000', 6, 'UTC'), toIntervalDay(21))), 0), in(session_replay_events.session_id, ['s3'])) + LIMIT 100 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 + ''' +# --- diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_udf.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_udf.ambr index aaba0c64a8244..2ce1ce619f3a2 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_udf.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation_udf.ambr @@ -177,11 +177,14 @@ persons.properties AS person_props FROM (SELECT person.id AS id, - argMax(person.properties, person.version) AS properties + person.properties AS properties FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons) AS persons ON equals(persons.id, funnel_actors.actor_id)) AS aggregation_target_with_props + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons) AS persons ON equals(persons.id, funnel_actors.actor_id)) AS aggregation_target_with_props GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2 HAVING ifNull(notIn((aggregation_target_with_props.prop).1, []), 0) LIMIT 100 @@ -294,17 +297,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -316,7 +316,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -338,17 +338,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -435,17 +432,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -457,7 +451,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -479,17 +473,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -576,17 +567,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -598,7 +586,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -620,17 +608,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -717,17 +702,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -739,7 +721,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -761,17 +743,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -866,11 +845,14 @@ persons.properties AS person_props FROM (SELECT person.id AS id, - argMax(person.properties, person.version) AS properties + person.properties AS properties FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS persons) AS persons ON equals(persons.id, funnel_actors.actor_id)) AS aggregation_target_with_props + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons) AS persons ON equals(persons.id, funnel_actors.actor_id)) AS aggregation_target_with_props GROUP BY (aggregation_target_with_props.prop).1, (aggregation_target_with_props.prop).2 HAVING ifNull(notIn((aggregation_target_with_props.prop).1, []), 0) LIMIT 100 @@ -983,17 +965,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -1005,7 +984,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -1027,17 +1006,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + (SELECT person.id AS id, nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -1124,17 +1100,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -1146,7 +1119,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -1168,17 +1141,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + (SELECT person.id AS id, nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Positive'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Positive'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -1265,17 +1235,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -1287,7 +1254,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -1309,17 +1276,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + (SELECT person.id AS id, nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -1406,17 +1370,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -1428,7 +1389,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events @@ -1450,17 +1411,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), person.version) AS `properties___$browser` + (SELECT person.id AS id, nullIf(nullIf(person.`pmat_$browser`, ''), 'null') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 0)))), ifNull(equals(nullIf(nullIf(person.`pmat_$browser`, ''), 'null'), 'Negative'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-14 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('paid', 'user signed up')), ifNull(equals(e__person.`properties___$browser`, 'Negative'), 0)), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_udf.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_udf.ambr index 22e9e4f16266b..5716fdbd2c292 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_udf.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_udf.ambr @@ -106,8 +106,8 @@ WHERE ifNull(greaterOrEquals(step_reached, 1), 0) ORDER BY aggregation_target ASC) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id @@ -328,18 +328,15 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), person.version) AS properties___age + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0))))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-07-01 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(e__person.properties___email, '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(e__person.properties___email, '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) @@ -395,26 +392,23 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), person.version) AS properties___age + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0))))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-07-01 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(e__person.properties___email, '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(e__person.properties___email, '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) WHERE ifNull(greaterOrEquals(step_reached, 0), 0) ORDER BY aggregation_target ASC) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id @@ -470,26 +464,23 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), person.version) AS properties___age + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0))))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-07-01 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(e__person.properties___email, '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(e__person.properties___email, '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) WHERE ifNull(greaterOrEquals(step_reached, 1), 0) ORDER BY aggregation_target ASC) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id @@ -545,26 +536,23 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), person.version) AS properties___age + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', '') AS properties___age FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 0))))), or(and(ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.com%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '20'), 0)), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%.org%'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'age'), ''), 'null'), '^"|"$', ''), '28'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(and(greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), toDateTime64('2020-07-01 23:59:59.999999', 6, 'UTC'))), in(e.event, tuple('$pageview', 'user signed up')), or(and(ifNull(ilike(e__person.properties___email, '%.com%'), 0), ifNull(equals(e__person.properties___age, '20'), 0)), or(ifNull(ilike(e__person.properties___email, '%.org%'), 0), ifNull(equals(e__person.properties___age, '28'), 0)))), or(ifNull(equals(step_0, 1), 0), ifNull(equals(step_1, 1), 0), ifNull(equals(step_2, 1), 0)))) GROUP BY aggregation_target HAVING ifNull(greaterOrEquals(step_reached, 0), 0)) WHERE ifNull(greaterOrEquals(step_reached, 2), 0) ORDER BY aggregation_target ASC) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id diff --git a/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambr b/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambr index f2ad687c51992..a035cd71bf10e 100644 --- a/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambr +++ b/posthog/hogql_queries/insights/test/__snapshots__/test_insight_actors_query_runner.ambr @@ -58,11 +58,14 @@ ORDER BY aggregation_target ASC) AS source INNER JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.properties___name ASC) LIMIT 100 SETTINGS readonly=2, max_execution_time=60, @@ -106,8 +109,8 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id @@ -118,36 +121,39 @@ and isNull(toStartOfDay(parseDateTime64BestEffortOrNull('2020-01-12', 6, 'US/Pacific')))), ifNull(equals(status, 'returning'), 0))) AS source INNER JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT source.actor_id AS actor_id - FROM - (SELECT DISTINCT actor_id AS actor_id - FROM - (SELECT min(events__person.created_at) AS created_at, arraySort(groupUniqArray(toStartOfDay(toTimeZone(events.timestamp, 'US/Pacific')))) AS all_activity, arrayPopBack(arrayPushFront(all_activity, toStartOfDay(created_at))) AS previous_activity, arrayPopFront(arrayPushBack(all_activity, toStartOfDay(parseDateTime64BestEffortOrNull('1970-01-01 00:00:00', 6, 'US/Pacific')))) AS following_activity, arrayMap((previous, current, index) -> if(ifNull(equals(previous, current), isNull(previous) - and isNull(current)), 'new', if(and(ifNull(equals(minus(current, toIntervalDay(1)), previous), isNull(minus(current, toIntervalDay(1))) - and isNull(previous)), ifNull(notEquals(index, 1), 1)), 'returning', 'resurrecting')), previous_activity, all_activity, arrayEnumerate(all_activity)) AS initial_status, arrayMap((current, next) -> if(ifNull(equals(plus(current, toIntervalDay(1)), next), isNull(plus(current, toIntervalDay(1))) - and isNull(next)), '', 'dormant'), all_activity, following_activity) AS dormant_status, arrayMap(x -> plus(x, toIntervalDay(1)), arrayFilter((current, is_dormant) -> ifNull(equals(is_dormant, 'dormant'), 0), all_activity, dormant_status)) AS dormant_periods, arrayMap(x -> 'dormant', dormant_periods) AS dormant_label, arrayConcat(arrayZip(all_activity, initial_status), arrayZip(dormant_periods, dormant_label)) AS temp_concat, arrayJoin(temp_concat) AS period_status_pairs, period_status_pairs.1 AS start_of_period, period_status_pairs.2 AS status, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id - FROM events - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) - LEFT JOIN - (SELECT person.id AS id, argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version) AS created_at - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) - WHERE and(equals(events.team_id, 2), greaterOrEquals(toTimeZone(events.timestamp, 'US/Pacific'), minus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-09 00:00:00', 6, 'US/Pacific'))), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'US/Pacific'), plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-19 23:59:59', 6, 'US/Pacific'))), toIntervalDay(1))), equals(events.event, '$pageview')) - GROUP BY actor_id) - WHERE and(ifNull(equals(start_of_period, toStartOfDay(parseDateTime64BestEffortOrNull('2020-01-12', 6, 'US/Pacific'))), isNull(start_of_period) - and isNull(toStartOfDay(parseDateTime64BestEffortOrNull('2020-01-12', 6, 'US/Pacific')))), ifNull(equals(status, 'returning'), 0))) AS source))) - GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) + WHERE and(equals(person.team_id, 2), in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE and(equals(person.team_id, 2), in(person.id, + (SELECT source.actor_id AS actor_id + FROM + (SELECT DISTINCT actor_id AS actor_id + FROM + (SELECT min(events__person.created_at) AS created_at, arraySort(groupUniqArray(toStartOfDay(toTimeZone(events.timestamp, 'US/Pacific')))) AS all_activity, arrayPopBack(arrayPushFront(all_activity, toStartOfDay(created_at))) AS previous_activity, arrayPopFront(arrayPushBack(all_activity, toStartOfDay(parseDateTime64BestEffortOrNull('1970-01-01 00:00:00', 6, 'US/Pacific')))) AS following_activity, arrayMap((previous, current, index) -> if(ifNull(equals(previous, current), isNull(previous) + and isNull(current)), 'new', if(and(ifNull(equals(minus(current, toIntervalDay(1)), previous), isNull(minus(current, toIntervalDay(1))) + and isNull(previous)), ifNull(notEquals(index, 1), 1)), 'returning', 'resurrecting')), previous_activity, all_activity, arrayEnumerate(all_activity)) AS initial_status, arrayMap((current, next) -> if(ifNull(equals(plus(current, toIntervalDay(1)), next), isNull(plus(current, toIntervalDay(1))) + and isNull(next)), '', 'dormant'), all_activity, following_activity) AS dormant_status, arrayMap(x -> plus(x, toIntervalDay(1)), arrayFilter((current, is_dormant) -> ifNull(equals(is_dormant, 'dormant'), 0), all_activity, dormant_status)) AS dormant_periods, arrayMap(x -> 'dormant', dormant_periods) AS dormant_label, arrayConcat(arrayZip(all_activity, initial_status), arrayZip(dormant_periods, dormant_label)) AS temp_concat, arrayJoin(temp_concat) AS period_status_pairs, period_status_pairs.1 AS start_of_period, period_status_pairs.2 AS status, if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id + FROM events + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 2) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) + LEFT JOIN + (SELECT argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version) AS created_at, person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(events.team_id, 2), greaterOrEquals(toTimeZone(events.timestamp, 'US/Pacific'), minus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-09 00:00:00', 6, 'US/Pacific'))), toIntervalDay(1))), less(toTimeZone(events.timestamp, 'US/Pacific'), plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-19 23:59:59', 6, 'US/Pacific'))), toIntervalDay(1))), equals(events.event, '$pageview')) + GROUP BY actor_id) + WHERE and(ifNull(equals(start_of_period, toStartOfDay(parseDateTime64BestEffortOrNull('2020-01-12', 6, 'US/Pacific'))), isNull(start_of_period) + and isNull(toStartOfDay(parseDateTime64BestEffortOrNull('2020-01-12', 6, 'US/Pacific')))), ifNull(equals(status, 'returning'), 0))) AS source))) + GROUP BY person.id + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.properties___name ASC) LIMIT 100 SETTINGS readonly=2, max_execution_time=60, @@ -213,26 +219,29 @@ WHERE ifNull(equals(num_intervals, 2), 0)) AS source INNER JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT source.actor_id AS actor_id - FROM - (SELECT aggregation_target AS actor_id - FROM - (SELECT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target, count(DISTINCT toStartOfDay(toTimeZone(e.timestamp, 'US/Pacific'))) AS num_intervals - FROM events AS e SAMPLE 1 - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) - WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'US/Pacific'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-09 00:00:00', 6, 'US/Pacific')))), lessOrEquals(toTimeZone(e.timestamp, 'US/Pacific'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-19 23:59:59', 6, 'US/Pacific'))), equals(e.event, '$pageview')) - GROUP BY aggregation_target) - WHERE ifNull(equals(num_intervals, 2), 0)) AS source))) - GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) + WHERE and(equals(person.team_id, 2), in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE and(equals(person.team_id, 2), in(person.id, + (SELECT source.actor_id AS actor_id + FROM + (SELECT aggregation_target AS actor_id + FROM + (SELECT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS aggregation_target, count(DISTINCT toStartOfDay(toTimeZone(e.timestamp, 'US/Pacific'))) AS num_intervals + FROM events AS e SAMPLE 1 + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 2) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) + WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'US/Pacific'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-09 00:00:00', 6, 'US/Pacific')))), lessOrEquals(toTimeZone(e.timestamp, 'US/Pacific'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-19 23:59:59', 6, 'US/Pacific'))), equals(e.event, '$pageview')) + GROUP BY aggregation_target) + WHERE ifNull(equals(num_intervals, 2), 0)) AS source))) + GROUP BY person.id + HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.properties___name ASC) LIMIT 100 SETTINGS readonly=2, max_execution_time=60, @@ -276,72 +285,6 @@ max_bytes_before_external_group_by=0 ''' # --- -# name: TestInsightActorsQueryRunner.test_insight_persons_trends_query - ''' - SELECT name AS name - FROM - (SELECT persons.properties___name AS name - FROM - (SELECT actor_id AS actor_id, - count() AS event_count - FROM - (SELECT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id, - toTimeZone(e.timestamp, 'US/Pacific') AS timestamp, - e.uuid AS uuid - FROM events AS e - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, - person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) - LEFT JOIN - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) - WHERE and(equals(e.team_id, 2), ifNull(notEquals(e__person.properties___email, 'tom@posthog.com'), 1), greaterOrEquals(timestamp, toDateTime64('2020-01-09 00:00:00.000000', 6, 'US/Pacific')), less(timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'US/Pacific')), equals(e.event, '$pageview'))) - GROUP BY actor_id) AS source - INNER JOIN - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name - FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT source.actor_id AS actor_id - FROM - (SELECT actor_id AS actor_id, count() AS event_count - FROM - (SELECT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id) AS actor_id, toTimeZone(e.timestamp, 'US/Pacific') AS timestamp, e.uuid AS uuid - FROM events AS e - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) - LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) - WHERE and(equals(e.team_id, 2), ifNull(notEquals(e__person.properties___email, 'tom@posthog.com'), 1), greaterOrEquals(timestamp, toDateTime64('2020-01-09 00:00:00.000000', 6, 'US/Pacific')), less(timestamp, toDateTime64('2020-01-10 00:00:00.000000', 6, 'US/Pacific')), equals(e.event, '$pageview'))) - GROUP BY actor_id) AS source))) - GROUP BY person.id - HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version), plus(now64(6, 'US/Pacific'), toIntervalDay(1))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) - ORDER BY persons.properties___name ASC) - LIMIT 100 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- # name: TestInsightActorsQueryRunner.test_insight_persons_trends_query_with_argmaxV1 ''' SELECT name AS name diff --git a/posthog/hogql_queries/insights/test/__snapshots__/test_lifecycle_query_runner.ambr b/posthog/hogql_queries/insights/test/__snapshots__/test_lifecycle_query_runner.ambr index b015b6ef963f2..b3d749554f12f 100644 --- a/posthog/hogql_queries/insights/test/__snapshots__/test_lifecycle_query_runner.ambr +++ b/posthog/hogql_queries/insights/test/__snapshots__/test_lifecycle_query_runner.ambr @@ -70,8 +70,8 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id @@ -148,8 +148,8 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id @@ -223,8 +223,8 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id @@ -298,8 +298,8 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'US/Pacific'), person.version) AS created_at, + person.id AS id FROM person WHERE equals(person.team_id, 2) GROUP BY person.id diff --git a/posthog/hogql_queries/insights/test/__snapshots__/test_paths_query_runner_ee.ambr b/posthog/hogql_queries/insights/test/__snapshots__/test_paths_query_runner_ee.ambr index a93e47ecb4120..326acba019703 100644 --- a/posthog/hogql_queries/insights/test/__snapshots__/test_paths_query_runner_ee.ambr +++ b/posthog/hogql_queries/insights/test/__snapshots__/test_paths_query_runner_ee.ambr @@ -1267,7 +1267,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -1415,7 +1415,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -1562,7 +1562,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -1710,7 +1710,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -1858,7 +1858,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -2005,7 +2005,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -2153,7 +2153,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -2301,7 +2301,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -2448,7 +2448,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -2687,10 +2687,10 @@ WHERE ifNull(equals(path_key, '2_/2'), 0) GROUP BY person_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -2853,10 +2853,10 @@ and isNull(path_key))) GROUP BY person_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -3006,10 +3006,10 @@ and isNull(path_key))) GROUP BY person_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -3172,10 +3172,10 @@ WHERE ifNull(equals(path_key, '2_/2'), 0) GROUP BY person_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -3346,10 +3346,10 @@ WHERE ifNull(equals(path_key, '2_/2'), 0) GROUP BY person_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -3689,7 +3689,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -3933,7 +3933,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -4177,7 +4177,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -4421,7 +4421,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -4816,7 +4816,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -4963,7 +4963,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -5192,7 +5192,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -5421,7 +5421,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -5568,7 +5568,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -5715,7 +5715,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -13121,7 +13121,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -13269,7 +13269,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -13416,7 +13416,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -13564,7 +13564,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -13712,7 +13712,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -13859,7 +13859,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -14007,7 +14007,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -14155,7 +14155,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -14302,7 +14302,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -14541,10 +14541,10 @@ WHERE ifNull(equals(path_key, '2_/2'), 0) GROUP BY person_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -14707,10 +14707,10 @@ and isNull(path_key))) GROUP BY person_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -14860,10 +14860,10 @@ and isNull(path_key))) GROUP BY person_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -15026,10 +15026,10 @@ WHERE ifNull(equals(path_key, '2_/2'), 0) GROUP BY person_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -15200,10 +15200,10 @@ WHERE ifNull(equals(path_key, '2_/2'), 0) GROUP BY person_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -15543,7 +15543,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -15787,7 +15787,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -16031,7 +16031,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -16275,7 +16275,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -16670,7 +16670,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -16817,7 +16817,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -17046,7 +17046,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -17275,7 +17275,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -17422,7 +17422,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count @@ -17569,7 +17569,7 @@ INNER JOIN (SELECT person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT person_id AS actor_id, groupUniqArray(100)(tuple(timestamp, uuid, session_id, window_id)) AS matching_events, count(*) AS event_count diff --git a/posthog/hogql_queries/insights/test/__snapshots__/test_retention_query_runner.ambr b/posthog/hogql_queries/insights/test/__snapshots__/test_retention_query_runner.ambr index 0350486731c92..63d18ae1c4380 100644 --- a/posthog/hogql_queries/insights/test/__snapshots__/test_retention_query_runner.ambr +++ b/posthog/hogql_queries/insights/test/__snapshots__/test_retention_query_runner.ambr @@ -337,11 +337,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfDay(toDateTime64('2020-06-10 00:00:00.000000', 6, 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-06-17 00:00:00.000000', 6, 'UTC'))), in(events.event, tuple('$pageview', '$pageview', 'non_matching_event'))) GROUP BY actor_id) AS actor_activity GROUP BY breakdown_values, diff --git a/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py b/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py index 045132aed54ec..d34bdfe8876b5 100644 --- a/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py +++ b/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py @@ -8,7 +8,7 @@ from posthog.models.group.util import create_group from posthog.models.group_type_mapping import GroupTypeMapping from posthog.models.team import WeekStartDay -from posthog.schema import HogQLQueryModifiers +from posthog.schema import HogQLQueryModifiers, PersonsArgMaxVersion from posthog.test.base import ( APIBaseTest, ClickhouseTestMixin, @@ -213,7 +213,7 @@ def test_insight_persons_stickiness_groups_query(self): self.assertEqual([("org1",)], response.results) @snapshot_clickhouse_queries - def test_insight_persons_trends_query(self): + def test_insight_persons_trends_query_with_argmaxV1(self): self._create_test_events() self.team.timezone = "US/Pacific" self.team.save() @@ -233,10 +233,39 @@ def test_insight_persons_trends_query(self): ) """, + modifiers={"personsArgMaxVersion": PersonsArgMaxVersion.V1}, ) self.assertEqual([("p2",)], response.results) - assert "in(person.id," in queries[0] + assert "in(id," in queries[0] + self.assertEqual(2, queries[0].count("toTimeZone(e.timestamp, 'US/Pacific') AS timestamp")) + + @snapshot_clickhouse_queries + def test_insight_persons_trends_query_with_argmaxV2(self): + self._create_test_events() + self.team.timezone = "US/Pacific" + self.team.save() + + with self.capture_queries(lambda query: re.match(r"^SELECT\s+name\s+AS\s+name", query) is not None) as queries: + response = self.select( + """ + select * from ( + + + } + series={[]} + properties={[]} + /> + + + ) + """, + modifiers={"personsArgMaxVersion": PersonsArgMaxVersion.V2}, + ) + + self.assertEqual([("p2",)], response.results) + assert "in(person.id" in queries[0] self.assertEqual(2, queries[0].count("toTimeZone(e.timestamp, 'US/Pacific') AS timestamp")) @snapshot_clickhouse_queries diff --git a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambr b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambr index 688ee60e16799..14201b4e6b41e 100644 --- a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambr +++ b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambr @@ -70,17 +70,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$bool_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$bool_prop` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$bool_prop'), ''), 'null'), '^"|"$', '') AS `properties___$bool_prop` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$bool_prop'), ''), 'null'), '^"|"$', ''), 'x'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$bool_prop'), ''), 'null'), '^"|"$', ''), 'x'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-07 23:59:59', 6, 'UTC'))), and(equals(e.event, 'sign up'), ifNull(in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), (SELECT cohortpeople.person_id AS person_id FROM cohortpeople @@ -260,10 +257,10 @@ WHERE and(equals(e.team_id, 2), greaterOrEquals(timestamp, toDateTime64('2020-01-02 00:00:00.000000', 6, 'UTC')), less(timestamp, toDateTime64('2020-01-03 00:00:00.000000', 6, 'UTC')), ifNull(equals(ifNull(nullIf(toString(e__group_0.properties___industry), ''), '$$_posthog_breakdown_null_$$'), 'technology'), 0), equals(e.event, 'sign up'))) GROUP BY actor_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT actor_id AS actor_id, count() AS event_count, groupUniqArray(100)(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS matching_events @@ -352,114 +349,6 @@ max_bytes_before_external_group_by=0 ''' # --- -# name: TestTrends.test_breakdown_by_person_property_pie_with_event_dau_filter - ''' - SELECT sum(total) AS total, - if(ifNull(ifNull(greaterOrEquals(row_number, 26), 0), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value - FROM - (SELECT count AS total, - breakdown_value AS breakdown_value, - row_number() OVER ( - ORDER BY total DESC) AS row_number - FROM - (SELECT sum(total) AS count, - breakdown_value AS breakdown_value - FROM - (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total, - ifNull(nullIf(toString(e__person.properties___name), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value - FROM events AS e SAMPLE 1 - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, - person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) - LEFT JOIN - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name - FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(notILike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), '%person3%'), 1))))) - 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) - WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-21 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'watched movie'), ifNull(notILike(e__person.properties___name, '%person3%'), 1)) - GROUP BY breakdown_value) - GROUP BY breakdown_value - ORDER BY breakdown_value ASC) - ORDER BY total DESC, breakdown_value ASC) - WHERE isNotNull(breakdown_value) - GROUP BY breakdown_value - ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, total DESC, - breakdown_value ASC - LIMIT 50000 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestTrends.test_breakdown_by_person_property_pie_with_event_dau_filter.1 - ''' - SELECT sum(total) AS total, - arrayMap(i -> if(ifNull(ifNull(greaterOrEquals(row_number, 26), 0), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value - FROM - (SELECT count AS total, - breakdown_value AS breakdown_value, - row_number() OVER ( - ORDER BY total DESC) AS row_number - FROM - (SELECT sum(total) AS count, - [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value - FROM - (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total, - ifNull(nullIf(toString(e__person.properties___name), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1 - FROM events AS e SAMPLE 1 - LEFT OUTER JOIN - (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, - person_distinct_id_overrides.distinct_id AS distinct_id - FROM person_distinct_id_overrides - WHERE equals(person_distinct_id_overrides.team_id, 2) - GROUP BY person_distinct_id_overrides.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) - LEFT JOIN - (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name - FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(notILike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), '%person3%'), 1))))) - 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) - WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-21 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'watched movie'), ifNull(notILike(e__person.properties___name, '%person3%'), 1)) - GROUP BY breakdown_value_1) - GROUP BY breakdown_value_1 - ORDER BY breakdown_value ASC) - ORDER BY total DESC, breakdown_value ASC) - WHERE arrayExists(x -> isNotNull(x), breakdown_value) - GROUP BY breakdown_value - ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, total DESC, - breakdown_value ASC - LIMIT 50000 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- # name: TestTrends.test_breakdown_filtering_with_properties_in_new_format ''' SELECT groupArray(1)(date)[1] AS date, @@ -800,17 +689,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'p1'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'p2'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'p3'), 0))))), or(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'p1'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'p2'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'p3'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(equals(e.event, '$pageview'), and(or(ifNull(equals(e__person.properties___name, 'p1'), 0), ifNull(equals(e__person.properties___name, 'p2'), 0), ifNull(equals(e__person.properties___name, 'p3'), 0)), ifNull(in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), (SELECT cohortpeople.person_id AS person_id FROM cohortpeople @@ -1484,17 +1370,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'Jane'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'Jane'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-26 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-02 23:59:59', 6, 'UTC'))), equals(e.event, 'event_name'), ifNull(equals(e__person.properties___name, 'Jane'), 0)) GROUP BY day_start) GROUP BY day_start @@ -1653,10 +1536,10 @@ WHERE and(equals(e.team_id, 2), and(ifNull(equals(e__group_0.properties___industry, 'finance'), 0), ifNull(equals(e__group_2.properties___name, 'six'), 0)), greaterOrEquals(timestamp, toDateTime64('2020-01-02 00:00:00.000000', 6, 'UTC')), less(timestamp, toDateTime64('2020-01-03 00:00:00.000000', 6, 'UTC')), equals(e.event, 'sign up'))) GROUP BY actor_id) AS source INNER JOIN - (SELECT person.id AS id, - argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at + (SELECT argMax(toTimeZone(person.created_at, 'UTC'), person.version) AS created_at, + person.id AS id FROM person - WHERE and(equals(person.team_id, 2), in(person.id, + WHERE and(equals(person.team_id, 2), in(id, (SELECT source.actor_id AS actor_id FROM (SELECT actor_id AS actor_id, count() AS event_count, groupUniqArray(100)(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS matching_events @@ -1776,18 +1659,15 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop`, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', ''), person.version) AS properties___filter_prop + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', '') AS properties___filter_prop FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', ''), 'filter_val'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', ''), 'filter_val'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(equals(e.event, 'sign up'), ifNull(equals(e__person.properties___filter_prop, 'filter_val'), 0)), ifNull(greaterOrEquals(timestamp, minus(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')), toIntervalDay(30))), 0), ifNull(lessOrEquals(timestamp, assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), 0)) GROUP BY timestamp, actor_id, breakdown_value) AS e @@ -1853,18 +1733,15 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop`, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', ''), person.version) AS properties___filter_prop + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop`, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', '') AS properties___filter_prop FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', ''), 'filter_val'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'filter_prop'), ''), 'null'), '^"|"$', ''), 'filter_val'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(equals(e.event, 'sign up'), ifNull(equals(e__person.properties___filter_prop, 'filter_val'), 0)), ifNull(greaterOrEquals(timestamp, minus(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')), toIntervalDay(30))), 0), ifNull(lessOrEquals(timestamp, assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), 0)) GROUP BY timestamp, actor_id, breakdown_value_1) AS e @@ -2227,17 +2104,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'person1'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'person1'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(e__person.properties___name, 'person1'), 0)) GROUP BY day_start) GROUP BY day_start @@ -2273,17 +2147,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'person1'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'person1'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(e__person.properties___name, 'person1'), 0)) GROUP BY day_start) GROUP BY day_start @@ -2345,17 +2216,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(nullIf(nullIf(person.pmat_name, ''), 'null'), person.version) AS properties___name + nullIf(nullIf(person.pmat_name, ''), 'null') AS properties___name FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.pmat_name, ''), 'null'), 'person1'), 0)))), ifNull(equals(nullIf(nullIf(person.pmat_name, ''), 'null'), 'person1'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(e__person.properties___name, 'person1'), 0)) GROUP BY day_start) GROUP BY day_start @@ -2417,17 +2285,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(nullIf(nullIf(person.pmat_name, ''), 'null'), person.version) AS properties___name + nullIf(nullIf(person.pmat_name, ''), 'null') AS properties___name FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.pmat_name, ''), 'null'), 'person1'), 0)))), ifNull(equals(nullIf(nullIf(person.pmat_name, ''), 'null'), 'person1'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'watched movie'), ifNull(equals(e__person.properties___name, 'person1'), 0)) GROUP BY day_start) GROUP BY day_start @@ -3532,19 +3397,16 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$os`, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', '') AS `properties___$os`, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', ''), 'android'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'safari'), 0))))), or(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', ''), 'android'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'safari'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-07-01 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up'), and(or(ifNull(notILike(e__person.properties___email, '%@posthog.com%'), 1), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0)), or(ifNull(equals(e__person.`properties___$os`, 'android'), 0), ifNull(equals(e__person.`properties___$browser`, 'safari'), 0)))) GROUP BY day_start, breakdown_value) @@ -3594,19 +3456,16 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$os`, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$browser` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', '') AS `properties___$os`, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', '') AS `properties___$browser` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', ''), 'android'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'chrome'), 0), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%@posthog.com%'), 0))))), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$os'), ''), 'null'), '^"|"$', ''), 'android'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'chrome'), 0), ifNull(ilike(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), '%@posthog.com%'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-07-01 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up'), and(ifNull(equals(e__person.`properties___$os`, 'android'), 0), ifNull(equals(e__person.`properties___$browser`, 'chrome'), 0)), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'key'), ''), 'null'), '^"|"$', ''), 'val'), 0), ifNull(ilike(e__person.properties___email, '%@posthog.com%'), 0))) GROUP BY day_start, breakdown_value) @@ -3674,17 +3533,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop` FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), 'some_val'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), 'some_val'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-24 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-31 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up'), ifNull(equals(e__person.`properties___$some_prop`, 'some_val'), 0)) GROUP BY day_start) GROUP BY day_start @@ -3728,11 +3584,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop` FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-24 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-31 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) GROUP BY day_start, breakdown_value) @@ -3782,11 +3641,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop` FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-24 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-31 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) GROUP BY day_start, breakdown_value_1) @@ -4816,11 +4678,14 @@ raw_sessions.session_id_v7) AS e__session ON equals(toUInt128(accurateCastOrNull(e.`$session_id`, 'UUID')), e__session.session_id_v7) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop` FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) GROUP BY e.`$session_id`, breakdown_value) @@ -4876,11 +4741,14 @@ raw_sessions.session_id_v7) AS e__session ON equals(toUInt128(accurateCastOrNull(e.`$session_id`, 'UUID')), e__session.session_id_v7) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', ''), person.version) AS `properties___$some_prop` + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, '$some_prop'), ''), 'null'), '^"|"$', '') AS `properties___$some_prop` FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) GROUP BY e.`$session_id`, breakdown_value_1) @@ -5551,17 +5419,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'person-1'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'person-2'), 0))))), or(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'person-1'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), 'person-2'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(equals(e.event, '$pageview'), or(ifNull(equals(e__person.properties___name, 'person-1'), 0), ifNull(equals(e__person.properties___name, 'person-2'), 0))), ifNull(greaterOrEquals(timestamp, minus(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC')), toIntervalDay(7))), 0), ifNull(lessOrEquals(timestamp, assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-12 23:59:59', 6, 'UTC'))), 0)) GROUP BY timestamp, actor_id) AS e WHERE and(ifNull(lessOrEquals(e.timestamp, plus(d.timestamp, toIntervalDay(1))), 0), ifNull(greater(e.timestamp, minus(d.timestamp, toIntervalDay(6))), 0)) @@ -5610,17 +5475,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(nullIf(nullIf(person.pmat_name, ''), 'null'), person.version) AS properties___name + nullIf(nullIf(person.pmat_name, ''), 'null') AS properties___name FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(ifNull(equals(nullIf(nullIf(person.pmat_name, ''), 'null'), 'person-1'), 0), ifNull(equals(nullIf(nullIf(person.pmat_name, ''), 'null'), 'person-2'), 0))))), or(ifNull(equals(nullIf(nullIf(person.pmat_name, ''), 'null'), 'person-1'), 0), ifNull(equals(nullIf(nullIf(person.pmat_name, ''), 'null'), 'person-2'), 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)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id) WHERE and(equals(e.team_id, 2), and(equals(e.event, '$pageview'), or(ifNull(equals(e__person.properties___name, 'person-1'), 0), ifNull(equals(e__person.properties___name, 'person-2'), 0))), ifNull(greaterOrEquals(timestamp, minus(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC')), toIntervalDay(7))), 0), ifNull(lessOrEquals(timestamp, assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-12 23:59:59', 6, 'UTC'))), 0)) GROUP BY timestamp, actor_id) AS e WHERE and(ifNull(lessOrEquals(e.timestamp, plus(d.timestamp, toIntervalDay(1))), 0), ifNull(greater(e.timestamp, minus(d.timestamp, toIntervalDay(6))), 0)) diff --git a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends_persons.ambr b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends_persons.ambr index 8b88bfb2d9371..46cefcb7c8f49 100644 --- a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends_persons.ambr +++ b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends_persons.ambr @@ -1,4 +1,14 @@ # serializer version: 1 +# name: TestTrendsPersons.test_trends_all_cohort_breakdown_persons_leftjoin + ''' + + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = NULL + ''' +# --- # name: TestTrendsPersons.test_trends_all_cohort_breakdown_persons_leftjoin.1 ''' /* cohort_calculation: */ diff --git a/posthog/hogql_queries/test/__snapshots__/test_actors_query_runner.ambr b/posthog/hogql_queries/test/__snapshots__/test_actors_query_runner.ambr index 7e097645bdbfb..b98c8fab5986f 100644 --- a/posthog/hogql_queries/test/__snapshots__/test_actors_query_runner.ambr +++ b/posthog/hogql_queries/test/__snapshots__/test_actors_query_runner.ambr @@ -1,80 +1,4 @@ # serializer version: 1 -# name: TestActorsQueryRunner.test_persons_query_search_email - ''' - SELECT persons.id, - persons.id AS id, - persons.created_at AS created_at, - 1 - FROM - (SELECT person.id AS id, - replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, - replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name, - toTimeZone(person.created_at, 'UTC') AS created_at - FROM person - WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), - (SELECT person.id AS id, max(person.version) AS version - FROM person - WHERE equals(person.team_id, 2) - 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons - WHERE or(ifNull(ilike(persons.properties___email, '%jacob4@RANDOM_TEST_ID::01929020-03d5-0000-a54b-af244f0e0186.posthog%'), 0), ifNull(ilike(persons.properties___name, '%jacob4@RANDOM_TEST_ID::01929020-03d5-0000-a54b-af244f0e0186.posthog%'), 0), ifNull(ilike(toString(persons.id), '%jacob4@RANDOM_TEST_ID::01929020-03d5-0000-a54b-af244f0e0186.posthog%'), 0), ifNull(in(persons.id, - (SELECT person_distinct_ids.person_id AS person_id - FROM - (SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id - FROM person_distinct_id2 - WHERE equals(person_distinct_id2.team_id, 2) - GROUP BY person_distinct_id2.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS person_distinct_ids - WHERE ifNull(ilike(person_distinct_ids.distinct_id, '%jacob4@RANDOM_TEST_ID::01929020-03d5-0000-a54b-af244f0e0186.posthog%'), 0))), 0)) - ORDER BY persons.created_at DESC - LIMIT 101 - OFFSET 0 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- -# name: TestActorsQueryRunner.test_persons_query_search_email.1 - ''' - SELECT persons.id, - persons.id AS id, - persons.created_at AS created_at, - 1 - FROM - (SELECT person.id AS id, - replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email, - replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '') AS properties___name, - toTimeZone(person.created_at, 'UTC') AS created_at - FROM person - WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), - (SELECT person.id AS id, max(person.version) AS version - FROM person - WHERE equals(person.team_id, 2) - 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS persons - WHERE or(ifNull(ilike(persons.properties___email, '%JACOB4@RANDOM_TEST_ID::01929020-03d5-0000-a54b-af244f0e0186.posthog%'), 0), ifNull(ilike(persons.properties___name, '%JACOB4@RANDOM_TEST_ID::01929020-03d5-0000-a54b-af244f0e0186.posthog%'), 0), ifNull(ilike(toString(persons.id), '%JACOB4@RANDOM_TEST_ID::01929020-03d5-0000-a54b-af244f0e0186.posthog%'), 0), ifNull(in(persons.id, - (SELECT person_distinct_ids.person_id AS person_id - FROM - (SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id - FROM person_distinct_id2 - WHERE equals(person_distinct_id2.team_id, 2) - GROUP BY person_distinct_id2.distinct_id - HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS person_distinct_ids - WHERE ifNull(ilike(person_distinct_ids.distinct_id, '%JACOB4@RANDOM_TEST_ID::01929020-03d5-0000-a54b-af244f0e0186.posthog%'), 0))), 0)) - ORDER BY persons.created_at DESC - LIMIT 101 - OFFSET 0 SETTINGS readonly=2, - max_execution_time=60, - allow_experimental_object_type=1, - format_csv_allow_double_quotes=0, - max_ast_elements=4000000, - max_expanded_ast_elements=4000000, - max_bytes_before_external_group_by=0 - ''' -# --- # name: TestActorsQueryRunner.test_persons_query_search_snapshot ''' diff --git a/posthog/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr b/posthog/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr index 5135e089baeac..9a973fc39730b 100644 --- a/posthog/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr +++ b/posthog/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr @@ -42,11 +42,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), equals(events.event, '$exception'), ifNull(notILike(events__person.properties___email, '%@posthog.com%'), 1)) GROUP BY fingerprint LIMIT 101 @@ -78,11 +81,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), equals(events.event, '$exception'), ifNull(notILike(events__person.properties___email, '%@posthog.com%'), 1), has([['SyntaxError']], JSONExtract(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', ''), '[]'), 'Array(String)'))) LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -136,6 +142,302 @@ max_bytes_before_external_group_by=0 ''' # --- +# name: TestErrorTrackingQueryRunner.test_fingerprints_with_null_characters.1 + ''' + SELECT "posthog_person"."id", + "posthog_person"."created_at", + "posthog_person"."properties_last_updated_at", + "posthog_person"."properties_last_operation", + "posthog_person"."team_id", + "posthog_person"."properties", + "posthog_person"."is_user_id", + "posthog_person"."is_identified", + "posthog_person"."uuid", + "posthog_person"."version" + FROM "posthog_person" + INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") + WHERE ("posthog_persondistinctid"."distinct_id" = 'user_1' + AND "posthog_persondistinctid"."team_id" = 2) + LIMIT 21 + ''' +# --- +# name: TestErrorTrackingQueryRunner.test_fingerprints_with_null_characters.10 + ''' + SELECT "posthog_datawarehousejoin"."created_by_id", + "posthog_datawarehousejoin"."created_at", + "posthog_datawarehousejoin"."deleted", + "posthog_datawarehousejoin"."deleted_at", + "posthog_datawarehousejoin"."id", + "posthog_datawarehousejoin"."team_id", + "posthog_datawarehousejoin"."source_table_name", + "posthog_datawarehousejoin"."source_table_key", + "posthog_datawarehousejoin"."joining_table_name", + "posthog_datawarehousejoin"."joining_table_key", + "posthog_datawarehousejoin"."field_name" + FROM "posthog_datawarehousejoin" + WHERE ("posthog_datawarehousejoin"."team_id" = 2 + AND NOT ("posthog_datawarehousejoin"."deleted" + AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestErrorTrackingQueryRunner.test_fingerprints_with_null_characters.11 + ''' + SELECT "posthog_propertydefinition"."name", + "posthog_propertydefinition"."property_type" + FROM "posthog_propertydefinition" + WHERE ("posthog_propertydefinition"."name" IN ('$exception_message', + '$exception_type', + '$exception_fingerprint') + AND "posthog_propertydefinition"."team_id" = 2 + AND "posthog_propertydefinition"."type" IN (1, + 2, + 3, + 4, + 5 /* ... */)) + ''' +# --- +# name: TestErrorTrackingQueryRunner.test_fingerprints_with_null_characters.2 + ''' + SELECT "posthog_errortrackinggroup"."fingerprint", + "posthog_errortrackinggroup"."merged_fingerprints", + "posthog_errortrackinggroup"."status", + "posthog_errortrackinggroup"."assignee_id" + FROM "posthog_errortrackinggroup" + WHERE ("posthog_errortrackinggroup"."team_id" = 2 + AND "posthog_errortrackinggroup"."fingerprint" = (ARRAY['SyntaxError', + 'Cannot use ''in'' operator to search for ''wireframes'' in ‹�” ýf�ì½é–"¹’0ø*Lö¹SY A�Ξ÷ԝf + ˆ�Ø'])::text[]) + ''' +# --- +# name: TestErrorTrackingQueryRunner.test_fingerprints_with_null_characters.3 + ''' + SELECT "posthog_grouptypemapping"."id", + "posthog_grouptypemapping"."team_id", + "posthog_grouptypemapping"."group_type", + "posthog_grouptypemapping"."group_type_index", + "posthog_grouptypemapping"."name_singular", + "posthog_grouptypemapping"."name_plural" + FROM "posthog_grouptypemapping" + WHERE "posthog_grouptypemapping"."team_id" = 2 + ''' +# --- +# name: TestErrorTrackingQueryRunner.test_fingerprints_with_null_characters.4 + ''' + SELECT "posthog_datawarehousetable"."created_by_id", + "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", + "posthog_datawarehousetable"."deleted", + "posthog_datawarehousetable"."deleted_at", + "posthog_datawarehousetable"."id", + "posthog_datawarehousetable"."name", + "posthog_datawarehousetable"."format", + "posthog_datawarehousetable"."team_id", + "posthog_datawarehousetable"."url_pattern", + "posthog_datawarehousetable"."credential_id", + "posthog_datawarehousetable"."external_data_source_id", + "posthog_datawarehousetable"."columns", + "posthog_datawarehousetable"."row_count", + "posthog_user"."id", + "posthog_user"."password", + "posthog_user"."last_login", + "posthog_user"."first_name", + "posthog_user"."last_name", + "posthog_user"."is_staff", + "posthog_user"."is_active", + "posthog_user"."date_joined", + "posthog_user"."uuid", + "posthog_user"."current_organization_id", + "posthog_user"."current_team_id", + "posthog_user"."email", + "posthog_user"."pending_email", + "posthog_user"."temporary_token", + "posthog_user"."distinct_id", + "posthog_user"."is_email_verified", + "posthog_user"."requested_password_reset_at", + "posthog_user"."has_seen_product_intro_for", + "posthog_user"."strapi_id", + "posthog_user"."theme_mode", + "posthog_user"."partial_notification_settings", + "posthog_user"."anonymize_data", + "posthog_user"."toolbar_mode", + "posthog_user"."hedgehog_config", + "posthog_user"."events_column_config", + "posthog_user"."email_opt_in", + "posthog_datawarehousecredential"."created_by_id", + "posthog_datawarehousecredential"."created_at", + "posthog_datawarehousecredential"."id", + "posthog_datawarehousecredential"."access_key", + "posthog_datawarehousecredential"."access_secret", + "posthog_datawarehousecredential"."team_id", + "posthog_externaldatasource"."created_by_id", + "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", + "posthog_externaldatasource"."deleted", + "posthog_externaldatasource"."deleted_at", + "posthog_externaldatasource"."id", + "posthog_externaldatasource"."source_id", + "posthog_externaldatasource"."connection_id", + "posthog_externaldatasource"."destination_id", + "posthog_externaldatasource"."team_id", + "posthog_externaldatasource"."sync_frequency", + "posthog_externaldatasource"."status", + "posthog_externaldatasource"."source_type", + "posthog_externaldatasource"."job_inputs", + "posthog_externaldatasource"."are_tables_created", + "posthog_externaldatasource"."prefix" + FROM "posthog_datawarehousetable" + LEFT OUTER JOIN "posthog_user" ON ("posthog_datawarehousetable"."created_by_id" = "posthog_user"."id") + LEFT OUTER JOIN "posthog_datawarehousecredential" ON ("posthog_datawarehousetable"."credential_id" = "posthog_datawarehousecredential"."id") + LEFT OUTER JOIN "posthog_externaldatasource" ON ("posthog_datawarehousetable"."external_data_source_id" = "posthog_externaldatasource"."id") + WHERE ("posthog_datawarehousetable"."team_id" = 2 + AND NOT ("posthog_datawarehousetable"."deleted" + AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestErrorTrackingQueryRunner.test_fingerprints_with_null_characters.5 + ''' + SELECT "posthog_datawarehousesavedquery"."created_by_id", + "posthog_datawarehousesavedquery"."created_at", + "posthog_datawarehousesavedquery"."deleted", + "posthog_datawarehousesavedquery"."deleted_at", + "posthog_datawarehousesavedquery"."id", + "posthog_datawarehousesavedquery"."name", + "posthog_datawarehousesavedquery"."team_id", + "posthog_datawarehousesavedquery"."columns", + "posthog_datawarehousesavedquery"."external_tables", + "posthog_datawarehousesavedquery"."query", + "posthog_datawarehousesavedquery"."status", + "posthog_datawarehousesavedquery"."last_run_at" + FROM "posthog_datawarehousesavedquery" + WHERE ("posthog_datawarehousesavedquery"."team_id" = 2 + AND NOT ("posthog_datawarehousesavedquery"."deleted" + AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestErrorTrackingQueryRunner.test_fingerprints_with_null_characters.6 + ''' + SELECT "posthog_datawarehousejoin"."created_by_id", + "posthog_datawarehousejoin"."created_at", + "posthog_datawarehousejoin"."deleted", + "posthog_datawarehousejoin"."deleted_at", + "posthog_datawarehousejoin"."id", + "posthog_datawarehousejoin"."team_id", + "posthog_datawarehousejoin"."source_table_name", + "posthog_datawarehousejoin"."source_table_key", + "posthog_datawarehousejoin"."joining_table_name", + "posthog_datawarehousejoin"."joining_table_key", + "posthog_datawarehousejoin"."field_name" + FROM "posthog_datawarehousejoin" + WHERE ("posthog_datawarehousejoin"."team_id" = 2 + AND NOT ("posthog_datawarehousejoin"."deleted" + AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestErrorTrackingQueryRunner.test_fingerprints_with_null_characters.7 + ''' + SELECT "posthog_grouptypemapping"."id", + "posthog_grouptypemapping"."team_id", + "posthog_grouptypemapping"."group_type", + "posthog_grouptypemapping"."group_type_index", + "posthog_grouptypemapping"."name_singular", + "posthog_grouptypemapping"."name_plural" + FROM "posthog_grouptypemapping" + WHERE "posthog_grouptypemapping"."team_id" = 2 + ''' +# --- +# name: TestErrorTrackingQueryRunner.test_fingerprints_with_null_characters.8 + ''' + SELECT "posthog_datawarehousetable"."created_by_id", + "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", + "posthog_datawarehousetable"."deleted", + "posthog_datawarehousetable"."deleted_at", + "posthog_datawarehousetable"."id", + "posthog_datawarehousetable"."name", + "posthog_datawarehousetable"."format", + "posthog_datawarehousetable"."team_id", + "posthog_datawarehousetable"."url_pattern", + "posthog_datawarehousetable"."credential_id", + "posthog_datawarehousetable"."external_data_source_id", + "posthog_datawarehousetable"."columns", + "posthog_datawarehousetable"."row_count", + "posthog_user"."id", + "posthog_user"."password", + "posthog_user"."last_login", + "posthog_user"."first_name", + "posthog_user"."last_name", + "posthog_user"."is_staff", + "posthog_user"."is_active", + "posthog_user"."date_joined", + "posthog_user"."uuid", + "posthog_user"."current_organization_id", + "posthog_user"."current_team_id", + "posthog_user"."email", + "posthog_user"."pending_email", + "posthog_user"."temporary_token", + "posthog_user"."distinct_id", + "posthog_user"."is_email_verified", + "posthog_user"."requested_password_reset_at", + "posthog_user"."has_seen_product_intro_for", + "posthog_user"."strapi_id", + "posthog_user"."theme_mode", + "posthog_user"."partial_notification_settings", + "posthog_user"."anonymize_data", + "posthog_user"."toolbar_mode", + "posthog_user"."hedgehog_config", + "posthog_user"."events_column_config", + "posthog_user"."email_opt_in", + "posthog_datawarehousecredential"."created_by_id", + "posthog_datawarehousecredential"."created_at", + "posthog_datawarehousecredential"."id", + "posthog_datawarehousecredential"."access_key", + "posthog_datawarehousecredential"."access_secret", + "posthog_datawarehousecredential"."team_id", + "posthog_externaldatasource"."created_by_id", + "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", + "posthog_externaldatasource"."deleted", + "posthog_externaldatasource"."deleted_at", + "posthog_externaldatasource"."id", + "posthog_externaldatasource"."source_id", + "posthog_externaldatasource"."connection_id", + "posthog_externaldatasource"."destination_id", + "posthog_externaldatasource"."team_id", + "posthog_externaldatasource"."sync_frequency", + "posthog_externaldatasource"."status", + "posthog_externaldatasource"."source_type", + "posthog_externaldatasource"."job_inputs", + "posthog_externaldatasource"."are_tables_created", + "posthog_externaldatasource"."prefix" + FROM "posthog_datawarehousetable" + LEFT OUTER JOIN "posthog_user" ON ("posthog_datawarehousetable"."created_by_id" = "posthog_user"."id") + LEFT OUTER JOIN "posthog_datawarehousecredential" ON ("posthog_datawarehousetable"."credential_id" = "posthog_datawarehousecredential"."id") + LEFT OUTER JOIN "posthog_externaldatasource" ON ("posthog_datawarehousetable"."external_data_source_id" = "posthog_externaldatasource"."id") + WHERE ("posthog_datawarehousetable"."team_id" = 2 + AND NOT ("posthog_datawarehousetable"."deleted" + AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestErrorTrackingQueryRunner.test_fingerprints_with_null_characters.9 + ''' + SELECT "posthog_datawarehousesavedquery"."created_by_id", + "posthog_datawarehousesavedquery"."created_at", + "posthog_datawarehousesavedquery"."deleted", + "posthog_datawarehousesavedquery"."deleted_at", + "posthog_datawarehousesavedquery"."id", + "posthog_datawarehousesavedquery"."name", + "posthog_datawarehousesavedquery"."team_id", + "posthog_datawarehousesavedquery"."columns", + "posthog_datawarehousesavedquery"."external_tables", + "posthog_datawarehousesavedquery"."query", + "posthog_datawarehousesavedquery"."status", + "posthog_datawarehousesavedquery"."last_run_at" + FROM "posthog_datawarehousesavedquery" + WHERE ("posthog_datawarehousesavedquery"."team_id" = 2 + AND NOT ("posthog_datawarehousesavedquery"."deleted" + AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) + ''' +# --- # name: TestErrorTrackingQueryRunner.test_hogql_filters ''' SELECT count(DISTINCT events.uuid) AS occurrences, @@ -156,17 +458,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'email@posthog.com'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'email@posthog.com'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), equals(events.event, '$exception'), ifNull(equals(events__person.properties___email, 'email@posthog.com'), 0)) GROUP BY fingerprint LIMIT 101 @@ -199,11 +498,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), equals(events.event, '$exception'), and(less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2022-01-11 00:00:00.000000', 6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2022-01-10 00:00:00.000000', 6, 'UTC')), ifNull(notILike(events__person.properties___email, '%@posthog.com%'), 1)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_list'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_type'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_message'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0))) GROUP BY fingerprint LIMIT 101 @@ -236,11 +538,14 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN (SELECT person.id AS id, - argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), equals(events.event, '$exception'), ifNull(notILike(events__person.properties___email, '%@posthog.com%'), 1), and(or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_list'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_type'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_message'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_list'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_type'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_message'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0)))) GROUP BY fingerprint LIMIT 101 diff --git a/posthog/hogql_queries/test/test_query_runner.py b/posthog/hogql_queries/test/test_query_runner.py index 57dd961fbdb96..927930dad2da0 100644 --- a/posthog/hogql_queries/test/test_query_runner.py +++ b/posthog/hogql_queries/test/test_query_runner.py @@ -92,6 +92,8 @@ def test_cache_payload(self): "hogql_modifiers": { "inCohortVia": "auto", "materializationMode": "legacy_null_as_null", + "personsArgMaxVersion": "auto", + "optimizeJoinedFilters": False, "personsOnEventsMode": PersonsOnEventsMode.PERSON_ID_OVERRIDE_PROPERTIES_JOINED, "bounceRatePageViewMode": "count_pageviews", "sessionTableVersion": "auto", @@ -113,7 +115,7 @@ def test_cache_key(self): runner = TestQueryRunner(query={"some_attr": "bla"}, team=team) cache_key = runner.get_cache_key() - self.assertEqual(cache_key, "cache_f3537dabae0c3bf5ca038413fc1a0566") + self.assertEqual(cache_key, "cache_93427f8f06e6cc8643a394ae002de2c1") def test_cache_key_runner_subclass(self): TestQueryRunner = self.setup_test_query_runner_class() @@ -127,7 +129,7 @@ class TestSubclassQueryRunner(TestQueryRunner): runner = TestSubclassQueryRunner(query={"some_attr": "bla"}, team=team) cache_key = runner.get_cache_key() - self.assertEqual(cache_key, "cache_a56e8e639aba0d22f86b228ff44c5a65") + self.assertEqual(cache_key, "cache_bb6398a99867dfbdc45a2fc4fccb8f27") def test_cache_key_different_timezone(self): TestQueryRunner = self.setup_test_query_runner_class() @@ -138,7 +140,7 @@ def test_cache_key_different_timezone(self): runner = TestQueryRunner(query={"some_attr": "bla"}, team=team) cache_key = runner.get_cache_key() - self.assertEqual(cache_key, "cache_1c3b6a542b4a10f3c609df3c98968b5c") + self.assertEqual(cache_key, "cache_e0c2bb1ad091102533399ebdddbfb24d") @mock.patch("django.db.transaction.on_commit") def test_cache_response(self, mock_on_commit): diff --git a/posthog/models/person/util.py b/posthog/models/person/util.py index 7aa883c9bab68..4dbf3117a1a46 100644 --- a/posthog/models/person/util.py +++ b/posthog/models/person/util.py @@ -106,7 +106,7 @@ def bulk_create_persons(persons_list: list[dict]): distinct_id_inserts.append(f"('{distinct_id}', '{person.uuid}', {person.team_id}, 0, 0, now(), 0, 0)") person_mapping[distinct_id] = person - created_at = persons_list[index].get("created_at", now()).strftime("%Y-%m-%d %H:%M:%S.%f") + created_at = now().strftime("%Y-%m-%d %H:%M:%S.%f") timestamp = now().strftime("%Y-%m-%d %H:%M:%S") person_inserts.append( f"('{person.uuid}', '{created_at}', {person.team_id}, '{json.dumps(person.properties)}', {'1' if person.is_identified else '0'}, '{timestamp}', 0, 0, 0)" diff --git a/posthog/schema.py b/posthog/schema.py index 6653c3866f646..1ba777cd25b26 100644 --- a/posthog/schema.py +++ b/posthog/schema.py @@ -683,6 +683,12 @@ class MaterializationMode(StrEnum): DISABLED = "disabled" +class PersonsArgMaxVersion(StrEnum): + AUTO = "auto" + V1 = "v1" + V2 = "v2" + + class PersonsJoinMode(StrEnum): INNER = "inner" LEFT = "left" @@ -716,6 +722,8 @@ class HogQLQueryModifiers(BaseModel): debug: Optional[bool] = None inCohortVia: Optional[InCohortVia] = None materializationMode: Optional[MaterializationMode] = None + optimizeJoinedFilters: Optional[bool] = None + personsArgMaxVersion: Optional[PersonsArgMaxVersion] = None personsJoinMode: Optional[PersonsJoinMode] = None personsOnEventsMode: Optional[PersonsOnEventsMode] = None propertyGroupsMode: Optional[PropertyGroupsMode] = None diff --git a/posthog/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_filters.ambr b/posthog/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_filters.ambr index da84bbd8ed4b1..a0fc5699f9ee7 100644 --- a/posthog/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_filters.ambr +++ b/posthog/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_filters.ambr @@ -1472,17 +1472,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-31 20:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-13 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-21 20:00:00.000000', 6, 'UTC')), and(equals(events.event, '$pageview'), 1), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING hasAll(groupUniqArray(events.event), ['$pageview'])))) @@ -1528,17 +1525,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-31 20:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-13 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-21 20:00:00.000000', 6, 'UTC')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Chrome'), 0), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING 1))) @@ -1622,17 +1616,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.pmat_email, ''), 'null'), person.version) AS properties___email + (SELECT person.id AS id, nullIf(nullIf(person.pmat_email, ''), 'null') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 0)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-31 20:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-13 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-21 20:00:00.000000', 6, 'UTC')), and(equals(events.event, '$pageview'), 1), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING hasAll(groupUniqArray(events.event), ['$pageview'])))) @@ -1678,17 +1669,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.pmat_email, ''), 'null'), person.version) AS properties___email + (SELECT person.id AS id, nullIf(nullIf(person.pmat_email, ''), 'null') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 0)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-31 20:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-13 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-21 20:00:00.000000', 6, 'UTC')), ifNull(equals(nullIf(nullIf(events.`mat_$browser`, ''), 'null'), 'Chrome'), 0), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING 1))) @@ -1734,17 +1722,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), and(equals(events.event, '$pageview'), ifNull(equals(events__person.properties___email, 'bla'), 0))) GROUP BY events.`$session_id` HAVING hasAll(groupUniqArray(events.event), ['$pageview'])))) @@ -1790,17 +1775,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'something else'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'something else'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), and(equals(events.event, '$pageview'), ifNull(equals(events__person.properties___email, 'something else'), 0))) GROUP BY events.`$session_id` HAVING hasAll(groupUniqArray(events.event), ['$pageview'])))) @@ -2378,11 +2360,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-31 20:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-13 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-21 20:00:00.000000', 6, 'UTC')), and(equals(events.event, '$pageview'), 1), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'is_internal_user'), ''), 'null'), '^"|"$', ''), 'false'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Chrome'), 0)), ifNull(notILike(events__person.properties___email, '%@posthog.com%'), 1)) GROUP BY events.`$session_id` HAVING hasAll(groupUniqArray(events.event), ['$pageview'])))) @@ -2466,11 +2451,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.pmat_email, ''), 'null'), person.version) AS properties___email + (SELECT person.id AS id, nullIf(nullIf(person.pmat_email, ''), 'null') AS properties___email FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-31 20:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-13 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-21 20:00:00.000000', 6, 'UTC')), and(equals(events.event, '$pageview'), 1), and(ifNull(equals(nullIf(nullIf(events.mat_is_internal_user, ''), 'null'), 'false'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$browser'), ''), 'null'), '^"|"$', ''), 'Chrome'), 0)), ifNull(notILike(events__person.properties___email, '%@posthog.com%'), 1)) GROUP BY events.`$session_id` HAVING hasAll(groupUniqArray(events.event), ['$pageview'])))) @@ -3345,17 +3333,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla@gmail.com'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla@gmail.com'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), ifNull(equals(events__person.properties___email, 'bla@gmail.com'), 0)) GROUP BY events.`$session_id` HAVING 1))) @@ -3401,11 +3386,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE equals(person.team_id, 2) - 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), ifNull(notILike(events__person.properties___email, '%gmail.com%'), 1)) GROUP BY events.`$session_id` HAVING 1))) @@ -4187,17 +4175,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'test@posthog.com'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'david@posthog.com'), 0))))), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'test@posthog.com'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'david@posthog.com'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), and(ifNull(equals(events__person.properties___email, 'test@posthog.com'), 0), ifNull(equals(events__person.properties___email, 'david@posthog.com'), 0))) GROUP BY events.`$session_id` HAVING 1))) @@ -4243,17 +4228,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), or(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'test@posthog.com'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'david@posthog.com'), 0))))), or(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'test@posthog.com'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'david@posthog.com'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-11 13:46:23.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-24 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-01 13:46:23.000000', 6, 'UTC')), or(ifNull(equals(events__person.properties___email, 'test@posthog.com'), 0), ifNull(equals(events__person.properties___email, 'david@posthog.com'), 0))) GROUP BY events.`$session_id` HAVING 1))) @@ -5086,17 +5068,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-31 20:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-13 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-21 20:00:00.000000', 6, 'UTC')), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING 1))) @@ -5180,17 +5159,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.pmat_email, ''), 'null'), person.version) AS properties___email + (SELECT person.id AS id, nullIf(nullIf(person.pmat_email, ''), 'null') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 0)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-31 20:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-13 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-21 20:00:00.000000', 6, 'UTC')), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING 1))) @@ -5274,17 +5250,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), person.version) AS properties___email + (SELECT person.id AS id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla'), 0)))), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', ''), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-31 20:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-13 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-21 20:00:00.000000', 6, 'UTC')), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING 1))) @@ -5368,17 +5341,14 @@ GROUP BY person_distinct_id_overrides.distinct_id HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) LEFT JOIN - (SELECT person.id AS id, argMax(nullIf(nullIf(person.pmat_email, ''), 'null'), person.version) AS properties___email + (SELECT person.id AS id, nullIf(nullIf(person.pmat_email, ''), 'null') AS properties___email FROM person - WHERE and(equals(person.team_id, 2), in(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), notIn(person.id, - (SELECT person.id AS id - FROM person - WHERE and(equals(person.team_id, 2), equals(person.is_deleted, 1)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 0)))), ifNull(equals(nullIf(nullIf(person.pmat_email, ''), 'null'), 'bla'), 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)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) + WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version), + (SELECT person.id AS id, max(person.version) AS version + FROM person + WHERE equals(person.team_id, 2) + 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)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id) WHERE and(equals(events.team_id, 2), notEmpty(events.`$session_id`), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-12-31 20:00:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), now64(6, 'UTC')), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-13 23:58:00.000000', 6, 'UTC')), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2021-01-21 20:00:00.000000', 6, 'UTC')), ifNull(equals(events__person.properties___email, 'bla'), 0)) GROUP BY events.`$session_id` HAVING 1))) diff --git a/posthog/session_recordings/session_recording_api.py b/posthog/session_recordings/session_recording_api.py index f35bf02dc16d6..c51d3105cadc7 100644 --- a/posthog/session_recordings/session_recording_api.py +++ b/posthog/session_recordings/session_recording_api.py @@ -32,7 +32,7 @@ from posthog.cloud_utils import is_cloud from posthog.constants import SESSION_RECORDINGS_FILTER_IDS from posthog.event_usage import report_user_action -from posthog.models import User +from posthog.models import Team, User from posthog.models.filters.session_recordings_filter import SessionRecordingsFilter from posthog.models.person.person import PersonDistinctId from posthog.rate_limit import ( @@ -40,7 +40,7 @@ ClickHouseSustainedRateThrottle, PersonalApiKeyRateThrottle, ) -from posthog.schema import QueryTiming +from posthog.schema import HogQLQueryModifiers, QueryTiming from posthog.session_recordings.models.session_recording import SessionRecording from posthog.session_recordings.models.session_recording_event import ( SessionRecordingViewed, @@ -347,8 +347,10 @@ def matching_events(self, request: request.Request, *args: Any, **kwargs: Any) - "Must specify at least one event or action filter", ) + distinct_id = str(cast(User, request.user).distinct_id) + modifiers = safely_read_modifiers_overrides(distinct_id, self.team) matching_events_query_response = ReplayFiltersEventsSubQuery( - filter=filter, team=self.team + filter=filter, team=self.team, hogql_query_modifiers=modifiers ).get_event_ids_for_session() response = JsonResponse(data={"results": matching_events_query_response.results}) @@ -905,9 +907,12 @@ def list_recordings( filter = filter.shallow_clone({SESSION_RECORDINGS_FILTER_IDS: remaining_session_ids}) if (all_session_ids and filter.session_ids) or not all_session_ids: + distinct_id = str(cast(User, request.user).distinct_id) + modifiers = safely_read_modifiers_overrides(distinct_id, team) + with timer("load_recordings_from_hogql"): (ch_session_recordings, more_recordings_available, hogql_timings) = SessionRecordingListFromFilters( - filter=filter, team=team, hogql_query_modifiers=None + filter=filter, team=team, hogql_query_modifiers=modifiers ).run() with timer("build_recordings"): @@ -963,6 +968,32 @@ def list_recordings( ) +def safely_read_modifiers_overrides(distinct_id: str, team: Team) -> HogQLQueryModifiers: + modifiers = HogQLQueryModifiers() + + try: + groups = {"organization": str(team.organization.id)} + flag_key = "HOG_QL_ORG_QUERY_OVERRIDES" + flags_n_bags = posthoganalytics.get_all_flags_and_payloads( + distinct_id, + groups=groups, + ) + # this loads nothing whereas the payload is available + # modifier_overrides = posthoganalytics.get_feature_flag_payload( + # flag_key, + # distinct_id, + # groups=groups, + # ) + modifier_overrides = (flags_n_bags or {}).get("featureFlagPayloads", {}).get(flag_key, None) + if modifier_overrides: + modifiers.optimizeJoinedFilters = json.loads(modifier_overrides).get("optimizeJoinedFilters", None) + except: + # be extra safe + pass + + return modifiers + + def _generate_timings(hogql_timings: list[QueryTiming] | None, timer: ServerTimingsGathered) -> dict[str, float]: timings_dict = timer.get_all_timings() hogql_timings_dict = {} diff --git a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr index 1ca5bd059f6bb..550009ec55f1c 100644 --- a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr +++ b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr @@ -595,6 +595,32 @@ ''' # --- # name: TestSessionRecordings.test_get_session_recordings.20 + ''' + SELECT "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_get_session_recordings.21 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -606,7 +632,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_get_session_recordings.21 +# name: TestSessionRecordings.test_get_session_recordings.22 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -627,7 +653,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_get_session_recordings.22 +# name: TestSessionRecordings.test_get_session_recordings.23 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -700,7 +726,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_get_session_recordings.23 +# name: TestSessionRecordings.test_get_session_recordings.24 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -719,7 +745,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_get_session_recordings.24 +# name: TestSessionRecordings.test_get_session_recordings.25 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -731,7 +757,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_get_session_recordings.25 +# name: TestSessionRecordings.test_get_session_recordings.26 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -752,7 +778,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_get_session_recordings.26 +# name: TestSessionRecordings.test_get_session_recordings.27 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -825,7 +851,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_get_session_recordings.27 +# name: TestSessionRecordings.test_get_session_recordings.28 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -844,7 +870,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_get_session_recordings.28 +# name: TestSessionRecordings.test_get_session_recordings.29 ''' SELECT "posthog_sessionrecording"."id", "posthog_sessionrecording"."session_id", @@ -872,14 +898,6 @@ AND "posthog_sessionrecording"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_get_session_recordings.29 - ''' - SELECT "posthog_sessionrecordingviewed"."session_id" - FROM "posthog_sessionrecordingviewed" - WHERE ("posthog_sessionrecordingviewed"."team_id" = 2 - AND "posthog_sessionrecordingviewed"."user_id" = 2) - ''' -# --- # name: TestSessionRecordings.test_get_session_recordings.3 ''' SELECT "posthog_team"."id", @@ -948,26 +966,10 @@ # --- # name: TestSessionRecordings.test_get_session_recordings.30 ''' - SELECT "posthog_persondistinctid"."id", - "posthog_persondistinctid"."team_id", - "posthog_persondistinctid"."person_id", - "posthog_persondistinctid"."distinct_id", - "posthog_persondistinctid"."version", - "posthog_person"."id", - "posthog_person"."created_at", - "posthog_person"."properties_last_updated_at", - "posthog_person"."properties_last_operation", - "posthog_person"."team_id", - "posthog_person"."properties", - "posthog_person"."is_user_id", - "posthog_person"."is_identified", - "posthog_person"."uuid", - "posthog_person"."version" - FROM "posthog_persondistinctid" - INNER JOIN "posthog_person" ON ("posthog_persondistinctid"."person_id" = "posthog_person"."id") - WHERE ("posthog_persondistinctid"."distinct_id" IN ('user2', - 'user_one_0') - AND "posthog_persondistinctid"."team_id" = 2) + SELECT "posthog_sessionrecordingviewed"."session_id" + FROM "posthog_sessionrecordingviewed" + WHERE ("posthog_sessionrecordingviewed"."team_id" = 2 + AND "posthog_sessionrecordingviewed"."user_id" = 2) ''' # --- # name: TestSessionRecordings.test_get_session_recordings.31 @@ -1483,26 +1485,21 @@ # --- # name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.10 ''' - SELECT "posthog_datawarehousejoin"."created_by_id", - "posthog_datawarehousejoin"."created_at", - "posthog_datawarehousejoin"."deleted", - "posthog_datawarehousejoin"."deleted_at", - "posthog_datawarehousejoin"."id", - "posthog_datawarehousejoin"."team_id", - "posthog_datawarehousejoin"."source_table_name", - "posthog_datawarehousejoin"."source_table_key", - "posthog_datawarehousejoin"."joining_table_name", - "posthog_datawarehousejoin"."joining_table_key", - "posthog_datawarehousejoin"."field_name" - FROM "posthog_datawarehousejoin" - WHERE ("posthog_datawarehousejoin"."team_id" = 2 - AND NOT ("posthog_datawarehousejoin"."deleted" - AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.100 - ''' - SELECT "posthog_user"."id", + SELECT "posthog_datawarehousetable"."created_by_id", + "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", + "posthog_datawarehousetable"."deleted", + "posthog_datawarehousetable"."deleted_at", + "posthog_datawarehousetable"."id", + "posthog_datawarehousetable"."name", + "posthog_datawarehousetable"."format", + "posthog_datawarehousetable"."team_id", + "posthog_datawarehousetable"."url_pattern", + "posthog_datawarehousetable"."credential_id", + "posthog_datawarehousetable"."external_data_source_id", + "posthog_datawarehousetable"."columns", + "posthog_datawarehousetable"."row_count", + "posthog_user"."id", "posthog_user"."password", "posthog_user"."last_login", "posthog_user"."first_name", @@ -1517,6 +1514,7 @@ "posthog_user"."temporary_token", "posthog_user"."distinct_id", "posthog_user"."is_email_verified", + "posthog_user"."requested_password_reset_at", "posthog_user"."has_seen_product_intro_for", "posthog_user"."strapi_id", "posthog_user"."is_active", @@ -1526,13 +1524,105 @@ "posthog_user"."toolbar_mode", "posthog_user"."hedgehog_config", "posthog_user"."events_column_config", - "posthog_user"."email_opt_in" - FROM "posthog_user" - WHERE "posthog_user"."id" = 2 - LIMIT 21 + "posthog_user"."email_opt_in", + "posthog_datawarehousecredential"."created_by_id", + "posthog_datawarehousecredential"."created_at", + "posthog_datawarehousecredential"."id", + "posthog_datawarehousecredential"."access_key", + "posthog_datawarehousecredential"."access_secret", + "posthog_datawarehousecredential"."team_id", + "posthog_externaldatasource"."created_by_id", + "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", + "posthog_externaldatasource"."deleted", + "posthog_externaldatasource"."deleted_at", + "posthog_externaldatasource"."id", + "posthog_externaldatasource"."source_id", + "posthog_externaldatasource"."connection_id", + "posthog_externaldatasource"."destination_id", + "posthog_externaldatasource"."team_id", + "posthog_externaldatasource"."sync_frequency", + "posthog_externaldatasource"."status", + "posthog_externaldatasource"."source_type", + "posthog_externaldatasource"."job_inputs", + "posthog_externaldatasource"."are_tables_created", + "posthog_externaldatasource"."prefix" + FROM "posthog_datawarehousetable" + LEFT OUTER JOIN "posthog_user" ON ("posthog_datawarehousetable"."created_by_id" = "posthog_user"."id") + LEFT OUTER JOIN "posthog_datawarehousecredential" ON ("posthog_datawarehousetable"."credential_id" = "posthog_datawarehousecredential"."id") + LEFT OUTER JOIN "posthog_externaldatasource" ON ("posthog_datawarehousetable"."external_data_source_id" = "posthog_externaldatasource"."id") + WHERE ("posthog_datawarehousetable"."team_id" = 2 + AND NOT ("posthog_datawarehousetable"."deleted" + AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.100 + ''' + SELECT "posthog_sessionrecording"."id", + "posthog_sessionrecording"."session_id", + "posthog_sessionrecording"."team_id", + "posthog_sessionrecording"."created_at", + "posthog_sessionrecording"."deleted", + "posthog_sessionrecording"."object_storage_path", + "posthog_sessionrecording"."distinct_id", + "posthog_sessionrecording"."duration", + "posthog_sessionrecording"."active_seconds", + "posthog_sessionrecording"."inactive_seconds", + "posthog_sessionrecording"."start_time", + "posthog_sessionrecording"."end_time", + "posthog_sessionrecording"."click_count", + "posthog_sessionrecording"."keypress_count", + "posthog_sessionrecording"."mouse_activity_count", + "posthog_sessionrecording"."console_log_count", + "posthog_sessionrecording"."console_warn_count", + "posthog_sessionrecording"."console_error_count", + "posthog_sessionrecording"."start_url", + "posthog_sessionrecording"."storage_version" + FROM "posthog_sessionrecording" + WHERE ("posthog_sessionrecording"."session_id" IN ('1', + '2', + '3', + '4', + '5') + AND "posthog_sessionrecording"."team_id" = 2) ''' # --- # name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.101 + ''' + SELECT "posthog_sessionrecordingviewed"."session_id" + FROM "posthog_sessionrecordingviewed" + WHERE ("posthog_sessionrecordingviewed"."team_id" = 2 + AND "posthog_sessionrecordingviewed"."user_id" = 2) + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.102 + ''' + SELECT "posthog_persondistinctid"."id", + "posthog_persondistinctid"."team_id", + "posthog_persondistinctid"."person_id", + "posthog_persondistinctid"."distinct_id", + "posthog_persondistinctid"."version", + "posthog_person"."id", + "posthog_person"."created_at", + "posthog_person"."properties_last_updated_at", + "posthog_person"."properties_last_operation", + "posthog_person"."team_id", + "posthog_person"."properties", + "posthog_person"."is_user_id", + "posthog_person"."is_identified", + "posthog_person"."uuid", + "posthog_person"."version" + FROM "posthog_persondistinctid" + INNER JOIN "posthog_person" ON ("posthog_persondistinctid"."person_id" = "posthog_person"."id") + WHERE ("posthog_persondistinctid"."distinct_id" IN ('user1', + 'user2', + 'user3', + 'user4', + 'user5') + AND "posthog_persondistinctid"."team_id" = 2) + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.103 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -1584,6 +1674,13 @@ "posthog_team"."modifiers", "posthog_team"."correlation_config", "posthog_team"."session_recording_retention_period_days", + "posthog_team"."plugins_opt_in", + "posthog_team"."opt_out_capture", + "posthog_team"."event_names", + "posthog_team"."event_names_with_usage", + "posthog_team"."event_properties", + "posthog_team"."event_properties_with_usage", + "posthog_team"."event_properties_numerical", "posthog_team"."external_data_workspace_id", "posthog_team"."external_data_workspace_last_synced_at" FROM "posthog_team" @@ -1591,51 +1688,225 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.102 - ''' - SELECT "posthog_organizationmembership"."id", - "posthog_organizationmembership"."organization_id", - "posthog_organizationmembership"."user_id", - "posthog_organizationmembership"."level", - "posthog_organizationmembership"."joined_at", - "posthog_organizationmembership"."updated_at", - "posthog_organization"."id", - "posthog_organization"."name", - "posthog_organization"."slug", - "posthog_organization"."logo_media_id", - "posthog_organization"."created_at", - "posthog_organization"."updated_at", - "posthog_organization"."plugins_access_level", - "posthog_organization"."for_internal_metrics", - "posthog_organization"."is_member_join_email_enabled", - "posthog_organization"."enforce_2fa", - "posthog_organization"."is_hipaa", - "posthog_organization"."customer_id", - "posthog_organization"."available_product_features", - "posthog_organization"."usage", - "posthog_organization"."never_drop_data", - "posthog_organization"."customer_trust_scores", - "posthog_organization"."setup_section_2_completed", - "posthog_organization"."personalization", - "posthog_organization"."domain_whitelist" - FROM "posthog_organizationmembership" - INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id") - WHERE "posthog_organizationmembership"."user_id" = 2 - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.103 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.104 ''' - SELECT "posthog_grouptypemapping"."id", - "posthog_grouptypemapping"."team_id", - "posthog_grouptypemapping"."group_type", - "posthog_grouptypemapping"."group_type_index", - "posthog_grouptypemapping"."name_singular", - "posthog_grouptypemapping"."name_plural" - FROM "posthog_grouptypemapping" - WHERE "posthog_grouptypemapping"."team_id" = 2 + SELECT "posthog_person"."id", + "posthog_person"."created_at", + "posthog_person"."properties_last_updated_at", + "posthog_person"."properties_last_operation", + "posthog_person"."team_id", + "posthog_person"."properties", + "posthog_person"."is_user_id", + "posthog_person"."is_identified", + "posthog_person"."uuid", + "posthog_person"."version" + FROM "posthog_person" + INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") + WHERE ("posthog_persondistinctid"."distinct_id" = 'user6' + AND "posthog_persondistinctid"."team_id" = 2) + LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.104 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.105 + ''' + SELECT "posthog_person"."id", + "posthog_person"."created_at", + "posthog_person"."properties_last_updated_at", + "posthog_person"."properties_last_operation", + "posthog_person"."team_id", + "posthog_person"."properties", + "posthog_person"."is_user_id", + "posthog_person"."is_identified", + "posthog_person"."uuid", + "posthog_person"."version" + FROM "posthog_person" + INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") + WHERE ("posthog_persondistinctid"."distinct_id" = 'user6' + AND "posthog_persondistinctid"."team_id" = 2) + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.106 + ''' + SELECT "posthog_user"."id", + "posthog_user"."password", + "posthog_user"."last_login", + "posthog_user"."first_name", + "posthog_user"."last_name", + "posthog_user"."is_staff", + "posthog_user"."date_joined", + "posthog_user"."uuid", + "posthog_user"."current_organization_id", + "posthog_user"."current_team_id", + "posthog_user"."email", + "posthog_user"."pending_email", + "posthog_user"."temporary_token", + "posthog_user"."distinct_id", + "posthog_user"."is_email_verified", + "posthog_user"."has_seen_product_intro_for", + "posthog_user"."strapi_id", + "posthog_user"."is_active", + "posthog_user"."theme_mode", + "posthog_user"."partial_notification_settings", + "posthog_user"."anonymize_data", + "posthog_user"."toolbar_mode", + "posthog_user"."hedgehog_config", + "posthog_user"."events_column_config", + "posthog_user"."email_opt_in" + FROM "posthog_user" + WHERE "posthog_user"."id" = 2 + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.107 + ''' + SELECT "posthog_team"."id", + "posthog_team"."uuid", + "posthog_team"."organization_id", + "posthog_team"."project_id", + "posthog_team"."api_token", + "posthog_team"."app_urls", + "posthog_team"."name", + "posthog_team"."slack_incoming_webhook", + "posthog_team"."created_at", + "posthog_team"."updated_at", + "posthog_team"."anonymize_ips", + "posthog_team"."completed_snippet_onboarding", + "posthog_team"."has_completed_onboarding_for", + "posthog_team"."ingested_event", + "posthog_team"."autocapture_opt_out", + "posthog_team"."autocapture_web_vitals_opt_in", + "posthog_team"."autocapture_web_vitals_allowed_metrics", + "posthog_team"."autocapture_exceptions_opt_in", + "posthog_team"."autocapture_exceptions_errors_to_ignore", + "posthog_team"."session_recording_opt_in", + "posthog_team"."session_recording_sample_rate", + "posthog_team"."session_recording_minimum_duration_milliseconds", + "posthog_team"."session_recording_linked_flag", + "posthog_team"."session_recording_network_payload_capture_config", + "posthog_team"."session_recording_url_trigger_config", + "posthog_team"."session_replay_config", + "posthog_team"."survey_config", + "posthog_team"."capture_console_log_opt_in", + "posthog_team"."capture_performance_opt_in", + "posthog_team"."surveys_opt_in", + "posthog_team"."heatmaps_opt_in", + "posthog_team"."session_recording_version", + "posthog_team"."signup_token", + "posthog_team"."is_demo", + "posthog_team"."access_control", + "posthog_team"."week_start_day", + "posthog_team"."inject_web_apps", + "posthog_team"."test_account_filters", + "posthog_team"."test_account_filters_default_checked", + "posthog_team"."path_cleaning_filters", + "posthog_team"."timezone", + "posthog_team"."data_attributes", + "posthog_team"."person_display_name_properties", + "posthog_team"."live_events_columns", + "posthog_team"."recording_domains", + "posthog_team"."primary_dashboard_id", + "posthog_team"."extra_settings", + "posthog_team"."modifiers", + "posthog_team"."correlation_config", + "posthog_team"."session_recording_retention_period_days", + "posthog_team"."external_data_workspace_id", + "posthog_team"."external_data_workspace_last_synced_at" + FROM "posthog_team" + WHERE "posthog_team"."id" = 2 + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.108 + ''' + SELECT "posthog_organizationmembership"."id", + "posthog_organizationmembership"."organization_id", + "posthog_organizationmembership"."user_id", + "posthog_organizationmembership"."level", + "posthog_organizationmembership"."joined_at", + "posthog_organizationmembership"."updated_at", + "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organizationmembership" + INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id") + WHERE "posthog_organizationmembership"."user_id" = 2 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.109 + ''' + SELECT "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.11 + ''' + SELECT "posthog_datawarehousejoin"."created_by_id", + "posthog_datawarehousejoin"."created_at", + "posthog_datawarehousejoin"."deleted", + "posthog_datawarehousejoin"."deleted_at", + "posthog_datawarehousejoin"."id", + "posthog_datawarehousejoin"."team_id", + "posthog_datawarehousejoin"."source_table_name", + "posthog_datawarehousejoin"."source_table_key", + "posthog_datawarehousejoin"."joining_table_name", + "posthog_datawarehousejoin"."joining_table_key", + "posthog_datawarehousejoin"."field_name" + FROM "posthog_datawarehousejoin" + WHERE ("posthog_datawarehousejoin"."team_id" = 2 + AND NOT ("posthog_datawarehousejoin"."deleted" + AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.110 + ''' + SELECT "posthog_grouptypemapping"."id", + "posthog_grouptypemapping"."team_id", + "posthog_grouptypemapping"."group_type", + "posthog_grouptypemapping"."group_type_index", + "posthog_grouptypemapping"."name_singular", + "posthog_grouptypemapping"."name_plural" + FROM "posthog_grouptypemapping" + WHERE "posthog_grouptypemapping"."team_id" = 2 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.111 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -1656,7 +1927,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.105 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.112 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -1729,7 +2000,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.106 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.113 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -1748,7 +2019,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.107 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.114 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -1760,7 +2031,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.108 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.115 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -1781,7 +2052,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.109 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.116 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -1854,15 +2125,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.11 - ''' - SELECT "posthog_sessionrecordingviewed"."session_id" - FROM "posthog_sessionrecordingviewed" - WHERE ("posthog_sessionrecordingviewed"."team_id" = 2 - AND "posthog_sessionrecordingviewed"."user_id" = 2) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.110 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.117 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -1881,7 +2144,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.111 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.118 ''' SELECT "posthog_sessionrecording"."id", "posthog_sessionrecording"."session_id", @@ -1913,7 +2176,7 @@ AND "posthog_sessionrecording"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.112 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.119 ''' SELECT "posthog_sessionrecordingviewed"."session_id" FROM "posthog_sessionrecordingviewed" @@ -1921,7 +2184,15 @@ AND "posthog_sessionrecordingviewed"."user_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.113 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.12 + ''' + SELECT "posthog_sessionrecordingviewed"."session_id" + FROM "posthog_sessionrecordingviewed" + WHERE ("posthog_sessionrecordingviewed"."team_id" = 2 + AND "posthog_sessionrecordingviewed"."user_id" = 2) + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.120 ''' SELECT "posthog_persondistinctid"."id", "posthog_persondistinctid"."team_id", @@ -1949,7 +2220,7 @@ AND "posthog_persondistinctid"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.114 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.121 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -2015,7 +2286,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.115 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.122 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -2034,7 +2305,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.116 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.123 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -2053,7 +2324,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.117 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.124 ''' SELECT "posthog_user"."id", "posthog_user"."password", @@ -2085,7 +2356,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.118 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.125 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -2144,7 +2415,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.119 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.126 ''' SELECT "posthog_organizationmembership"."id", "posthog_organizationmembership"."organization_id", @@ -2176,7 +2447,66 @@ WHERE "posthog_organizationmembership"."user_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.12 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.127 + ''' + SELECT "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.128 + ''' + SELECT "posthog_grouptypemapping"."id", + "posthog_grouptypemapping"."team_id", + "posthog_grouptypemapping"."group_type", + "posthog_grouptypemapping"."group_type_index", + "posthog_grouptypemapping"."name_singular", + "posthog_grouptypemapping"."name_plural" + FROM "posthog_grouptypemapping" + WHERE "posthog_grouptypemapping"."team_id" = 2 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.129 + ''' + SELECT "posthog_datawarehousesavedquery"."created_by_id", + "posthog_datawarehousesavedquery"."created_at", + "posthog_datawarehousesavedquery"."deleted", + "posthog_datawarehousesavedquery"."deleted_at", + "posthog_datawarehousesavedquery"."id", + "posthog_datawarehousesavedquery"."name", + "posthog_datawarehousesavedquery"."team_id", + "posthog_datawarehousesavedquery"."columns", + "posthog_datawarehousesavedquery"."external_tables", + "posthog_datawarehousesavedquery"."query", + "posthog_datawarehousesavedquery"."status", + "posthog_datawarehousesavedquery"."last_run_at", + "posthog_datawarehousesavedquery"."table_id" + FROM "posthog_datawarehousesavedquery" + WHERE ("posthog_datawarehousesavedquery"."team_id" = 2 + AND NOT ("posthog_datawarehousesavedquery"."deleted" + AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.13 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -2242,40 +2572,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.120 - ''' - SELECT "posthog_grouptypemapping"."id", - "posthog_grouptypemapping"."team_id", - "posthog_grouptypemapping"."group_type", - "posthog_grouptypemapping"."group_type_index", - "posthog_grouptypemapping"."name_singular", - "posthog_grouptypemapping"."name_plural" - FROM "posthog_grouptypemapping" - WHERE "posthog_grouptypemapping"."team_id" = 2 - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.121 - ''' - SELECT "posthog_datawarehousesavedquery"."created_by_id", - "posthog_datawarehousesavedquery"."created_at", - "posthog_datawarehousesavedquery"."deleted", - "posthog_datawarehousesavedquery"."deleted_at", - "posthog_datawarehousesavedquery"."id", - "posthog_datawarehousesavedquery"."name", - "posthog_datawarehousesavedquery"."team_id", - "posthog_datawarehousesavedquery"."columns", - "posthog_datawarehousesavedquery"."external_tables", - "posthog_datawarehousesavedquery"."query", - "posthog_datawarehousesavedquery"."status", - "posthog_datawarehousesavedquery"."last_run_at", - "posthog_datawarehousesavedquery"."table_id" - FROM "posthog_datawarehousesavedquery" - WHERE ("posthog_datawarehousesavedquery"."team_id" = 2 - AND NOT ("posthog_datawarehousesavedquery"."deleted" - AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.122 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.130 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -2348,7 +2645,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.123 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.131 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -2367,7 +2664,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.124 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.132 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -2379,7 +2676,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.125 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.133 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -2400,7 +2697,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.126 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.134 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -2473,7 +2770,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.127 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.135 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -2492,7 +2789,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.128 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.136 ''' SELECT "posthog_sessionrecording"."id", "posthog_sessionrecording"."session_id", @@ -2525,7 +2822,7 @@ AND "posthog_sessionrecording"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.129 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.137 ''' SELECT "posthog_sessionrecordingviewed"."session_id" FROM "posthog_sessionrecordingviewed" @@ -2533,26 +2830,7 @@ AND "posthog_sessionrecordingviewed"."user_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.13 - ''' - SELECT "posthog_person"."id", - "posthog_person"."created_at", - "posthog_person"."properties_last_updated_at", - "posthog_person"."properties_last_operation", - "posthog_person"."team_id", - "posthog_person"."properties", - "posthog_person"."is_user_id", - "posthog_person"."is_identified", - "posthog_person"."uuid", - "posthog_person"."version" - FROM "posthog_person" - INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") - WHERE ("posthog_persondistinctid"."distinct_id" = 'user1' - AND "posthog_persondistinctid"."team_id" = 2) - LIMIT 21 - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.130 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.138 ''' SELECT "posthog_persondistinctid"."id", "posthog_persondistinctid"."team_id", @@ -2581,7 +2859,7 @@ AND "posthog_persondistinctid"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.131 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.139 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -2647,7 +2925,26 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.132 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.14 + ''' + SELECT "posthog_person"."id", + "posthog_person"."created_at", + "posthog_person"."properties_last_updated_at", + "posthog_person"."properties_last_operation", + "posthog_person"."team_id", + "posthog_person"."properties", + "posthog_person"."is_user_id", + "posthog_person"."is_identified", + "posthog_person"."uuid", + "posthog_person"."version" + FROM "posthog_person" + INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") + WHERE ("posthog_persondistinctid"."distinct_id" = 'user1' + AND "posthog_persondistinctid"."team_id" = 2) + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.140 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -2666,7 +2963,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.133 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.141 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -2685,7 +2982,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.134 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.142 ''' SELECT "posthog_user"."id", "posthog_user"."password", @@ -2717,7 +3014,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.135 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.143 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -2776,7 +3073,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.136 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.144 ''' SELECT "posthog_organizationmembership"."id", "posthog_organizationmembership"."organization_id", @@ -2808,7 +3105,33 @@ WHERE "posthog_organizationmembership"."user_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.137 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.145 + ''' + SELECT "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.146 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -2820,7 +3143,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.138 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.147 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -2841,7 +3164,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.139 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.148 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -2914,26 +3237,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.14 - ''' - SELECT "posthog_person"."id", - "posthog_person"."created_at", - "posthog_person"."properties_last_updated_at", - "posthog_person"."properties_last_operation", - "posthog_person"."team_id", - "posthog_person"."properties", - "posthog_person"."is_user_id", - "posthog_person"."is_identified", - "posthog_person"."uuid", - "posthog_person"."version" - FROM "posthog_person" - INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") - WHERE ("posthog_persondistinctid"."distinct_id" = 'user1' - AND "posthog_persondistinctid"."team_id" = 2) - LIMIT 21 - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.140 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.149 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -2952,7 +3256,26 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.141 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.15 + ''' + SELECT "posthog_person"."id", + "posthog_person"."created_at", + "posthog_person"."properties_last_updated_at", + "posthog_person"."properties_last_operation", + "posthog_person"."team_id", + "posthog_person"."properties", + "posthog_person"."is_user_id", + "posthog_person"."is_identified", + "posthog_person"."uuid", + "posthog_person"."version" + FROM "posthog_person" + INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") + WHERE ("posthog_persondistinctid"."distinct_id" = 'user1' + AND "posthog_persondistinctid"."team_id" = 2) + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.150 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -2964,7 +3287,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.142 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.151 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -2985,7 +3308,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.143 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.152 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -3058,7 +3381,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.144 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.153 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -3077,7 +3400,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.145 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.154 ''' SELECT "posthog_sessionrecording"."id", "posthog_sessionrecording"."session_id", @@ -3111,7 +3434,7 @@ AND "posthog_sessionrecording"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.146 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.155 ''' SELECT "posthog_sessionrecordingviewed"."session_id" FROM "posthog_sessionrecordingviewed" @@ -3119,7 +3442,7 @@ AND "posthog_sessionrecordingviewed"."user_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.147 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.156 ''' SELECT "posthog_persondistinctid"."id", "posthog_persondistinctid"."team_id", @@ -3149,7 +3472,7 @@ AND "posthog_persondistinctid"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.148 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.157 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -3215,7 +3538,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.149 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.158 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -3234,13 +3557,32 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.15 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.159 ''' - SELECT "posthog_user"."id", - "posthog_user"."password", - "posthog_user"."last_login", - "posthog_user"."first_name", - "posthog_user"."last_name", + SELECT "posthog_person"."id", + "posthog_person"."created_at", + "posthog_person"."properties_last_updated_at", + "posthog_person"."properties_last_operation", + "posthog_person"."team_id", + "posthog_person"."properties", + "posthog_person"."is_user_id", + "posthog_person"."is_identified", + "posthog_person"."uuid", + "posthog_person"."version" + FROM "posthog_person" + INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") + WHERE ("posthog_persondistinctid"."distinct_id" = 'user9' + AND "posthog_persondistinctid"."team_id" = 2) + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.16 + ''' + SELECT "posthog_user"."id", + "posthog_user"."password", + "posthog_user"."last_login", + "posthog_user"."first_name", + "posthog_user"."last_name", "posthog_user"."is_staff", "posthog_user"."date_joined", "posthog_user"."uuid", @@ -3266,26 +3608,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.150 - ''' - SELECT "posthog_person"."id", - "posthog_person"."created_at", - "posthog_person"."properties_last_updated_at", - "posthog_person"."properties_last_operation", - "posthog_person"."team_id", - "posthog_person"."properties", - "posthog_person"."is_user_id", - "posthog_person"."is_identified", - "posthog_person"."uuid", - "posthog_person"."version" - FROM "posthog_person" - INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") - WHERE ("posthog_persondistinctid"."distinct_id" = 'user9' - AND "posthog_persondistinctid"."team_id" = 2) - LIMIT 21 - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.151 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.160 ''' SELECT "posthog_user"."id", "posthog_user"."password", @@ -3317,7 +3640,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.152 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.161 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -3376,7 +3699,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.153 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.162 ''' SELECT "posthog_organizationmembership"."id", "posthog_organizationmembership"."organization_id", @@ -3408,7 +3731,33 @@ WHERE "posthog_organizationmembership"."user_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.154 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.163 + ''' + SELECT "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.164 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -3420,7 +3769,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.155 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.165 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -3441,7 +3790,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.156 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.166 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -3514,7 +3863,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.157 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.167 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -3533,7 +3882,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.158 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.168 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -3545,7 +3894,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.159 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.169 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -3566,7 +3915,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.16 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.17 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -3625,7 +3974,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.160 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.170 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -3698,7 +4047,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.161 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.171 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -3717,7 +4066,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.162 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.172 ''' SELECT "posthog_sessionrecording"."id", "posthog_sessionrecording"."session_id", @@ -3752,7 +4101,7 @@ AND "posthog_sessionrecording"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.163 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.173 ''' SELECT "posthog_sessionrecordingviewed"."session_id" FROM "posthog_sessionrecordingviewed" @@ -3760,7 +4109,7 @@ AND "posthog_sessionrecordingviewed"."user_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.164 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.174 ''' SELECT "posthog_persondistinctid"."id", "posthog_persondistinctid"."team_id", @@ -3791,7 +4140,7 @@ AND "posthog_persondistinctid"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.165 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.175 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -3857,7 +4206,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.166 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.176 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -3876,7 +4225,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.167 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.177 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -3895,7 +4244,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.168 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.178 ''' SELECT "posthog_user"."id", "posthog_user"."password", @@ -3927,7 +4276,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.169 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.179 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -3986,7 +4335,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.17 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.18 ''' SELECT "posthog_organizationmembership"."id", "posthog_organizationmembership"."organization_id", @@ -4018,7 +4367,7 @@ WHERE "posthog_organizationmembership"."user_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.170 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.180 ''' SELECT "posthog_organizationmembership"."id", "posthog_organizationmembership"."organization_id", @@ -4050,7 +4399,33 @@ WHERE "posthog_organizationmembership"."user_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.171 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.181 + ''' + SELECT "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.182 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -4062,7 +4437,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.172 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.183 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -4083,7 +4458,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.173 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.184 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -4156,7 +4531,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.174 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.185 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -4175,7 +4550,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.175 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.186 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -4187,7 +4562,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.176 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.187 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -4208,7 +4583,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.177 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.188 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -4281,7 +4656,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.178 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.189 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -4300,7 +4675,33 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.179 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.19 + ''' + SELECT "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.190 ''' SELECT "posthog_sessionrecording"."id", "posthog_sessionrecording"."session_id", @@ -4336,19 +4737,7 @@ AND "posthog_sessionrecording"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.18 - ''' - SELECT "posthog_grouptypemapping"."id", - "posthog_grouptypemapping"."team_id", - "posthog_grouptypemapping"."group_type", - "posthog_grouptypemapping"."group_type_index", - "posthog_grouptypemapping"."name_singular", - "posthog_grouptypemapping"."name_plural" - FROM "posthog_grouptypemapping" - WHERE "posthog_grouptypemapping"."team_id" = 2 - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.180 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.191 ''' SELECT "posthog_sessionrecordingviewed"."session_id" FROM "posthog_sessionrecordingviewed" @@ -4356,7 +4745,7 @@ AND "posthog_sessionrecordingviewed"."user_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.181 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.192 ''' SELECT "posthog_persondistinctid"."id", "posthog_persondistinctid"."team_id", @@ -4388,7 +4777,39 @@ AND "posthog_persondistinctid"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.182 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.2 + ''' + SELECT "posthog_organizationmembership"."id", + "posthog_organizationmembership"."organization_id", + "posthog_organizationmembership"."user_id", + "posthog_organizationmembership"."level", + "posthog_organizationmembership"."joined_at", + "posthog_organizationmembership"."updated_at", + "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organizationmembership" + INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id") + WHERE "posthog_organizationmembership"."user_id" = 2 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.20 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -4400,7 +4821,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.183 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.21 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -4421,7 +4842,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.184 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.22 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -4494,7 +4915,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.185 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.23 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -4513,7 +4934,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.186 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.24 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -4525,7 +4946,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.187 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.25 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -4546,7 +4967,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.188 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.26 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -4619,7 +5040,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.189 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.27 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -4638,28 +5059,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.19 - ''' - SELECT "posthog_datawarehousesavedquery"."created_by_id", - "posthog_datawarehousesavedquery"."created_at", - "posthog_datawarehousesavedquery"."deleted", - "posthog_datawarehousesavedquery"."deleted_at", - "posthog_datawarehousesavedquery"."id", - "posthog_datawarehousesavedquery"."name", - "posthog_datawarehousesavedquery"."team_id", - "posthog_datawarehousesavedquery"."columns", - "posthog_datawarehousesavedquery"."external_tables", - "posthog_datawarehousesavedquery"."query", - "posthog_datawarehousesavedquery"."status", - "posthog_datawarehousesavedquery"."last_run_at", - "posthog_datawarehousesavedquery"."table_id" - FROM "posthog_datawarehousesavedquery" - WHERE ("posthog_datawarehousesavedquery"."team_id" = 2 - AND NOT ("posthog_datawarehousesavedquery"."deleted" - AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.190 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.28 ''' SELECT "posthog_sessionrecording"."id", "posthog_sessionrecording"."session_id", @@ -4682,20 +5082,11 @@ "posthog_sessionrecording"."start_url", "posthog_sessionrecording"."storage_version" FROM "posthog_sessionrecording" - WHERE ("posthog_sessionrecording"."session_id" IN ('1', - '10', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9') + WHERE ("posthog_sessionrecording"."session_id" IN ('1') AND "posthog_sessionrecording"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.191 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.29 ''' SELECT "posthog_sessionrecordingviewed"."session_id" FROM "posthog_sessionrecordingviewed" @@ -4703,47 +5094,9 @@ AND "posthog_sessionrecordingviewed"."user_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.192 - ''' - SELECT "posthog_persondistinctid"."id", - "posthog_persondistinctid"."team_id", - "posthog_persondistinctid"."person_id", - "posthog_persondistinctid"."distinct_id", - "posthog_persondistinctid"."version", - "posthog_person"."id", - "posthog_person"."created_at", - "posthog_person"."properties_last_updated_at", - "posthog_person"."properties_last_operation", - "posthog_person"."team_id", - "posthog_person"."properties", - "posthog_person"."is_user_id", - "posthog_person"."is_identified", - "posthog_person"."uuid", - "posthog_person"."version" - FROM "posthog_persondistinctid" - INNER JOIN "posthog_person" ON ("posthog_persondistinctid"."person_id" = "posthog_person"."id") - WHERE ("posthog_persondistinctid"."distinct_id" IN ('user1', - 'user10', - 'user2', - 'user3', - 'user4', - 'user5', - 'user6', - 'user7', - 'user8', - 'user9') - AND "posthog_persondistinctid"."team_id" = 2) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.2 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.3 ''' - SELECT "posthog_organizationmembership"."id", - "posthog_organizationmembership"."organization_id", - "posthog_organizationmembership"."user_id", - "posthog_organizationmembership"."level", - "posthog_organizationmembership"."joined_at", - "posthog_organizationmembership"."updated_at", - "posthog_organization"."id", + SELECT "posthog_organization"."id", "posthog_organization"."name", "posthog_organization"."slug", "posthog_organization"."logo_media_id", @@ -4762,264 +5115,12 @@ "posthog_organization"."setup_section_2_completed", "posthog_organization"."personalization", "posthog_organization"."domain_whitelist" - FROM "posthog_organizationmembership" - INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id") - WHERE "posthog_organizationmembership"."user_id" = 2 - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.20 - ''' - SELECT "posthog_datawarehousetable"."created_by_id", - "posthog_datawarehousetable"."created_at", - "posthog_datawarehousetable"."updated_at", - "posthog_datawarehousetable"."deleted", - "posthog_datawarehousetable"."deleted_at", - "posthog_datawarehousetable"."id", - "posthog_datawarehousetable"."name", - "posthog_datawarehousetable"."format", - "posthog_datawarehousetable"."team_id", - "posthog_datawarehousetable"."url_pattern", - "posthog_datawarehousetable"."credential_id", - "posthog_datawarehousetable"."external_data_source_id", - "posthog_datawarehousetable"."columns", - "posthog_datawarehousetable"."row_count", - "posthog_user"."id", - "posthog_user"."password", - "posthog_user"."last_login", - "posthog_user"."first_name", - "posthog_user"."last_name", - "posthog_user"."is_staff", - "posthog_user"."date_joined", - "posthog_user"."uuid", - "posthog_user"."current_organization_id", - "posthog_user"."current_team_id", - "posthog_user"."email", - "posthog_user"."pending_email", - "posthog_user"."temporary_token", - "posthog_user"."distinct_id", - "posthog_user"."is_email_verified", - "posthog_user"."requested_password_reset_at", - "posthog_user"."has_seen_product_intro_for", - "posthog_user"."strapi_id", - "posthog_user"."is_active", - "posthog_user"."theme_mode", - "posthog_user"."partial_notification_settings", - "posthog_user"."anonymize_data", - "posthog_user"."toolbar_mode", - "posthog_user"."hedgehog_config", - "posthog_user"."events_column_config", - "posthog_user"."email_opt_in", - "posthog_datawarehousecredential"."created_by_id", - "posthog_datawarehousecredential"."created_at", - "posthog_datawarehousecredential"."id", - "posthog_datawarehousecredential"."access_key", - "posthog_datawarehousecredential"."access_secret", - "posthog_datawarehousecredential"."team_id", - "posthog_externaldatasource"."created_by_id", - "posthog_externaldatasource"."created_at", - "posthog_externaldatasource"."updated_at", - "posthog_externaldatasource"."deleted", - "posthog_externaldatasource"."deleted_at", - "posthog_externaldatasource"."id", - "posthog_externaldatasource"."source_id", - "posthog_externaldatasource"."connection_id", - "posthog_externaldatasource"."destination_id", - "posthog_externaldatasource"."team_id", - "posthog_externaldatasource"."sync_frequency", - "posthog_externaldatasource"."status", - "posthog_externaldatasource"."source_type", - "posthog_externaldatasource"."job_inputs", - "posthog_externaldatasource"."are_tables_created", - "posthog_externaldatasource"."prefix" - FROM "posthog_datawarehousetable" - LEFT OUTER JOIN "posthog_user" ON ("posthog_datawarehousetable"."created_by_id" = "posthog_user"."id") - LEFT OUTER JOIN "posthog_datawarehousecredential" ON ("posthog_datawarehousetable"."credential_id" = "posthog_datawarehousecredential"."id") - LEFT OUTER JOIN "posthog_externaldatasource" ON ("posthog_datawarehousetable"."external_data_source_id" = "posthog_externaldatasource"."id") - WHERE ("posthog_datawarehousetable"."team_id" = 2 - AND NOT ("posthog_datawarehousetable"."deleted" - AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.21 - ''' - SELECT "posthog_datawarehousejoin"."created_by_id", - "posthog_datawarehousejoin"."created_at", - "posthog_datawarehousejoin"."deleted", - "posthog_datawarehousejoin"."deleted_at", - "posthog_datawarehousejoin"."id", - "posthog_datawarehousejoin"."team_id", - "posthog_datawarehousejoin"."source_table_name", - "posthog_datawarehousejoin"."source_table_key", - "posthog_datawarehousejoin"."joining_table_name", - "posthog_datawarehousejoin"."joining_table_key", - "posthog_datawarehousejoin"."field_name" - FROM "posthog_datawarehousejoin" - WHERE ("posthog_datawarehousejoin"."team_id" = 2 - AND NOT ("posthog_datawarehousejoin"."deleted" - AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.22 - ''' - SELECT "posthog_grouptypemapping"."id", - "posthog_grouptypemapping"."team_id", - "posthog_grouptypemapping"."group_type", - "posthog_grouptypemapping"."group_type_index", - "posthog_grouptypemapping"."name_singular", - "posthog_grouptypemapping"."name_plural" - FROM "posthog_grouptypemapping" - WHERE "posthog_grouptypemapping"."team_id" = 2 - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.23 - ''' - SELECT "posthog_datawarehousesavedquery"."created_by_id", - "posthog_datawarehousesavedquery"."created_at", - "posthog_datawarehousesavedquery"."deleted", - "posthog_datawarehousesavedquery"."deleted_at", - "posthog_datawarehousesavedquery"."id", - "posthog_datawarehousesavedquery"."name", - "posthog_datawarehousesavedquery"."team_id", - "posthog_datawarehousesavedquery"."columns", - "posthog_datawarehousesavedquery"."external_tables", - "posthog_datawarehousesavedquery"."query", - "posthog_datawarehousesavedquery"."status", - "posthog_datawarehousesavedquery"."last_run_at", - "posthog_datawarehousesavedquery"."table_id" - FROM "posthog_datawarehousesavedquery" - WHERE ("posthog_datawarehousesavedquery"."team_id" = 2 - AND NOT ("posthog_datawarehousesavedquery"."deleted" - AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.24 - ''' - SELECT "posthog_datawarehousetable"."created_by_id", - "posthog_datawarehousetable"."created_at", - "posthog_datawarehousetable"."updated_at", - "posthog_datawarehousetable"."deleted", - "posthog_datawarehousetable"."deleted_at", - "posthog_datawarehousetable"."id", - "posthog_datawarehousetable"."name", - "posthog_datawarehousetable"."format", - "posthog_datawarehousetable"."team_id", - "posthog_datawarehousetable"."url_pattern", - "posthog_datawarehousetable"."credential_id", - "posthog_datawarehousetable"."external_data_source_id", - "posthog_datawarehousetable"."columns", - "posthog_datawarehousetable"."row_count", - "posthog_user"."id", - "posthog_user"."password", - "posthog_user"."last_login", - "posthog_user"."first_name", - "posthog_user"."last_name", - "posthog_user"."is_staff", - "posthog_user"."date_joined", - "posthog_user"."uuid", - "posthog_user"."current_organization_id", - "posthog_user"."current_team_id", - "posthog_user"."email", - "posthog_user"."pending_email", - "posthog_user"."temporary_token", - "posthog_user"."distinct_id", - "posthog_user"."is_email_verified", - "posthog_user"."requested_password_reset_at", - "posthog_user"."has_seen_product_intro_for", - "posthog_user"."strapi_id", - "posthog_user"."is_active", - "posthog_user"."theme_mode", - "posthog_user"."partial_notification_settings", - "posthog_user"."anonymize_data", - "posthog_user"."toolbar_mode", - "posthog_user"."hedgehog_config", - "posthog_user"."events_column_config", - "posthog_user"."email_opt_in", - "posthog_datawarehousecredential"."created_by_id", - "posthog_datawarehousecredential"."created_at", - "posthog_datawarehousecredential"."id", - "posthog_datawarehousecredential"."access_key", - "posthog_datawarehousecredential"."access_secret", - "posthog_datawarehousecredential"."team_id", - "posthog_externaldatasource"."created_by_id", - "posthog_externaldatasource"."created_at", - "posthog_externaldatasource"."updated_at", - "posthog_externaldatasource"."deleted", - "posthog_externaldatasource"."deleted_at", - "posthog_externaldatasource"."id", - "posthog_externaldatasource"."source_id", - "posthog_externaldatasource"."connection_id", - "posthog_externaldatasource"."destination_id", - "posthog_externaldatasource"."team_id", - "posthog_externaldatasource"."sync_frequency", - "posthog_externaldatasource"."status", - "posthog_externaldatasource"."source_type", - "posthog_externaldatasource"."job_inputs", - "posthog_externaldatasource"."are_tables_created", - "posthog_externaldatasource"."prefix" - FROM "posthog_datawarehousetable" - LEFT OUTER JOIN "posthog_user" ON ("posthog_datawarehousetable"."created_by_id" = "posthog_user"."id") - LEFT OUTER JOIN "posthog_datawarehousecredential" ON ("posthog_datawarehousetable"."credential_id" = "posthog_datawarehousecredential"."id") - LEFT OUTER JOIN "posthog_externaldatasource" ON ("posthog_datawarehousetable"."external_data_source_id" = "posthog_externaldatasource"."id") - WHERE ("posthog_datawarehousetable"."team_id" = 2 - AND NOT ("posthog_datawarehousetable"."deleted" - AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.25 - ''' - SELECT "posthog_datawarehousejoin"."created_by_id", - "posthog_datawarehousejoin"."created_at", - "posthog_datawarehousejoin"."deleted", - "posthog_datawarehousejoin"."deleted_at", - "posthog_datawarehousejoin"."id", - "posthog_datawarehousejoin"."team_id", - "posthog_datawarehousejoin"."source_table_name", - "posthog_datawarehousejoin"."source_table_key", - "posthog_datawarehousejoin"."joining_table_name", - "posthog_datawarehousejoin"."joining_table_key", - "posthog_datawarehousejoin"."field_name" - FROM "posthog_datawarehousejoin" - WHERE ("posthog_datawarehousejoin"."team_id" = 2 - AND NOT ("posthog_datawarehousejoin"."deleted" - AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.26 - ''' - SELECT "posthog_sessionrecording"."id", - "posthog_sessionrecording"."session_id", - "posthog_sessionrecording"."team_id", - "posthog_sessionrecording"."created_at", - "posthog_sessionrecording"."deleted", - "posthog_sessionrecording"."object_storage_path", - "posthog_sessionrecording"."distinct_id", - "posthog_sessionrecording"."duration", - "posthog_sessionrecording"."active_seconds", - "posthog_sessionrecording"."inactive_seconds", - "posthog_sessionrecording"."start_time", - "posthog_sessionrecording"."end_time", - "posthog_sessionrecording"."click_count", - "posthog_sessionrecording"."keypress_count", - "posthog_sessionrecording"."mouse_activity_count", - "posthog_sessionrecording"."console_log_count", - "posthog_sessionrecording"."console_warn_count", - "posthog_sessionrecording"."console_error_count", - "posthog_sessionrecording"."start_url", - "posthog_sessionrecording"."storage_version" - FROM "posthog_sessionrecording" - WHERE ("posthog_sessionrecording"."session_id" IN ('1') - AND "posthog_sessionrecording"."team_id" = 2) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.27 - ''' - SELECT "posthog_sessionrecordingviewed"."session_id" - FROM "posthog_sessionrecordingviewed" - WHERE ("posthog_sessionrecordingviewed"."team_id" = 2 - AND "posthog_sessionrecordingviewed"."user_id" = 2) + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.28 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.30 ''' SELECT "posthog_persondistinctid"."id", "posthog_persondistinctid"."team_id", @@ -5042,7 +5143,7 @@ AND "posthog_persondistinctid"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.29 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.31 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -5108,19 +5209,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.3 - ''' - SELECT "posthog_grouptypemapping"."id", - "posthog_grouptypemapping"."team_id", - "posthog_grouptypemapping"."group_type", - "posthog_grouptypemapping"."group_type_index", - "posthog_grouptypemapping"."name_singular", - "posthog_grouptypemapping"."name_plural" - FROM "posthog_grouptypemapping" - WHERE "posthog_grouptypemapping"."team_id" = 2 - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.30 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.32 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -5139,7 +5228,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.31 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.33 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -5158,7 +5247,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.32 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.34 ''' SELECT "posthog_user"."id", "posthog_user"."password", @@ -5190,7 +5279,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.33 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.35 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -5249,7 +5338,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.34 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.36 ''' SELECT "posthog_organizationmembership"."id", "posthog_organizationmembership"."organization_id", @@ -5276,12 +5365,38 @@ "posthog_organization"."setup_section_2_completed", "posthog_organization"."personalization", "posthog_organization"."domain_whitelist" - FROM "posthog_organizationmembership" - INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id") - WHERE "posthog_organizationmembership"."user_id" = 2 + FROM "posthog_organizationmembership" + INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id") + WHERE "posthog_organizationmembership"."user_id" = 2 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.37 + ''' + SELECT "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.35 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.38 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -5293,7 +5408,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.36 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.39 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -5314,7 +5429,19 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.37 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.4 + ''' + SELECT "posthog_grouptypemapping"."id", + "posthog_grouptypemapping"."team_id", + "posthog_grouptypemapping"."group_type", + "posthog_grouptypemapping"."group_type_index", + "posthog_grouptypemapping"."name_singular", + "posthog_grouptypemapping"."name_plural" + FROM "posthog_grouptypemapping" + WHERE "posthog_grouptypemapping"."team_id" = 2 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.40 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -5387,7 +5514,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.38 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.41 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -5406,7 +5533,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.39 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.42 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -5418,28 +5545,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.4 - ''' - SELECT "posthog_datawarehousesavedquery"."created_by_id", - "posthog_datawarehousesavedquery"."created_at", - "posthog_datawarehousesavedquery"."deleted", - "posthog_datawarehousesavedquery"."deleted_at", - "posthog_datawarehousesavedquery"."id", - "posthog_datawarehousesavedquery"."name", - "posthog_datawarehousesavedquery"."team_id", - "posthog_datawarehousesavedquery"."columns", - "posthog_datawarehousesavedquery"."external_tables", - "posthog_datawarehousesavedquery"."query", - "posthog_datawarehousesavedquery"."status", - "posthog_datawarehousesavedquery"."last_run_at", - "posthog_datawarehousesavedquery"."table_id" - FROM "posthog_datawarehousesavedquery" - WHERE ("posthog_datawarehousesavedquery"."team_id" = 2 - AND NOT ("posthog_datawarehousesavedquery"."deleted" - AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.40 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.43 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -5460,7 +5566,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.41 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.44 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -5533,7 +5639,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.42 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.45 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -5552,7 +5658,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.43 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.46 ''' SELECT "posthog_sessionrecording"."id", "posthog_sessionrecording"."session_id", @@ -5580,7 +5686,7 @@ AND "posthog_sessionrecording"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.44 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.47 ''' SELECT "posthog_sessionrecordingviewed"."session_id" FROM "posthog_sessionrecordingviewed" @@ -5588,7 +5694,7 @@ AND "posthog_sessionrecordingviewed"."user_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.45 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.48 ''' SELECT "posthog_persondistinctid"."id", "posthog_persondistinctid"."team_id", @@ -5612,7 +5718,7 @@ AND "posthog_persondistinctid"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.46 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.49 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -5678,7 +5784,28 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.47 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.5 + ''' + SELECT "posthog_datawarehousesavedquery"."created_by_id", + "posthog_datawarehousesavedquery"."created_at", + "posthog_datawarehousesavedquery"."deleted", + "posthog_datawarehousesavedquery"."deleted_at", + "posthog_datawarehousesavedquery"."id", + "posthog_datawarehousesavedquery"."name", + "posthog_datawarehousesavedquery"."team_id", + "posthog_datawarehousesavedquery"."columns", + "posthog_datawarehousesavedquery"."external_tables", + "posthog_datawarehousesavedquery"."query", + "posthog_datawarehousesavedquery"."status", + "posthog_datawarehousesavedquery"."last_run_at", + "posthog_datawarehousesavedquery"."table_id" + FROM "posthog_datawarehousesavedquery" + WHERE ("posthog_datawarehousesavedquery"."team_id" = 2 + AND NOT ("posthog_datawarehousesavedquery"."deleted" + AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.50 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -5697,7 +5824,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.48 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.51 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -5716,7 +5843,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.49 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.52 ''' SELECT "posthog_user"."id", "posthog_user"."password", @@ -5748,80 +5875,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.5 - ''' - SELECT "posthog_datawarehousetable"."created_by_id", - "posthog_datawarehousetable"."created_at", - "posthog_datawarehousetable"."updated_at", - "posthog_datawarehousetable"."deleted", - "posthog_datawarehousetable"."deleted_at", - "posthog_datawarehousetable"."id", - "posthog_datawarehousetable"."name", - "posthog_datawarehousetable"."format", - "posthog_datawarehousetable"."team_id", - "posthog_datawarehousetable"."url_pattern", - "posthog_datawarehousetable"."credential_id", - "posthog_datawarehousetable"."external_data_source_id", - "posthog_datawarehousetable"."columns", - "posthog_datawarehousetable"."row_count", - "posthog_user"."id", - "posthog_user"."password", - "posthog_user"."last_login", - "posthog_user"."first_name", - "posthog_user"."last_name", - "posthog_user"."is_staff", - "posthog_user"."date_joined", - "posthog_user"."uuid", - "posthog_user"."current_organization_id", - "posthog_user"."current_team_id", - "posthog_user"."email", - "posthog_user"."pending_email", - "posthog_user"."temporary_token", - "posthog_user"."distinct_id", - "posthog_user"."is_email_verified", - "posthog_user"."requested_password_reset_at", - "posthog_user"."has_seen_product_intro_for", - "posthog_user"."strapi_id", - "posthog_user"."is_active", - "posthog_user"."theme_mode", - "posthog_user"."partial_notification_settings", - "posthog_user"."anonymize_data", - "posthog_user"."toolbar_mode", - "posthog_user"."hedgehog_config", - "posthog_user"."events_column_config", - "posthog_user"."email_opt_in", - "posthog_datawarehousecredential"."created_by_id", - "posthog_datawarehousecredential"."created_at", - "posthog_datawarehousecredential"."id", - "posthog_datawarehousecredential"."access_key", - "posthog_datawarehousecredential"."access_secret", - "posthog_datawarehousecredential"."team_id", - "posthog_externaldatasource"."created_by_id", - "posthog_externaldatasource"."created_at", - "posthog_externaldatasource"."updated_at", - "posthog_externaldatasource"."deleted", - "posthog_externaldatasource"."deleted_at", - "posthog_externaldatasource"."id", - "posthog_externaldatasource"."source_id", - "posthog_externaldatasource"."connection_id", - "posthog_externaldatasource"."destination_id", - "posthog_externaldatasource"."team_id", - "posthog_externaldatasource"."sync_frequency", - "posthog_externaldatasource"."status", - "posthog_externaldatasource"."source_type", - "posthog_externaldatasource"."job_inputs", - "posthog_externaldatasource"."are_tables_created", - "posthog_externaldatasource"."prefix" - FROM "posthog_datawarehousetable" - LEFT OUTER JOIN "posthog_user" ON ("posthog_datawarehousetable"."created_by_id" = "posthog_user"."id") - LEFT OUTER JOIN "posthog_datawarehousecredential" ON ("posthog_datawarehousetable"."credential_id" = "posthog_datawarehousecredential"."id") - LEFT OUTER JOIN "posthog_externaldatasource" ON ("posthog_datawarehousetable"."external_data_source_id" = "posthog_externaldatasource"."id") - WHERE ("posthog_datawarehousetable"."team_id" = 2 - AND NOT ("posthog_datawarehousetable"."deleted" - AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.50 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.53 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -5880,7 +5934,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.51 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.54 ''' SELECT "posthog_organizationmembership"."id", "posthog_organizationmembership"."organization_id", @@ -5912,7 +5966,33 @@ WHERE "posthog_organizationmembership"."user_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.52 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.55 + ''' + SELECT "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.56 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -5924,7 +6004,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.53 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.57 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -5945,7 +6025,99 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.54 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.58 + ''' + SELECT "posthog_datawarehousetable"."created_by_id", + "posthog_datawarehousetable"."created_at", + "posthog_datawarehousetable"."updated_at", + "posthog_datawarehousetable"."deleted", + "posthog_datawarehousetable"."deleted_at", + "posthog_datawarehousetable"."id", + "posthog_datawarehousetable"."name", + "posthog_datawarehousetable"."format", + "posthog_datawarehousetable"."team_id", + "posthog_datawarehousetable"."url_pattern", + "posthog_datawarehousetable"."credential_id", + "posthog_datawarehousetable"."external_data_source_id", + "posthog_datawarehousetable"."columns", + "posthog_datawarehousetable"."row_count", + "posthog_user"."id", + "posthog_user"."password", + "posthog_user"."last_login", + "posthog_user"."first_name", + "posthog_user"."last_name", + "posthog_user"."is_staff", + "posthog_user"."date_joined", + "posthog_user"."uuid", + "posthog_user"."current_organization_id", + "posthog_user"."current_team_id", + "posthog_user"."email", + "posthog_user"."pending_email", + "posthog_user"."temporary_token", + "posthog_user"."distinct_id", + "posthog_user"."is_email_verified", + "posthog_user"."requested_password_reset_at", + "posthog_user"."has_seen_product_intro_for", + "posthog_user"."strapi_id", + "posthog_user"."is_active", + "posthog_user"."theme_mode", + "posthog_user"."partial_notification_settings", + "posthog_user"."anonymize_data", + "posthog_user"."toolbar_mode", + "posthog_user"."hedgehog_config", + "posthog_user"."events_column_config", + "posthog_user"."email_opt_in", + "posthog_datawarehousecredential"."created_by_id", + "posthog_datawarehousecredential"."created_at", + "posthog_datawarehousecredential"."id", + "posthog_datawarehousecredential"."access_key", + "posthog_datawarehousecredential"."access_secret", + "posthog_datawarehousecredential"."team_id", + "posthog_externaldatasource"."created_by_id", + "posthog_externaldatasource"."created_at", + "posthog_externaldatasource"."updated_at", + "posthog_externaldatasource"."deleted", + "posthog_externaldatasource"."deleted_at", + "posthog_externaldatasource"."id", + "posthog_externaldatasource"."source_id", + "posthog_externaldatasource"."connection_id", + "posthog_externaldatasource"."destination_id", + "posthog_externaldatasource"."team_id", + "posthog_externaldatasource"."sync_frequency", + "posthog_externaldatasource"."status", + "posthog_externaldatasource"."source_type", + "posthog_externaldatasource"."job_inputs", + "posthog_externaldatasource"."are_tables_created", + "posthog_externaldatasource"."prefix" + FROM "posthog_datawarehousetable" + LEFT OUTER JOIN "posthog_user" ON ("posthog_datawarehousetable"."created_by_id" = "posthog_user"."id") + LEFT OUTER JOIN "posthog_datawarehousecredential" ON ("posthog_datawarehousetable"."credential_id" = "posthog_datawarehousecredential"."id") + LEFT OUTER JOIN "posthog_externaldatasource" ON ("posthog_datawarehousetable"."external_data_source_id" = "posthog_externaldatasource"."id") + WHERE ("posthog_datawarehousetable"."team_id" = 2 + AND NOT ("posthog_datawarehousetable"."deleted" + AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.59 + ''' + SELECT "posthog_datawarehousejoin"."created_by_id", + "posthog_datawarehousejoin"."created_at", + "posthog_datawarehousejoin"."deleted", + "posthog_datawarehousejoin"."deleted_at", + "posthog_datawarehousejoin"."id", + "posthog_datawarehousejoin"."team_id", + "posthog_datawarehousejoin"."source_table_name", + "posthog_datawarehousejoin"."source_table_key", + "posthog_datawarehousejoin"."joining_table_name", + "posthog_datawarehousejoin"."joining_table_key", + "posthog_datawarehousejoin"."field_name" + FROM "posthog_datawarehousejoin" + WHERE ("posthog_datawarehousejoin"."team_id" = 2 + AND NOT ("posthog_datawarehousejoin"."deleted" + AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.6 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -6018,26 +6190,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.55 - ''' - SELECT "posthog_datawarehousejoin"."created_by_id", - "posthog_datawarehousejoin"."created_at", - "posthog_datawarehousejoin"."deleted", - "posthog_datawarehousejoin"."deleted_at", - "posthog_datawarehousejoin"."id", - "posthog_datawarehousejoin"."team_id", - "posthog_datawarehousejoin"."source_table_name", - "posthog_datawarehousejoin"."source_table_key", - "posthog_datawarehousejoin"."joining_table_name", - "posthog_datawarehousejoin"."joining_table_key", - "posthog_datawarehousejoin"."field_name" - FROM "posthog_datawarehousejoin" - WHERE ("posthog_datawarehousejoin"."team_id" = 2 - AND NOT ("posthog_datawarehousejoin"."deleted" - AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.56 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.60 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -6049,7 +6202,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.57 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.61 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -6070,7 +6223,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.58 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.62 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -6143,26 +6296,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.59 - ''' - SELECT "posthog_datawarehousejoin"."created_by_id", - "posthog_datawarehousejoin"."created_at", - "posthog_datawarehousejoin"."deleted", - "posthog_datawarehousejoin"."deleted_at", - "posthog_datawarehousejoin"."id", - "posthog_datawarehousejoin"."team_id", - "posthog_datawarehousejoin"."source_table_name", - "posthog_datawarehousejoin"."source_table_key", - "posthog_datawarehousejoin"."joining_table_name", - "posthog_datawarehousejoin"."joining_table_key", - "posthog_datawarehousejoin"."field_name" - FROM "posthog_datawarehousejoin" - WHERE ("posthog_datawarehousejoin"."team_id" = 2 - AND NOT ("posthog_datawarehousejoin"."deleted" - AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.6 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.63 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -6181,7 +6315,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.60 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.64 ''' SELECT "posthog_sessionrecording"."id", "posthog_sessionrecording"."session_id", @@ -6210,7 +6344,7 @@ AND "posthog_sessionrecording"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.61 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.65 ''' SELECT "posthog_sessionrecordingviewed"."session_id" FROM "posthog_sessionrecordingviewed" @@ -6218,7 +6352,7 @@ AND "posthog_sessionrecordingviewed"."user_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.62 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.66 ''' SELECT "posthog_persondistinctid"."id", "posthog_persondistinctid"."team_id", @@ -6243,7 +6377,7 @@ AND "posthog_persondistinctid"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.63 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.67 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -6309,7 +6443,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.64 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.68 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -6328,7 +6462,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.65 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.69 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -6347,7 +6481,26 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.66 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.7 + ''' + SELECT "posthog_datawarehousejoin"."created_by_id", + "posthog_datawarehousejoin"."created_at", + "posthog_datawarehousejoin"."deleted", + "posthog_datawarehousejoin"."deleted_at", + "posthog_datawarehousejoin"."id", + "posthog_datawarehousejoin"."team_id", + "posthog_datawarehousejoin"."source_table_name", + "posthog_datawarehousejoin"."source_table_key", + "posthog_datawarehousejoin"."joining_table_name", + "posthog_datawarehousejoin"."joining_table_key", + "posthog_datawarehousejoin"."field_name" + FROM "posthog_datawarehousejoin" + WHERE ("posthog_datawarehousejoin"."team_id" = 2 + AND NOT ("posthog_datawarehousejoin"."deleted" + AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.70 ''' SELECT "posthog_user"."id", "posthog_user"."password", @@ -6379,7 +6532,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.67 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.71 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -6438,7 +6591,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.68 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.72 ''' SELECT "posthog_organizationmembership"."id", "posthog_organizationmembership"."organization_id", @@ -6470,19 +6623,33 @@ WHERE "posthog_organizationmembership"."user_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.69 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.73 ''' - SELECT "posthog_grouptypemapping"."id", - "posthog_grouptypemapping"."team_id", - "posthog_grouptypemapping"."group_type", - "posthog_grouptypemapping"."group_type_index", - "posthog_grouptypemapping"."name_singular", - "posthog_grouptypemapping"."name_plural" - FROM "posthog_grouptypemapping" - WHERE "posthog_grouptypemapping"."team_id" = 2 + SELECT "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.7 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.74 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -6494,7 +6661,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.70 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.75 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -6515,7 +6682,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.71 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.76 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -6588,7 +6755,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.72 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.77 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -6607,7 +6774,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.73 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.78 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -6619,7 +6786,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.74 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.79 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -6640,7 +6807,19 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.75 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.8 + ''' + SELECT "posthog_grouptypemapping"."id", + "posthog_grouptypemapping"."team_id", + "posthog_grouptypemapping"."group_type", + "posthog_grouptypemapping"."group_type_index", + "posthog_grouptypemapping"."name_singular", + "posthog_grouptypemapping"."name_plural" + FROM "posthog_grouptypemapping" + WHERE "posthog_grouptypemapping"."team_id" = 2 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.80 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -6713,7 +6892,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.76 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.81 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -6732,7 +6911,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.77 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.82 ''' SELECT "posthog_sessionrecording"."id", "posthog_sessionrecording"."session_id", @@ -6762,7 +6941,7 @@ AND "posthog_sessionrecording"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.78 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.83 ''' SELECT "posthog_sessionrecordingviewed"."session_id" FROM "posthog_sessionrecordingviewed" @@ -6770,7 +6949,7 @@ AND "posthog_sessionrecordingviewed"."user_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.79 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.84 ''' SELECT "posthog_persondistinctid"."id", "posthog_persondistinctid"."team_id", @@ -6796,28 +6975,7 @@ AND "posthog_persondistinctid"."team_id" = 2) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.8 - ''' - SELECT "posthog_datawarehousesavedquery"."created_by_id", - "posthog_datawarehousesavedquery"."created_at", - "posthog_datawarehousesavedquery"."deleted", - "posthog_datawarehousesavedquery"."deleted_at", - "posthog_datawarehousesavedquery"."id", - "posthog_datawarehousesavedquery"."name", - "posthog_datawarehousesavedquery"."team_id", - "posthog_datawarehousesavedquery"."columns", - "posthog_datawarehousesavedquery"."external_tables", - "posthog_datawarehousesavedquery"."query", - "posthog_datawarehousesavedquery"."status", - "posthog_datawarehousesavedquery"."last_run_at", - "posthog_datawarehousesavedquery"."table_id" - FROM "posthog_datawarehousesavedquery" - WHERE ("posthog_datawarehousesavedquery"."team_id" = 2 - AND NOT ("posthog_datawarehousesavedquery"."deleted" - AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.80 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.85 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -6883,7 +7041,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.81 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.86 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -6902,7 +7060,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.82 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.87 ''' SELECT "posthog_person"."id", "posthog_person"."created_at", @@ -6921,7 +7079,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.83 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.88 ''' SELECT "posthog_user"."id", "posthog_user"."password", @@ -6953,7 +7111,7 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.84 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.89 ''' SELECT "posthog_team"."id", "posthog_team"."uuid", @@ -7012,7 +7170,28 @@ LIMIT 21 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.85 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.9 + ''' + SELECT "posthog_datawarehousesavedquery"."created_by_id", + "posthog_datawarehousesavedquery"."created_at", + "posthog_datawarehousesavedquery"."deleted", + "posthog_datawarehousesavedquery"."deleted_at", + "posthog_datawarehousesavedquery"."id", + "posthog_datawarehousesavedquery"."name", + "posthog_datawarehousesavedquery"."team_id", + "posthog_datawarehousesavedquery"."columns", + "posthog_datawarehousesavedquery"."external_tables", + "posthog_datawarehousesavedquery"."query", + "posthog_datawarehousesavedquery"."status", + "posthog_datawarehousesavedquery"."last_run_at", + "posthog_datawarehousesavedquery"."table_id" + FROM "posthog_datawarehousesavedquery" + WHERE ("posthog_datawarehousesavedquery"."team_id" = 2 + AND NOT ("posthog_datawarehousesavedquery"."deleted" + AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.90 ''' SELECT "posthog_organizationmembership"."id", "posthog_organizationmembership"."organization_id", @@ -7044,7 +7223,33 @@ WHERE "posthog_organizationmembership"."user_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.86 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.91 + ''' + SELECT "posthog_organization"."id", + "posthog_organization"."name", + "posthog_organization"."slug", + "posthog_organization"."logo_media_id", + "posthog_organization"."created_at", + "posthog_organization"."updated_at", + "posthog_organization"."plugins_access_level", + "posthog_organization"."for_internal_metrics", + "posthog_organization"."is_member_join_email_enabled", + "posthog_organization"."enforce_2fa", + "posthog_organization"."is_hipaa", + "posthog_organization"."customer_id", + "posthog_organization"."available_product_features", + "posthog_organization"."usage", + "posthog_organization"."never_drop_data", + "posthog_organization"."customer_trust_scores", + "posthog_organization"."setup_section_2_completed", + "posthog_organization"."personalization", + "posthog_organization"."domain_whitelist" + FROM "posthog_organization" + WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid + LIMIT 21 + ''' +# --- +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.92 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -7056,7 +7261,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.87 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.93 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -7077,7 +7282,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.88 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.94 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -7150,7 +7355,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.89 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.95 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -7169,80 +7374,7 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.9 - ''' - SELECT "posthog_datawarehousetable"."created_by_id", - "posthog_datawarehousetable"."created_at", - "posthog_datawarehousetable"."updated_at", - "posthog_datawarehousetable"."deleted", - "posthog_datawarehousetable"."deleted_at", - "posthog_datawarehousetable"."id", - "posthog_datawarehousetable"."name", - "posthog_datawarehousetable"."format", - "posthog_datawarehousetable"."team_id", - "posthog_datawarehousetable"."url_pattern", - "posthog_datawarehousetable"."credential_id", - "posthog_datawarehousetable"."external_data_source_id", - "posthog_datawarehousetable"."columns", - "posthog_datawarehousetable"."row_count", - "posthog_user"."id", - "posthog_user"."password", - "posthog_user"."last_login", - "posthog_user"."first_name", - "posthog_user"."last_name", - "posthog_user"."is_staff", - "posthog_user"."date_joined", - "posthog_user"."uuid", - "posthog_user"."current_organization_id", - "posthog_user"."current_team_id", - "posthog_user"."email", - "posthog_user"."pending_email", - "posthog_user"."temporary_token", - "posthog_user"."distinct_id", - "posthog_user"."is_email_verified", - "posthog_user"."requested_password_reset_at", - "posthog_user"."has_seen_product_intro_for", - "posthog_user"."strapi_id", - "posthog_user"."is_active", - "posthog_user"."theme_mode", - "posthog_user"."partial_notification_settings", - "posthog_user"."anonymize_data", - "posthog_user"."toolbar_mode", - "posthog_user"."hedgehog_config", - "posthog_user"."events_column_config", - "posthog_user"."email_opt_in", - "posthog_datawarehousecredential"."created_by_id", - "posthog_datawarehousecredential"."created_at", - "posthog_datawarehousecredential"."id", - "posthog_datawarehousecredential"."access_key", - "posthog_datawarehousecredential"."access_secret", - "posthog_datawarehousecredential"."team_id", - "posthog_externaldatasource"."created_by_id", - "posthog_externaldatasource"."created_at", - "posthog_externaldatasource"."updated_at", - "posthog_externaldatasource"."deleted", - "posthog_externaldatasource"."deleted_at", - "posthog_externaldatasource"."id", - "posthog_externaldatasource"."source_id", - "posthog_externaldatasource"."connection_id", - "posthog_externaldatasource"."destination_id", - "posthog_externaldatasource"."team_id", - "posthog_externaldatasource"."sync_frequency", - "posthog_externaldatasource"."status", - "posthog_externaldatasource"."source_type", - "posthog_externaldatasource"."job_inputs", - "posthog_externaldatasource"."are_tables_created", - "posthog_externaldatasource"."prefix" - FROM "posthog_datawarehousetable" - LEFT OUTER JOIN "posthog_user" ON ("posthog_datawarehousetable"."created_by_id" = "posthog_user"."id") - LEFT OUTER JOIN "posthog_datawarehousecredential" ON ("posthog_datawarehousetable"."credential_id" = "posthog_datawarehousecredential"."id") - LEFT OUTER JOIN "posthog_externaldatasource" ON ("posthog_datawarehousetable"."external_data_source_id" = "posthog_externaldatasource"."id") - WHERE ("posthog_datawarehousetable"."team_id" = 2 - AND NOT ("posthog_datawarehousetable"."deleted" - AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.90 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.96 ''' SELECT "posthog_grouptypemapping"."id", "posthog_grouptypemapping"."team_id", @@ -7254,7 +7386,7 @@ WHERE "posthog_grouptypemapping"."team_id" = 2 ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.91 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.97 ''' SELECT "posthog_datawarehousesavedquery"."created_by_id", "posthog_datawarehousesavedquery"."created_at", @@ -7275,7 +7407,7 @@ AND "posthog_datawarehousesavedquery"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.92 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.98 ''' SELECT "posthog_datawarehousetable"."created_by_id", "posthog_datawarehousetable"."created_at", @@ -7348,7 +7480,7 @@ AND "posthog_datawarehousetable"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.93 +# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.99 ''' SELECT "posthog_datawarehousejoin"."created_by_id", "posthog_datawarehousejoin"."created_at", @@ -7367,173 +7499,3 @@ AND "posthog_datawarehousejoin"."deleted" IS NOT NULL)) ''' # --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.94 - ''' - SELECT "posthog_sessionrecording"."id", - "posthog_sessionrecording"."session_id", - "posthog_sessionrecording"."team_id", - "posthog_sessionrecording"."created_at", - "posthog_sessionrecording"."deleted", - "posthog_sessionrecording"."object_storage_path", - "posthog_sessionrecording"."distinct_id", - "posthog_sessionrecording"."duration", - "posthog_sessionrecording"."active_seconds", - "posthog_sessionrecording"."inactive_seconds", - "posthog_sessionrecording"."start_time", - "posthog_sessionrecording"."end_time", - "posthog_sessionrecording"."click_count", - "posthog_sessionrecording"."keypress_count", - "posthog_sessionrecording"."mouse_activity_count", - "posthog_sessionrecording"."console_log_count", - "posthog_sessionrecording"."console_warn_count", - "posthog_sessionrecording"."console_error_count", - "posthog_sessionrecording"."start_url", - "posthog_sessionrecording"."storage_version" - FROM "posthog_sessionrecording" - WHERE ("posthog_sessionrecording"."session_id" IN ('1', - '2', - '3', - '4', - '5') - AND "posthog_sessionrecording"."team_id" = 2) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.95 - ''' - SELECT "posthog_sessionrecordingviewed"."session_id" - FROM "posthog_sessionrecordingviewed" - WHERE ("posthog_sessionrecordingviewed"."team_id" = 2 - AND "posthog_sessionrecordingviewed"."user_id" = 2) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.96 - ''' - SELECT "posthog_persondistinctid"."id", - "posthog_persondistinctid"."team_id", - "posthog_persondistinctid"."person_id", - "posthog_persondistinctid"."distinct_id", - "posthog_persondistinctid"."version", - "posthog_person"."id", - "posthog_person"."created_at", - "posthog_person"."properties_last_updated_at", - "posthog_person"."properties_last_operation", - "posthog_person"."team_id", - "posthog_person"."properties", - "posthog_person"."is_user_id", - "posthog_person"."is_identified", - "posthog_person"."uuid", - "posthog_person"."version" - FROM "posthog_persondistinctid" - INNER JOIN "posthog_person" ON ("posthog_persondistinctid"."person_id" = "posthog_person"."id") - WHERE ("posthog_persondistinctid"."distinct_id" IN ('user1', - 'user2', - 'user3', - 'user4', - 'user5') - AND "posthog_persondistinctid"."team_id" = 2) - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.97 - ''' - SELECT "posthog_team"."id", - "posthog_team"."uuid", - "posthog_team"."organization_id", - "posthog_team"."project_id", - "posthog_team"."api_token", - "posthog_team"."app_urls", - "posthog_team"."name", - "posthog_team"."slack_incoming_webhook", - "posthog_team"."created_at", - "posthog_team"."updated_at", - "posthog_team"."anonymize_ips", - "posthog_team"."completed_snippet_onboarding", - "posthog_team"."has_completed_onboarding_for", - "posthog_team"."ingested_event", - "posthog_team"."autocapture_opt_out", - "posthog_team"."autocapture_web_vitals_opt_in", - "posthog_team"."autocapture_web_vitals_allowed_metrics", - "posthog_team"."autocapture_exceptions_opt_in", - "posthog_team"."autocapture_exceptions_errors_to_ignore", - "posthog_team"."session_recording_opt_in", - "posthog_team"."session_recording_sample_rate", - "posthog_team"."session_recording_minimum_duration_milliseconds", - "posthog_team"."session_recording_linked_flag", - "posthog_team"."session_recording_network_payload_capture_config", - "posthog_team"."session_recording_url_trigger_config", - "posthog_team"."session_replay_config", - "posthog_team"."survey_config", - "posthog_team"."capture_console_log_opt_in", - "posthog_team"."capture_performance_opt_in", - "posthog_team"."surveys_opt_in", - "posthog_team"."heatmaps_opt_in", - "posthog_team"."session_recording_version", - "posthog_team"."signup_token", - "posthog_team"."is_demo", - "posthog_team"."access_control", - "posthog_team"."week_start_day", - "posthog_team"."inject_web_apps", - "posthog_team"."test_account_filters", - "posthog_team"."test_account_filters_default_checked", - "posthog_team"."path_cleaning_filters", - "posthog_team"."timezone", - "posthog_team"."data_attributes", - "posthog_team"."person_display_name_properties", - "posthog_team"."live_events_columns", - "posthog_team"."recording_domains", - "posthog_team"."primary_dashboard_id", - "posthog_team"."extra_settings", - "posthog_team"."modifiers", - "posthog_team"."correlation_config", - "posthog_team"."session_recording_retention_period_days", - "posthog_team"."plugins_opt_in", - "posthog_team"."opt_out_capture", - "posthog_team"."event_names", - "posthog_team"."event_names_with_usage", - "posthog_team"."event_properties", - "posthog_team"."event_properties_with_usage", - "posthog_team"."event_properties_numerical", - "posthog_team"."external_data_workspace_id", - "posthog_team"."external_data_workspace_last_synced_at" - FROM "posthog_team" - WHERE "posthog_team"."id" = 2 - LIMIT 21 - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.98 - ''' - SELECT "posthog_person"."id", - "posthog_person"."created_at", - "posthog_person"."properties_last_updated_at", - "posthog_person"."properties_last_operation", - "posthog_person"."team_id", - "posthog_person"."properties", - "posthog_person"."is_user_id", - "posthog_person"."is_identified", - "posthog_person"."uuid", - "posthog_person"."version" - FROM "posthog_person" - INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") - WHERE ("posthog_persondistinctid"."distinct_id" = 'user6' - AND "posthog_persondistinctid"."team_id" = 2) - LIMIT 21 - ''' -# --- -# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.99 - ''' - SELECT "posthog_person"."id", - "posthog_person"."created_at", - "posthog_person"."properties_last_updated_at", - "posthog_person"."properties_last_operation", - "posthog_person"."team_id", - "posthog_person"."properties", - "posthog_person"."is_user_id", - "posthog_person"."is_identified", - "posthog_person"."uuid", - "posthog_person"."version" - FROM "posthog_person" - INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") - WHERE ("posthog_persondistinctid"."distinct_id" = 'user6' - AND "posthog_persondistinctid"."team_id" = 2) - LIMIT 21 - ''' -# ---