diff --git a/ee/clickhouse/queries/test/__snapshots__/test_cohort_query.ambr b/ee/clickhouse/queries/test/__snapshots__/test_cohort_query.ambr index 5ad0d10339d05..0e8bac745cba6 100644 --- a/ee/clickhouse/queries/test/__snapshots__/test_cohort_query.ambr +++ b/ee/clickhouse/queries/test/__snapshots__/test_cohort_query.ambr @@ -510,12 +510,22 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestCohortQuery.test_precalculated_cohort_filter_with_extra_filters.2 ' + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 0 + ' +--- +# name: TestCohortQuery.test_precalculated_cohort_filter_with_extra_filters.3 + ' + SELECT id FROM person WHERE team_id = 2 diff --git a/ee/clickhouse/queries/test/__snapshots__/test_event_query.ambr b/ee/clickhouse/queries/test/__snapshots__/test_event_query.ambr index 54c9cd5db8ca5..90ca2ed44543e 100644 --- a/ee/clickhouse/queries/test/__snapshots__/test_event_query.ambr +++ b/ee/clickhouse/queries/test/__snapshots__/test_event_query.ambr @@ -15,11 +15,21 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestEventQuery.test_account_filters.2 ' + + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 0 + ' +--- +# name: TestEventQuery.test_account_filters.3 + ' SELECT e.timestamp as timestamp, pdi.person_id as person_id FROM events e diff --git a/frontend/__snapshots__/scenes-app-insights--funnel-left-to-right-breakdown.png b/frontend/__snapshots__/scenes-app-insights--funnel-left-to-right-breakdown.png index 8eaedc5c1d3fa..c610c0b410781 100644 Binary files a/frontend/__snapshots__/scenes-app-insights--funnel-left-to-right-breakdown.png and b/frontend/__snapshots__/scenes-app-insights--funnel-left-to-right-breakdown.png differ diff --git a/frontend/src/scenes/cohorts/CohortEdit.tsx b/frontend/src/scenes/cohorts/CohortEdit.tsx index 72774547a2057..1d466f1f79d39 100644 --- a/frontend/src/scenes/cohorts/CohortEdit.tsx +++ b/frontend/src/scenes/cohorts/CohortEdit.tsx @@ -23,14 +23,17 @@ import { Form } from 'kea-forms' import { NotFound } from 'lib/components/NotFound' import { Query } from '~/queries/Query/Query' import { pluralize } from 'lib/utils' -import { LemonDivider } from '@posthog/lemon-ui' +import { LemonCheckbox, LemonDivider, Link } from '@posthog/lemon-ui' import { AndOrFilterSelect } from '~/queries/nodes/InsightViz/PropertyGroupFilters/AndOrFilterSelect' import { More } from 'lib/lemon-ui/LemonButton/More' import { NotebookSelectButton } from 'scenes/notebooks/NotebookSelectButton/NotebookSelectButton' +import { teamLogic } from 'scenes/teamLogic' export function CohortEdit({ id }: CohortLogicProps): JSX.Element { const logicProps = { id } const logic = cohortEditLogic(logicProps) + const { currentTeam } = useValues(teamLogic) + const slackEnabled = currentTeam?.slack_incoming_webhook const { deleteCohort, setOuterGroupsType, setQuery, duplicateCohort } = useActions(logic) const { cohort, cohortLoading, cohortMissing, query, duplicatedCohortLoading } = useValues(logic) const { hasAvailableFeature } = useValues(userLogic) @@ -230,6 +233,25 @@ export function CohortEdit({ id }: CohortLogicProps): JSX.Element { /> + + + {({ value, onChange }) => ( + + Post to webhook when this cohort is updated.} + /> + + + {slackEnabled ? 'Configure' : 'Enable'} webhooks in project settings. + + + + )} + > )} diff --git a/frontend/src/scenes/cohorts/cohortUtils.tsx b/frontend/src/scenes/cohorts/cohortUtils.tsx index 6c13ba3e5adc6..48d878351354c 100644 --- a/frontend/src/scenes/cohorts/cohortUtils.tsx +++ b/frontend/src/scenes/cohorts/cohortUtils.tsx @@ -88,6 +88,7 @@ export function isValidCohortGroup(criteria: AnyCohortGroupType): boolean { export function createCohortFormData(cohort: CohortType): FormData { const rawCohort = { + ...(cohort.post_to_webhook ? { post_to_webhook: cohort.post_to_webhook } : {}), ...(cohort.name ? { name: cohort.name } : {}), ...(cohort.description ? { description: cohort.description } : {}), ...(cohort.csv ? { csv: cohort.csv } : {}), diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 1ba6f2e6157e8..14c06d7f8d9ff 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -924,6 +924,7 @@ export interface CohortType { last_calculation?: string is_static?: boolean name?: string + post_to_webhook?: boolean csv?: UploadFile groups: CohortGroupType[] // To be deprecated once `filter` takes over filters: { diff --git a/latest_migrations.manifest b/latest_migrations.manifest index 7ad1758c3c617..af59f93237146 100644 --- a/latest_migrations.manifest +++ b/latest_migrations.manifest @@ -5,7 +5,7 @@ contenttypes: 0002_remove_content_type_name ee: 0015_add_verified_properties otp_static: 0002_throttling otp_totp: 0002_auto_20190420_0723 -posthog: 0364_team_external_data_workspace_rows +posthog: 0365_merge_20231118_0612 sessions: 0001_initial social_django: 0010_uid_db_index two_factor: 0007_auto_20201201_1019 diff --git a/plugin-server/src/types.ts b/plugin-server/src/types.ts index 700bf4f6cef89..5299f01bec25b 100644 --- a/plugin-server/src/types.ts +++ b/plugin-server/src/types.ts @@ -792,6 +792,7 @@ export interface ClickHousePersonDistinctId2 { export interface Cohort { id: number name: string + post_to_webhook: boolean description: string deleted: boolean groups: any[] diff --git a/plugin-server/src/utils/db/db.ts b/plugin-server/src/utils/db/db.ts index cf64f86b600a2..26a6a98d1620c 100644 --- a/plugin-server/src/utils/db/db.ts +++ b/plugin-server/src/utils/db/db.ts @@ -961,8 +961,8 @@ export class DB { `INSERT INTO posthog_cohort (name, description, deleted, groups, team_id, created_at, created_by_id, is_calculating, last_calculation, errors_calculating, is_static, - version, pending_version) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) + version, pending_version, post_to_webhook) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING *;`, [ cohort.name, @@ -978,6 +978,7 @@ export class DB { cohort.is_static ?? false, cohort.version, cohort.pending_version ?? cohort.version ?? 0, + cohort.post_to_webhook ?? false, ], 'createCohort' ) diff --git a/posthog/api/cohort.py b/posthog/api/cohort.py index c525be8d263be..598fe87b3f5e7 100644 --- a/posthog/api/cohort.py +++ b/posthog/api/cohort.py @@ -90,6 +90,7 @@ class Meta: fields = [ "id", "name", + "post_to_webhook", "description", "groups", "deleted", @@ -190,6 +191,7 @@ def update(self, cohort: Cohort, validated_data: Dict, *args: Any, **kwargs: Any user = cast(User, request.user) cohort.name = validated_data.get("name", cohort.name) + cohort.post_to_webhook = validated_data.get("post_to_webhook", False) cohort.description = validated_data.get("description", cohort.description) cohort.groups = validated_data.get("groups", cohort.groups) cohort.is_static = validated_data.get("is_static", cohort.is_static) diff --git a/posthog/api/test/__snapshots__/test_cohort.ambr b/posthog/api/test/__snapshots__/test_cohort.ambr index e8c0b7d444e0d..157b291301ab4 100644 --- a/posthog/api/test/__snapshots__/test_cohort.ambr +++ b/posthog/api/test/__snapshots__/test_cohort.ambr @@ -1,6 +1,6 @@ # name: TestCohort.test_async_deletion_of_cohort ' - /* user_id:119 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ + /* user_id:501 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ SELECT count(DISTINCT person_id) FROM cohortpeople WHERE team_id = 2 @@ -10,7 +10,56 @@ --- # name: TestCohort.test_async_deletion_of_cohort.1 ' - /* user_id:119 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ + /* user_id:501 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = NULL + ' +--- +# name: TestCohort.test_async_deletion_of_cohort.10 + ' + /* celery:posthog.celery.clickhouse_clear_removed_data */ + SELECT DISTINCT team_id, + cohort_id + FROM cohortpeople + WHERE (team_id = 2 + AND cohort_id = '132' + AND version < '2') + ' +--- +# name: TestCohort.test_async_deletion_of_cohort.11 + ' + /* celery:posthog.celery.clickhouse_clear_removed_data */ + DELETE + FROM cohortpeople + WHERE (team_id = 2 + AND cohort_id = '132' + AND version < '2') + ' +--- +# name: TestCohort.test_async_deletion_of_cohort.12 + ' + SELECT count() + FROM cohortpeople + WHERE cohort_id = 2 + ' +--- +# name: TestCohort.test_async_deletion_of_cohort.13 + ' + /* celery:posthog.celery.clickhouse_clear_removed_data */ + SELECT DISTINCT team_id, + cohort_id + FROM cohortpeople + WHERE (team_id = 2 + AND cohort_id = '132' + AND version < '2') + ' +--- +# name: TestCohort.test_async_deletion_of_cohort.2 + ' + /* user_id:501 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ INSERT INTO cohortpeople SELECT id, 2 as cohort_id, @@ -23,7 +72,7 @@ (SELECT pdi.person_id AS person_id, countIf(timestamp > now() - INTERVAL 1 day AND timestamp < now() - AND event = '$pageview') > 0 AS performed_event_condition_1_level_level_0_level_1_level_0_0 + AND event = '$pageview') > 0 AS performed_event_condition_132_level_level_0_level_1_level_0_0 FROM events e INNER JOIN (SELECT distinct_id, @@ -49,7 +98,7 @@ HAVING max(is_deleted) = 0 SETTINGS optimize_aggregation_in_order = 1)) person ON person.person_id = behavior_query.person_id WHERE 1 = 1 AND ((((has(['something'], replaceRegexpAll(JSONExtractRaw(person_props, '$some_prop'), '^"|"$', '')))) - OR ((performed_event_condition_1_level_level_0_level_1_level_0_0)))) ) as person + OR ((performed_event_condition_132_level_level_0_level_1_level_0_0)))) ) as person UNION ALL SELECT person_id, cohort_id, @@ -63,27 +112,9 @@ AND sign = 1 ' --- -# name: TestCohort.test_async_deletion_of_cohort.10 - ' - SELECT count() - FROM cohortpeople - WHERE cohort_id = 2 - ' ---- -# name: TestCohort.test_async_deletion_of_cohort.11 - ' - /* celery:posthog.celery.clickhouse_clear_removed_data */ - SELECT DISTINCT team_id, - cohort_id - FROM cohortpeople - WHERE (team_id = 2 - AND cohort_id = '1' - AND version < '2') - ' ---- -# name: TestCohort.test_async_deletion_of_cohort.2 +# name: TestCohort.test_async_deletion_of_cohort.3 ' - /* user_id:119 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ + /* user_id:501 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ SELECT count(DISTINCT person_id) FROM cohortpeople WHERE team_id = 2 @@ -91,9 +122,9 @@ AND version = 1 ' --- -# name: TestCohort.test_async_deletion_of_cohort.3 +# name: TestCohort.test_async_deletion_of_cohort.4 ' - /* user_id:119 celery:posthog.tasks.calculate_cohort.clear_stale_cohort */ + /* user_id:501 celery:posthog.tasks.calculate_cohort.clear_stale_cohort */ SELECT count() FROM cohortpeople WHERE team_id = 2 @@ -101,9 +132,9 @@ AND version < 1 ' --- -# name: TestCohort.test_async_deletion_of_cohort.4 +# name: TestCohort.test_async_deletion_of_cohort.5 ' - /* user_id:119 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ + /* user_id:501 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ SELECT count(DISTINCT person_id) FROM cohortpeople WHERE team_id = 2 @@ -111,9 +142,19 @@ AND version = 1 ' --- -# name: TestCohort.test_async_deletion_of_cohort.5 +# name: TestCohort.test_async_deletion_of_cohort.6 + ' + /* user_id:501 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 1 + ' +--- +# name: TestCohort.test_async_deletion_of_cohort.7 ' - /* user_id:119 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ + /* user_id:501 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ INSERT INTO cohortpeople SELECT id, 2 as cohort_id, @@ -145,9 +186,9 @@ AND sign = 1 ' --- -# name: TestCohort.test_async_deletion_of_cohort.6 +# name: TestCohort.test_async_deletion_of_cohort.8 ' - /* user_id:119 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ + /* user_id:501 celery:posthog.tasks.calculate_cohort.calculate_cohort_ch */ SELECT count(DISTINCT person_id) FROM cohortpeople WHERE team_id = 2 @@ -155,9 +196,9 @@ AND version = 2 ' --- -# name: TestCohort.test_async_deletion_of_cohort.7 +# name: TestCohort.test_async_deletion_of_cohort.9 ' - /* user_id:119 celery:posthog.tasks.calculate_cohort.clear_stale_cohort */ + /* user_id:501 celery:posthog.tasks.calculate_cohort.clear_stale_cohort */ SELECT count() FROM cohortpeople WHERE team_id = 2 @@ -165,24 +206,3 @@ AND version < 2 ' --- -# name: TestCohort.test_async_deletion_of_cohort.8 - ' - /* celery:posthog.celery.clickhouse_clear_removed_data */ - SELECT DISTINCT team_id, - cohort_id - FROM cohortpeople - WHERE (team_id = 2 - AND cohort_id = '1' - AND version < '2') - ' ---- -# name: TestCohort.test_async_deletion_of_cohort.9 - ' - /* celery:posthog.celery.clickhouse_clear_removed_data */ - DELETE - FROM cohortpeople - WHERE (team_id = 2 - AND cohort_id = '1' - AND version < '2') - ' ---- diff --git a/posthog/api/test/__snapshots__/test_decide.ambr b/posthog/api/test/__snapshots__/test_decide.ambr index f0c0385bd2ccc..b478138befe57 100644 --- a/posthog/api/test/__snapshots__/test_decide.ambr +++ b/posthog/api/test/__snapshots__/test_decide.ambr @@ -1,6 +1,3 @@ -# name: TestDatabaseCheckForDecide.test_decide_doesnt_error_out_when_database_is_down_and_database_check_isnt_cached - 'SELECT 1' ---- # name: TestDecide.test_decide_doesnt_error_out_when_database_is_down ' SELECT "posthog_user"."id", @@ -364,6 +361,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating", @@ -387,6 +385,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating", @@ -520,6 +519,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating", @@ -555,6 +555,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating", diff --git a/posthog/api/test/__snapshots__/test_feature_flag.ambr b/posthog/api/test/__snapshots__/test_feature_flag.ambr index 6fc6c63c17f20..db2c66f1aea98 100644 --- a/posthog/api/test/__snapshots__/test_feature_flag.ambr +++ b/posthog/api/test/__snapshots__/test_feature_flag.ambr @@ -94,7 +94,7 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestBlastRadius.test_user_blast_radius_with_multiple_precalculated_cohorts.2 @@ -104,7 +104,7 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = NULL + AND version = 0 ' --- # name: TestBlastRadius.test_user_blast_radius_with_multiple_precalculated_cohorts.3 @@ -114,11 +114,31 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestBlastRadius.test_user_blast_radius_with_multiple_precalculated_cohorts.4 ' + + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = NULL + ' +--- +# name: TestBlastRadius.test_user_blast_radius_with_multiple_precalculated_cohorts.5 + ' + + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 0 + ' +--- +# name: TestBlastRadius.test_user_blast_radius_with_multiple_precalculated_cohorts.6 + ' /* user_id:0 request:_snapshot_ */ SELECT count(1) FROM @@ -141,7 +161,7 @@ HAVING max(is_deleted) = 0 SETTINGS optimize_aggregation_in_order = 1) ' --- -# name: TestBlastRadius.test_user_blast_radius_with_multiple_precalculated_cohorts.5 +# name: TestBlastRadius.test_user_blast_radius_with_multiple_precalculated_cohorts.7 ' /* user_id:0 request:_snapshot_ */ SELECT count(1) @@ -217,7 +237,7 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestBlastRadius.test_user_blast_radius_with_multiple_static_cohorts.5 @@ -227,7 +247,7 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = NULL + AND version = 0 ' --- # name: TestBlastRadius.test_user_blast_radius_with_multiple_static_cohorts.6 @@ -237,11 +257,31 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestBlastRadius.test_user_blast_radius_with_multiple_static_cohorts.7 ' + + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = NULL + ' +--- +# name: TestBlastRadius.test_user_blast_radius_with_multiple_static_cohorts.8 + ' + + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 0 + ' +--- +# name: TestBlastRadius.test_user_blast_radius_with_multiple_static_cohorts.9 + ' /* user_id:0 request:_snapshot_ */ SELECT count(1) FROM @@ -312,11 +352,21 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestBlastRadius.test_user_blast_radius_with_single_cohort.4 ' + + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 0 + ' +--- +# name: TestBlastRadius.test_user_blast_radius_with_single_cohort.5 + ' /* user_id:0 request:_snapshot_ */ SELECT count(1) FROM diff --git a/posthog/migrations/0362_cohort_post_to_webhook.py b/posthog/migrations/0362_cohort_post_to_webhook.py new file mode 100644 index 0000000000000..8d6e6a925a461 --- /dev/null +++ b/posthog/migrations/0362_cohort_post_to_webhook.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.19 on 2023-11-17 15:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("posthog", "0361_add_plugin_config_ui_fields"), + ] + + operations = [ + migrations.AddField( + model_name="cohort", + name="post_to_webhook", + field=models.BooleanField(default=False), + ), + ] diff --git a/posthog/migrations/0365_merge_20231118_0612.py b/posthog/migrations/0365_merge_20231118_0612.py new file mode 100644 index 0000000000000..417fac4138540 --- /dev/null +++ b/posthog/migrations/0365_merge_20231118_0612.py @@ -0,0 +1,14 @@ +# Generated by Django 3.2.19 on 2023-11-18 06:12 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('posthog', '0362_cohort_post_to_webhook'), + ('posthog', '0364_team_external_data_workspace_rows'), + ] + + operations = [ + ] diff --git a/posthog/models/cohort/cohort.py b/posthog/models/cohort/cohort.py index b907df41c934a..2094c43c0c27f 100644 --- a/posthog/models/cohort/cohort.py +++ b/posthog/models/cohort/cohort.py @@ -80,6 +80,7 @@ class Cohort(models.Model): version: models.IntegerField = models.IntegerField(blank=True, null=True) pending_version: models.IntegerField = models.IntegerField(blank=True, null=True) count: models.IntegerField = models.IntegerField(blank=True, null=True) + post_to_webhook: models.BooleanField = models.BooleanField(default=False) created_by: models.ForeignKey = models.ForeignKey("User", on_delete=models.SET_NULL, blank=True, null=True) created_at: models.DateTimeField = models.DateTimeField(default=timezone.now, blank=True, null=True) @@ -192,6 +193,8 @@ def get_analytics_metadata(self): def calculate_people_ch(self, pending_version): from posthog.models.cohort.util import recalculate_cohortpeople from posthog.tasks.calculate_cohort import clear_stale_cohort + from posthog.models.cohort.util import call_webhook_on_cohort_update + from posthog.models.cohort.util import get_cohort_size logger.warn( "cohort_calculation_started", @@ -201,12 +204,16 @@ def calculate_people_ch(self, pending_version): ) start_time = time.monotonic() + before_count = get_cohort_size(self) + try: count = recalculate_cohortpeople(self, pending_version) self.count = count self.last_calculation = timezone.now() self.errors_calculating = 0 + if count != before_count and self.post_to_webhook: + call_webhook_on_cohort_update(before_count, count, self) except Exception: self.errors_calculating = F("errors_calculating") + 1 logger.warning( diff --git a/posthog/models/cohort/util.py b/posthog/models/cohort/util.py index abd4e6c89920c..ba5f0064bc14f 100644 --- a/posthog/models/cohort/util.py +++ b/posthog/models/cohort/util.py @@ -1,4 +1,5 @@ import uuid +import requests from datetime import datetime, timedelta from typing import Any, Dict, List, Optional, Set, Tuple, Union @@ -14,6 +15,7 @@ from posthog.models import Action, Filter, Team from posthog.models.action.util import format_action_filter from posthog.models.async_deletion import AsyncDeletion, DeletionType +import json from posthog.models.cohort.cohort import Cohort from posthog.models.cohort.sql import ( CALCULATE_COHORT_PEOPLE_SQL, @@ -470,6 +472,25 @@ def get_dependent_cohorts( return cohorts +def call_webhook_on_cohort_update( + before_cohortpeople_count: int, after_cohortpeople_count: int, cohort: Cohort +) -> None: + team = Team.objects.filter(pk=cohort.team_id).get() + if team.slack_incoming_webhook: + webhook_url = team.slack_incoming_webhook + else: + return + change = abs(after_cohortpeople_count - before_cohortpeople_count) + is_addition = after_cohortpeople_count > before_cohortpeople_count + message = f"{change} {'persons' if change > 1 else 'person'} {'have' if change > 1 else 'has'} been {'added' if is_addition else 'removed'} {'to' if is_addition else 'from'} a cohort named {cohort.name}." + data = {"message": message} + headers = {"Content-Type": "application/json"} + try: + requests.post(webhook_url, data=json.dumps(data), headers=headers) + except requests.RequestException as e: + logger.warn(f"Error sending webhook: {e}") + + def sort_cohorts_topologically(cohort_ids: Set[int], seen_cohorts_cache: Dict[str, Cohort]) -> List[int]: """ Sorts the given cohorts in an order where cohorts with no dependencies are placed first, diff --git a/posthog/models/filters/test/__snapshots__/test_filter.ambr b/posthog/models/filters/test/__snapshots__/test_filter.ambr index c236a5d28a6fa..21d281a07f776 100644 --- a/posthog/models/filters/test/__snapshots__/test_filter.ambr +++ b/posthog/models/filters/test/__snapshots__/test_filter.ambr @@ -379,6 +379,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating", @@ -451,6 +452,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating", @@ -514,6 +516,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating", @@ -537,6 +540,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating", @@ -560,6 +564,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating", @@ -583,6 +588,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating", diff --git a/posthog/queries/funnels/test/__snapshots__/test_funnel.ambr b/posthog/queries/funnels/test/__snapshots__/test_funnel.ambr index 811e4253d9704..612db3bdcf8b8 100644 --- a/posthog/queries/funnels/test/__snapshots__/test_funnel.ambr +++ b/posthog/queries/funnels/test/__snapshots__/test_funnel.ambr @@ -373,12 +373,22 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestFOSSFunnel.test_funnel_with_precalculated_cohort_step_filter.2 ' + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 0 + ' +--- +# name: TestFOSSFunnel.test_funnel_with_precalculated_cohort_step_filter.3 + ' + SELECT countIf(steps = 1) step_1, countIf(steps = 2) step_2, avg(step_1_average_conversion_time_inner) step_1_average_conversion_time, diff --git a/posthog/queries/funnels/test/__snapshots__/test_funnel_persons.ambr b/posthog/queries/funnels/test/__snapshots__/test_funnel_persons.ambr deleted file mode 100644 index e45604987f687..0000000000000 --- a/posthog/queries/funnels/test/__snapshots__/test_funnel_persons.ambr +++ /dev/null @@ -1,525 +0,0 @@ -# name: TestFunnelPersons.test_funnel_person_recordings - ' - - SELECT aggregation_target AS actor_id, - step_0_matching_events as matching_events - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner, - groupArray(10)(step_0_matching_event) as step_0_matching_events, - groupArray(10)(step_1_matching_event) as step_1_matching_events, - groupArray(10)(step_2_matching_event) as step_2_matching_events, - groupArray(10)(final_matching_event) as final_matching_events - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2, - if(latest_2 < latest_1, NULL, "uuid_2") as "uuid_2", - if(latest_2 < latest_1, NULL, "$session_id_2") as "$session_id_2", - if(latest_2 < latest_1, NULL, "$window_id_2") as "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - last_value("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_1", - last_value("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_1", - last_value("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps) - WHERE steps IN [1, 2, 3] - ORDER BY aggregation_target - LIMIT 100 - OFFSET 0 - ' ---- -# name: TestFunnelPersons.test_funnel_person_recordings.1 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s1'] - AND min_first_timestamp >= '2020-12-31 00:00:00' - AND max_last_timestamp <= '2021-01-09 23:59:59' - ' ---- -# name: TestFunnelPersons.test_funnel_person_recordings.2 - ' - - SELECT aggregation_target AS actor_id, - step_1_matching_events as matching_events - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner, - groupArray(10)(step_0_matching_event) as step_0_matching_events, - groupArray(10)(step_1_matching_event) as step_1_matching_events, - groupArray(10)(step_2_matching_event) as step_2_matching_events, - groupArray(10)(final_matching_event) as final_matching_events - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2, - if(latest_2 < latest_1, NULL, "uuid_2") as "uuid_2", - if(latest_2 < latest_1, NULL, "$session_id_2") as "$session_id_2", - if(latest_2 < latest_1, NULL, "$window_id_2") as "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - last_value("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_1", - last_value("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_1", - last_value("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps) - WHERE steps IN [2, 3] - ORDER BY aggregation_target - LIMIT 100 - OFFSET 0 - ' ---- -# name: TestFunnelPersons.test_funnel_person_recordings.3 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s2'] - AND min_first_timestamp >= '2020-12-31 00:00:00' - AND max_last_timestamp <= '2021-01-09 23:59:59' - ' ---- -# name: TestFunnelPersons.test_funnel_person_recordings.4 - ' - - SELECT aggregation_target AS actor_id, - step_1_matching_events as matching_events - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner, - groupArray(10)(step_0_matching_event) as step_0_matching_events, - groupArray(10)(step_1_matching_event) as step_1_matching_events, - groupArray(10)(step_2_matching_event) as step_2_matching_events, - groupArray(10)(final_matching_event) as final_matching_events - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2, - if(latest_2 < latest_1, NULL, "uuid_2") as "uuid_2", - if(latest_2 < latest_1, NULL, "$session_id_2") as "$session_id_2", - if(latest_2 < latest_1, NULL, "$window_id_2") as "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - last_value("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_1", - last_value("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_1", - last_value("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps) - WHERE steps = 2 - ORDER BY aggregation_target - LIMIT 100 - OFFSET 0 - ' ---- -# name: TestFunnelPersons.test_funnel_person_recordings.5 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s2'] - AND min_first_timestamp >= '2020-12-31 00:00:00' - AND max_last_timestamp <= '2021-01-09 23:59:59' - ' ---- diff --git a/posthog/queries/funnels/test/__snapshots__/test_funnel_strict.ambr b/posthog/queries/funnels/test/__snapshots__/test_funnel_strict.ambr deleted file mode 100644 index d92a99dc53dd8..0000000000000 --- a/posthog/queries/funnels/test/__snapshots__/test_funnel_strict.ambr +++ /dev/null @@ -1,268 +0,0 @@ -# name: TestFunnelStrictStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen - ' - - SELECT groupArray(value) - FROM - (SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS value, - count(*) as count - FROM events e - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - GROUP BY value - ORDER BY count DESC, value DESC - LIMIT 25 - OFFSET 0) - ' ---- -# name: TestFunnelStrictStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen.1 - ' - - SELECT countIf(steps = 1) step_1, - countIf(steps = 2) step_2, - avg(step_1_average_conversion_time_inner) step_1_average_conversion_time, - median(step_1_median_conversion_time_inner) step_1_median_conversion_time, - prop - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - prop - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target, - prop) as max_steps, - step_1_conversion_time, - prop - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1) AS steps, - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target, - prop - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) latest_1 , - if(has([[''], ['Mac'], ['Chrome'], ['Safari']], prop), prop, ['Other']) as prop - FROM - (SELECT *, - if(notEmpty(arrayFilter(x -> notEmpty(x), prop_vals)), prop_vals, ['']) as prop - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'sign up', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'buy' - AND (has(['xyz'], replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', ''))), 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS prop_basic, - prop_basic as prop, - argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) over (PARTITION by aggregation_target) as prop_vals - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - AND (1=1) ))) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps, - prop - HAVING steps = max_steps) - GROUP BY prop - ' ---- -# name: TestFunnelStrictStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step - ' - - SELECT groupArray(value) - FROM - (SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS value, - count(*) as count - FROM events e - WHERE team_id = 2 - AND event = 'buy' - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - AND (has(['xyz'], replaceRegexpAll(JSONExtractRaw(e.properties, '$version'), '^"|"$', ''))) - GROUP BY value - ORDER BY count DESC, value DESC - LIMIT 25 - OFFSET 0) - ' ---- -# name: TestFunnelStrictStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step.1 - ' - - SELECT countIf(steps = 1) step_1, - countIf(steps = 2) step_2, - avg(step_1_average_conversion_time_inner) step_1_average_conversion_time, - median(step_1_median_conversion_time_inner) step_1_median_conversion_time, - prop - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - prop - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target, - prop) as max_steps, - step_1_conversion_time, - prop - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1) AS steps, - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target, - prop - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) latest_1 , - if(has([['Safari'], ['Mac']], prop), prop, ['Other']) as prop - FROM - (SELECT *, - prop - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'sign up', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'buy' - AND (has(['xyz'], replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', ''))), 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS prop_basic, - if(step_0 = 1, prop_basic, []) as prop_0, - if(step_1 = 1, prop_basic, []) as prop_1, - prop_1 as prop, - groupUniqArray(prop) over (PARTITION by aggregation_target) as prop_vals - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - AND (1=1) ) ARRAY - JOIN prop_vals as prop - WHERE prop != [] )) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps, - prop - HAVING steps = max_steps) - GROUP BY prop - ' ---- -# name: TestFunnelStrictStepsBreakdown.test_funnel_step_multiple_breakdown_snapshot - ' - - SELECT groupArray(value) - FROM - (SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', ''), replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', '')) AS value, - count(*) as count - FROM events e - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - GROUP BY value - ORDER BY count DESC, value DESC - LIMIT 25 - OFFSET 0) - ' ---- -# name: TestFunnelStrictStepsBreakdown.test_funnel_step_multiple_breakdown_snapshot.1 - ' - - SELECT countIf(steps = 1) step_1, - countIf(steps = 2) step_2, - avg(step_1_average_conversion_time_inner) step_1_average_conversion_time, - median(step_1_median_conversion_time_inner) step_1_median_conversion_time, - prop - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - prop - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target, - prop) as max_steps, - step_1_conversion_time, - prop - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1) AS steps, - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target, - prop - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) latest_1 , - if(has([['', ''], ['alakazam', ''], ['Safari', 'xyz'], ['Mac', ''], ['Chrome', 'xyz'], ['0', '0'], ['', 'no-mac']], prop), prop, ['Other']) as prop - FROM - (SELECT *, - if(notEmpty(arrayFilter(x -> notEmpty(x), prop_vals)), prop_vals, ['','']) as prop - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'sign up', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'buy', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', ''), replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', '')) AS prop_basic, - prop_basic as prop, - argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) over (PARTITION by aggregation_target) as prop_vals - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - AND (1=1) ))) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps, - prop - HAVING steps = max_steps) - GROUP BY prop - ' ---- diff --git a/posthog/queries/funnels/test/__snapshots__/test_funnel_strict_persons.ambr b/posthog/queries/funnels/test/__snapshots__/test_funnel_strict_persons.ambr deleted file mode 100644 index 357898144a3fc..0000000000000 --- a/posthog/queries/funnels/test/__snapshots__/test_funnel_strict_persons.ambr +++ /dev/null @@ -1,408 +0,0 @@ -# name: TestFunnelStrictStepsPersons.test_strict_funnel_person_recordings - ' - - SELECT aggregation_target AS actor_id, - step_0_matching_events as matching_events - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner , - groupArray(10)(step_0_matching_event) as step_0_matching_events, - groupArray(10)(step_1_matching_event) as step_1_matching_events, - groupArray(10)(step_2_matching_event) as step_2_matching_events, - groupArray(10)(final_matching_event) as final_matching_events - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time , - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps, - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) latest_1, - min("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) "uuid_1", - min("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) "$session_id_1", - min("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) latest_2, - min("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) "uuid_2", - min("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) "$session_id_2", - min("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-01-08 23:59:59', 'UTC') - AND (1=1) )) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps) - WHERE steps IN [1, 2, 3] - ORDER BY aggregation_target - LIMIT 100 - OFFSET 0 - ' ---- -# name: TestFunnelStrictStepsPersons.test_strict_funnel_person_recordings.1 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s1'] - AND min_first_timestamp >= '2020-12-31 00:00:00' - AND max_last_timestamp <= '2021-01-09 23:59:59' - ' ---- -# name: TestFunnelStrictStepsPersons.test_strict_funnel_person_recordings.2 - ' - - SELECT aggregation_target AS actor_id, - step_1_matching_events as matching_events - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner , - groupArray(10)(step_0_matching_event) as step_0_matching_events, - groupArray(10)(step_1_matching_event) as step_1_matching_events, - groupArray(10)(step_2_matching_event) as step_2_matching_events, - groupArray(10)(final_matching_event) as final_matching_events - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time , - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps, - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) latest_1, - min("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) "uuid_1", - min("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) "$session_id_1", - min("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) latest_2, - min("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) "uuid_2", - min("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) "$session_id_2", - min("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-01-08 23:59:59', 'UTC') - AND (1=1) )) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps) - WHERE steps IN [2, 3] - ORDER BY aggregation_target - LIMIT 100 - OFFSET 0 - ' ---- -# name: TestFunnelStrictStepsPersons.test_strict_funnel_person_recordings.3 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s2'] - AND min_first_timestamp >= '2020-12-31 00:00:00' - AND max_last_timestamp <= '2021-01-09 23:59:59' - ' ---- -# name: TestFunnelStrictStepsPersons.test_strict_funnel_person_recordings.4 - ' - - SELECT aggregation_target AS actor_id, - step_1_matching_events as matching_events - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner , - groupArray(10)(step_0_matching_event) as step_0_matching_events, - groupArray(10)(step_1_matching_event) as step_1_matching_events, - groupArray(10)(step_2_matching_event) as step_2_matching_events, - groupArray(10)(final_matching_event) as final_matching_events - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time , - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps, - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) latest_1, - min("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) "uuid_1", - min("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) "$session_id_1", - min("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) latest_2, - min("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) "uuid_2", - min("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) "$session_id_2", - min("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-01-08 23:59:59', 'UTC') - AND (1=1) )) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps) - WHERE steps = 2 - ORDER BY aggregation_target - LIMIT 100 - OFFSET 0 - ' ---- -# name: TestFunnelStrictStepsPersons.test_strict_funnel_person_recordings.5 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s2'] - AND min_first_timestamp >= '2020-12-31 00:00:00' - AND max_last_timestamp <= '2021-01-09 23:59:59' - ' ---- diff --git a/posthog/queries/funnels/test/__snapshots__/test_funnel_time_to_convert.ambr b/posthog/queries/funnels/test/__snapshots__/test_funnel_time_to_convert.ambr deleted file mode 100644 index 0e16ceb59d50c..0000000000000 --- a/posthog/queries/funnels/test/__snapshots__/test_funnel_time_to_convert.ambr +++ /dev/null @@ -1,646 +0,0 @@ -# name: TestFunnelTimeToConvert.test_auto_bin_count_single_step - ' - WITH step_runs AS - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2 - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-06-07 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-06-13 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps), - histogram_params AS - (SELECT ifNull(floor(min(step_1_average_conversion_time_inner)), 0) AS from_seconds, - ifNull(ceil(max(step_1_average_conversion_time_inner)), 1) AS to_seconds, - round(avg(step_1_average_conversion_time_inner), 2) AS average_conversion_time, - count() AS sample_count, - least(60, greatest(1, ceil(cbrt(ifNull(sample_count, 0))))) AS bin_count, - ceil((to_seconds - from_seconds) / bin_count) AS bin_width_seconds_raw, - if(bin_width_seconds_raw > 0, bin_width_seconds_raw, 60) AS bin_width_seconds - FROM step_runs - WHERE step_1_average_conversion_time_inner IS NOT NULL ), - - (SELECT bin_width_seconds - FROM histogram_params) AS bin_width_seconds, - - (SELECT bin_count - FROM histogram_params) AS bin_count, - - (SELECT from_seconds - FROM histogram_params) AS histogram_from_seconds, - - (SELECT to_seconds - FROM histogram_params) AS histogram_to_seconds, - - (SELECT average_conversion_time - FROM histogram_params) AS histogram_average_conversion_time - SELECT bin_from_seconds, - person_count, - histogram_average_conversion_time AS average_conversion_time - FROM - (SELECT histogram_from_seconds + floor((step_1_average_conversion_time_inner - histogram_from_seconds) / bin_width_seconds) * bin_width_seconds AS bin_from_seconds, - count() AS person_count - FROM step_runs - GROUP BY bin_from_seconds) results - RIGHT OUTER JOIN - (SELECT histogram_from_seconds + number * bin_width_seconds AS bin_from_seconds - FROM system.numbers - LIMIT ifNull(bin_count, 0) + 1) fill USING (bin_from_seconds) - ORDER BY bin_from_seconds - ' ---- -# name: TestFunnelTimeToConvert.test_auto_bin_count_total - ' - WITH step_runs AS - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2 - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-06-07 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-06-13 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps), - histogram_params AS - (SELECT ifNull(floor(min(step_1_average_conversion_time_inner + step_2_average_conversion_time_inner)), 0) AS from_seconds, - ifNull(ceil(max(step_1_average_conversion_time_inner + step_2_average_conversion_time_inner)), 1) AS to_seconds, - round(avg(step_1_average_conversion_time_inner + step_2_average_conversion_time_inner), 2) AS average_conversion_time, - count() AS sample_count, - least(60, greatest(1, ceil(cbrt(ifNull(sample_count, 0))))) AS bin_count, - ceil((to_seconds - from_seconds) / bin_count) AS bin_width_seconds_raw, - if(bin_width_seconds_raw > 0, bin_width_seconds_raw, 60) AS bin_width_seconds - FROM step_runs - WHERE step_2_average_conversion_time_inner IS NOT NULL ), - - (SELECT bin_width_seconds - FROM histogram_params) AS bin_width_seconds, - - (SELECT bin_count - FROM histogram_params) AS bin_count, - - (SELECT from_seconds - FROM histogram_params) AS histogram_from_seconds, - - (SELECT to_seconds - FROM histogram_params) AS histogram_to_seconds, - - (SELECT average_conversion_time - FROM histogram_params) AS histogram_average_conversion_time - SELECT bin_from_seconds, - person_count, - histogram_average_conversion_time AS average_conversion_time - FROM - (SELECT histogram_from_seconds + floor((step_1_average_conversion_time_inner + step_2_average_conversion_time_inner - histogram_from_seconds) / bin_width_seconds) * bin_width_seconds AS bin_from_seconds, - count() AS person_count - FROM step_runs - GROUP BY bin_from_seconds) results - RIGHT OUTER JOIN - (SELECT histogram_from_seconds + number * bin_width_seconds AS bin_from_seconds - FROM system.numbers - LIMIT ifNull(bin_count, 0) + 1) fill USING (bin_from_seconds) - ORDER BY bin_from_seconds - ' ---- -# name: TestFunnelTimeToConvert.test_auto_bin_count_total.1 - ' - WITH step_runs AS - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2 - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-06-07 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-06-13 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps), - histogram_params AS - (SELECT ifNull(floor(min(step_1_average_conversion_time_inner + step_2_average_conversion_time_inner)), 0) AS from_seconds, - ifNull(ceil(max(step_1_average_conversion_time_inner + step_2_average_conversion_time_inner)), 1) AS to_seconds, - round(avg(step_1_average_conversion_time_inner + step_2_average_conversion_time_inner), 2) AS average_conversion_time, - count() AS sample_count, - least(60, greatest(1, ceil(cbrt(ifNull(sample_count, 0))))) AS bin_count, - ceil((to_seconds - from_seconds) / bin_count) AS bin_width_seconds_raw, - if(bin_width_seconds_raw > 0, bin_width_seconds_raw, 60) AS bin_width_seconds - FROM step_runs - WHERE step_2_average_conversion_time_inner IS NOT NULL ), - - (SELECT bin_width_seconds - FROM histogram_params) AS bin_width_seconds, - - (SELECT bin_count - FROM histogram_params) AS bin_count, - - (SELECT from_seconds - FROM histogram_params) AS histogram_from_seconds, - - (SELECT to_seconds - FROM histogram_params) AS histogram_to_seconds, - - (SELECT average_conversion_time - FROM histogram_params) AS histogram_average_conversion_time - SELECT bin_from_seconds, - person_count, - histogram_average_conversion_time AS average_conversion_time - FROM - (SELECT histogram_from_seconds + floor((step_1_average_conversion_time_inner + step_2_average_conversion_time_inner - histogram_from_seconds) / bin_width_seconds) * bin_width_seconds AS bin_from_seconds, - count() AS person_count - FROM step_runs - GROUP BY bin_from_seconds) results - RIGHT OUTER JOIN - (SELECT histogram_from_seconds + number * bin_width_seconds AS bin_from_seconds - FROM system.numbers - LIMIT ifNull(bin_count, 0) + 1) fill USING (bin_from_seconds) - ORDER BY bin_from_seconds - ' ---- -# name: TestFunnelTimeToConvert.test_basic_strict - ' - WITH step_runs AS - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps, - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) latest_2 - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2 - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-06-07 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-06-13 23:59:59', 'UTC') - AND (1=1) )) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps), - histogram_params AS - (SELECT ifNull(floor(min(step_1_average_conversion_time_inner)), 0) AS from_seconds, - ifNull(ceil(max(step_1_average_conversion_time_inner)), 1) AS to_seconds, - round(avg(step_1_average_conversion_time_inner), 2) AS average_conversion_time, - count() AS sample_count, - least(60, greatest(1, ceil(cbrt(ifNull(sample_count, 0))))) AS bin_count, - ceil((to_seconds - from_seconds) / bin_count) AS bin_width_seconds_raw, - if(bin_width_seconds_raw > 0, bin_width_seconds_raw, 60) AS bin_width_seconds - FROM step_runs - WHERE step_1_average_conversion_time_inner IS NOT NULL ), - - (SELECT bin_width_seconds - FROM histogram_params) AS bin_width_seconds, - - (SELECT bin_count - FROM histogram_params) AS bin_count, - - (SELECT from_seconds - FROM histogram_params) AS histogram_from_seconds, - - (SELECT to_seconds - FROM histogram_params) AS histogram_to_seconds, - - (SELECT average_conversion_time - FROM histogram_params) AS histogram_average_conversion_time - SELECT bin_from_seconds, - person_count, - histogram_average_conversion_time AS average_conversion_time - FROM - (SELECT histogram_from_seconds + floor((step_1_average_conversion_time_inner - histogram_from_seconds) / bin_width_seconds) * bin_width_seconds AS bin_from_seconds, - count() AS person_count - FROM step_runs - GROUP BY bin_from_seconds) results - RIGHT OUTER JOIN - (SELECT histogram_from_seconds + number * bin_width_seconds AS bin_from_seconds - FROM system.numbers - LIMIT ifNull(bin_count, 0) + 1) fill USING (bin_from_seconds) - ORDER BY bin_from_seconds - ' ---- -# name: TestFunnelTimeToConvert.test_basic_unordered - ' - WITH step_runs AS - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time - FROM - (SELECT *, - arraySort([latest_0,latest_1,latest_2]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0),if(latest_0 < latest_2 AND latest_2 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1,latest_2]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time, - if(isNotNull(conversion_times[3]) - AND conversion_times[3] <= conversion_times[2] + INTERVAL 7 DAY, dateDiff('second', conversion_times[2], conversion_times[3]), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2 - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-06-07 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-06-13 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )) - WHERE step_0 = 1 - UNION ALL SELECT *, - arraySort([latest_0,latest_1,latest_2]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0),if(latest_0 < latest_2 AND latest_2 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1,latest_2]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time, - if(isNotNull(conversion_times[3]) - AND conversion_times[3] <= conversion_times[2] + INTERVAL 7 DAY, dateDiff('second', conversion_times[2], conversion_times[3]), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'step two', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'step three', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(event = 'step one', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2 - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-06-07 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-06-13 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )) - WHERE step_0 = 1 - UNION ALL SELECT *, - arraySort([latest_0,latest_1,latest_2]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0),if(latest_0 < latest_2 AND latest_2 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1,latest_2]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time, - if(isNotNull(conversion_times[3]) - AND conversion_times[3] <= conversion_times[2] + INTERVAL 7 DAY, dateDiff('second', conversion_times[2], conversion_times[3]), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'step three', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'step one', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(event = 'step two', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2 - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-06-07 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-06-13 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps), - histogram_params AS - (SELECT ifNull(floor(min(step_1_average_conversion_time_inner)), 0) AS from_seconds, - ifNull(ceil(max(step_1_average_conversion_time_inner)), 1) AS to_seconds, - round(avg(step_1_average_conversion_time_inner), 2) AS average_conversion_time, - count() AS sample_count, - least(60, greatest(1, ceil(cbrt(ifNull(sample_count, 0))))) AS bin_count, - ceil((to_seconds - from_seconds) / bin_count) AS bin_width_seconds_raw, - if(bin_width_seconds_raw > 0, bin_width_seconds_raw, 60) AS bin_width_seconds - FROM step_runs - WHERE step_1_average_conversion_time_inner IS NOT NULL ), - - (SELECT bin_width_seconds - FROM histogram_params) AS bin_width_seconds, - - (SELECT bin_count - FROM histogram_params) AS bin_count, - - (SELECT from_seconds - FROM histogram_params) AS histogram_from_seconds, - - (SELECT to_seconds - FROM histogram_params) AS histogram_to_seconds, - - (SELECT average_conversion_time - FROM histogram_params) AS histogram_average_conversion_time - SELECT bin_from_seconds, - person_count, - histogram_average_conversion_time AS average_conversion_time - FROM - (SELECT histogram_from_seconds + floor((step_1_average_conversion_time_inner - histogram_from_seconds) / bin_width_seconds) * bin_width_seconds AS bin_from_seconds, - count() AS person_count - FROM step_runs - GROUP BY bin_from_seconds) results - RIGHT OUTER JOIN - (SELECT histogram_from_seconds + number * bin_width_seconds AS bin_from_seconds - FROM system.numbers - LIMIT ifNull(bin_count, 0) + 1) fill USING (bin_from_seconds) - ORDER BY bin_from_seconds - ' ---- diff --git a/posthog/queries/funnels/test/__snapshots__/test_funnel_trends.ambr b/posthog/queries/funnels/test/__snapshots__/test_funnel_trends.ambr deleted file mode 100644 index 49699ea7b27f0..0000000000000 --- a/posthog/queries/funnels/test/__snapshots__/test_funnel_trends.ambr +++ /dev/null @@ -1,333 +0,0 @@ -# name: TestFunnelTrends.test_timezones_trends - ' - - SELECT entrance_period_start, - reached_from_step_count, - reached_to_step_count, - if(reached_from_step_count > 0, round(reached_to_step_count / reached_from_step_count * 100, 2), 0) AS conversion_rate - FROM - (SELECT entrance_period_start, - countIf(steps_completed >= 1) AS reached_from_step_count, - countIf(steps_completed >= 3) AS reached_to_step_count - FROM - (SELECT aggregation_target, - toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) AS entrance_period_start, - max(steps) AS steps_completed - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2 - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-04-30 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-05-07 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 ) - GROUP BY aggregation_target, - entrance_period_start) - GROUP BY entrance_period_start) data - RIGHT OUTER JOIN - (SELECT toStartOfDay(toDateTime('2021-04-30 00:00:00', 'UTC')) + toIntervalDay(number) AS entrance_period_start - FROM numbers(dateDiff('day', toStartOfDay(toDateTime('2021-04-30 00:00:00', 'UTC')), toStartOfDay(toDateTime('2021-05-07 00:00:00', 'UTC'))) + 1) AS period_offsets) fill USING (entrance_period_start) - ORDER BY entrance_period_start ASC - ' ---- -# name: TestFunnelTrends.test_timezones_trends.1 - ' - - SELECT entrance_period_start, - reached_from_step_count, - reached_to_step_count, - if(reached_from_step_count > 0, round(reached_to_step_count / reached_from_step_count * 100, 2), 0) AS conversion_rate - FROM - (SELECT entrance_period_start, - countIf(steps_completed >= 1) AS reached_from_step_count, - countIf(steps_completed >= 3) AS reached_to_step_count - FROM - (SELECT aggregation_target, - toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'US/Pacific')) AS entrance_period_start, - max(steps) AS steps_completed - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2 - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'US/Pacific') >= toDateTime('2021-04-30 00:00:00', 'US/Pacific') - AND toTimeZone(timestamp, 'US/Pacific') <= toDateTime('2021-05-07 23:59:59', 'US/Pacific') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 ) - GROUP BY aggregation_target, - entrance_period_start) - GROUP BY entrance_period_start) data - RIGHT OUTER JOIN - (SELECT toStartOfDay(toDateTime('2021-04-30 00:00:00', 'US/Pacific')) + toIntervalDay(number) AS entrance_period_start - FROM numbers(dateDiff('day', toStartOfDay(toDateTime('2021-04-30 00:00:00', 'US/Pacific')), toStartOfDay(toDateTime('2021-05-07 00:00:00', 'US/Pacific'))) + 1) AS period_offsets) fill USING (entrance_period_start) - ORDER BY entrance_period_start ASC - ' ---- -# name: TestFunnelTrends.test_week_interval - ' - - SELECT entrance_period_start, - reached_from_step_count, - reached_to_step_count, - if(reached_from_step_count > 0, round(reached_to_step_count / reached_from_step_count * 100, 2), 0) AS conversion_rate - FROM - (SELECT entrance_period_start, - countIf(steps_completed >= 1) AS reached_from_step_count, - countIf(steps_completed >= 3) AS reached_to_step_count - FROM - (SELECT aggregation_target, - toStartOfWeek(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC'), 0) AS entrance_period_start, - max(steps) AS steps_completed - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2 - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-05-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-05-07 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 ) - GROUP BY aggregation_target, - entrance_period_start) - GROUP BY entrance_period_start) data - RIGHT OUTER JOIN - (SELECT toStartOfWeek(toDateTime('2021-05-01 00:00:00', 'UTC'), 0) + toIntervalWeek(number) AS entrance_period_start - FROM numbers(dateDiff('week', toStartOfWeek(toDateTime('2021-05-01 00:00:00', 'UTC'), 0), toStartOfWeek(toDateTime('2021-05-07 00:00:00', 'UTC'), 0)) + 1) AS period_offsets) fill USING (entrance_period_start) - ORDER BY entrance_period_start ASC - ' ---- -# name: TestFunnelTrends.test_week_interval.1 - ' - - SELECT aggregation_target AS actor_id - FROM - (SELECT aggregation_target, - toStartOfWeek(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC'), 0) AS entrance_period_start, - max(steps) AS steps_completed - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 7 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 7 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 7 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - latest_1, - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2 - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2 - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2 - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-05-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-05-07 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 ) - WHERE toDateTime(entrance_period_start) = '2021-04-25 00:00:00' - GROUP BY aggregation_target, - entrance_period_start) - WHERE steps_completed >= 3 - ORDER BY aggregation_target - LIMIT 100 - OFFSET 0 - ' ---- diff --git a/posthog/queries/funnels/test/__snapshots__/test_funnel_trends_persons.ambr b/posthog/queries/funnels/test/__snapshots__/test_funnel_trends_persons.ambr deleted file mode 100644 index ea8be26d05717..0000000000000 --- a/posthog/queries/funnels/test/__snapshots__/test_funnel_trends_persons.ambr +++ /dev/null @@ -1,493 +0,0 @@ -# name: TestFunnelTrendsPersons.test_funnel_trend_persons_returns_recordings - ' - - SELECT aggregation_target AS actor_id, - step_1_matching_events as matching_events - FROM - (SELECT aggregation_target, - toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) AS entrance_period_start, - max(steps) AS steps_completed , - groupArray(10)(step_0_matching_event) as step_0_matching_events, - groupArray(10)(step_1_matching_event) as step_1_matching_events, - groupArray(10)(step_2_matching_event) as step_2_matching_events, - groupArray(10)(final_matching_event) as final_matching_events - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 14 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 14 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 14 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 14 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 14 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2, - if(latest_2 < latest_1, NULL, "uuid_2") as "uuid_2", - if(latest_2 < latest_1, NULL, "$session_id_2") as "$session_id_2", - if(latest_2 < latest_1, NULL, "$window_id_2") as "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - last_value("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_1", - last_value("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_1", - last_value("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-05-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-05-07 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 ) - WHERE toDateTime(entrance_period_start) = '2021-05-01 00:00:00' - GROUP BY aggregation_target, - entrance_period_start) - WHERE steps_completed >= 2 - ORDER BY aggregation_target - LIMIT 100 - OFFSET 0 - ' ---- -# name: TestFunnelTrendsPersons.test_funnel_trend_persons_returns_recordings.1 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s1b'] - AND min_first_timestamp >= '2021-04-30 00:00:00' - AND max_last_timestamp <= '2021-05-08 23:59:59' - ' ---- -# name: TestFunnelTrendsPersons.test_funnel_trend_persons_returns_recordings.2 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s1b'] - AND min_first_timestamp >= '2021-04-30 00:00:00' - AND max_last_timestamp <= '2021-05-08 23:59:59' - ' ---- -# name: TestFunnelTrendsPersons.test_funnel_trend_persons_with_drop_off - ' - - SELECT aggregation_target AS actor_id, - final_matching_events as matching_events - FROM - (SELECT aggregation_target, - toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) AS entrance_period_start, - max(steps) AS steps_completed , - groupArray(10)(step_0_matching_event) as step_0_matching_events, - groupArray(10)(step_1_matching_event) as step_1_matching_events, - groupArray(10)(step_2_matching_event) as step_2_matching_events, - groupArray(10)(final_matching_event) as final_matching_events - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 14 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 14 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 14 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 14 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 14 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2, - if(latest_2 < latest_1, NULL, "uuid_2") as "uuid_2", - if(latest_2 < latest_1, NULL, "$session_id_2") as "$session_id_2", - if(latest_2 < latest_1, NULL, "$window_id_2") as "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - last_value("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_1", - last_value("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_1", - last_value("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-05-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-05-07 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 ) - WHERE toDateTime(entrance_period_start) = '2021-05-01 00:00:00' - GROUP BY aggregation_target, - entrance_period_start) - WHERE steps_completed >= 1 - AND steps_completed < 3 - ORDER BY aggregation_target - LIMIT 100 - OFFSET 0 - ' ---- -# name: TestFunnelTrendsPersons.test_funnel_trend_persons_with_drop_off.1 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s1a'] - AND min_first_timestamp >= '2021-04-30 00:00:00' - AND max_last_timestamp <= '2021-05-08 23:59:59' - ' ---- -# name: TestFunnelTrendsPersons.test_funnel_trend_persons_with_drop_off.2 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s1a'] - AND min_first_timestamp >= '2021-04-30 00:00:00' - AND max_last_timestamp <= '2021-05-08 23:59:59' - ' ---- -# name: TestFunnelTrendsPersons.test_funnel_trend_persons_with_no_to_step - ' - - SELECT aggregation_target AS actor_id, - final_matching_events as matching_events - FROM - (SELECT aggregation_target, - toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) AS entrance_period_start, - max(steps) AS steps_completed , - groupArray(10)(step_0_matching_event) as step_0_matching_events, - groupArray(10)(step_1_matching_event) as step_1_matching_events, - groupArray(10)(step_2_matching_event) as step_2_matching_events, - groupArray(10)(final_matching_event) as final_matching_events - FROM - (SELECT *, - if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 14 DAY - AND latest_1 <= latest_2 - AND latest_2 <= latest_0 + INTERVAL 14 DAY, 3, if(latest_0 <= latest_1 - AND latest_1 <= latest_0 + INTERVAL 14 DAY, 2, 1)) AS steps , - if(isNotNull(latest_1) - AND latest_1 <= latest_0 + INTERVAL 14 DAY, dateDiff('second', toDateTime(latest_0), toDateTime(latest_1)), NULL) step_1_conversion_time, - if(isNotNull(latest_2) - AND latest_2 <= latest_1 + INTERVAL 14 DAY, dateDiff('second', toDateTime(latest_1), toDateTime(latest_2)), NULL) step_2_conversion_time, - ("latest_0", - "uuid_0", - "$session_id_0", - "$window_id_0") as step_0_matching_event, - ("latest_1", - "uuid_1", - "$session_id_1", - "$window_id_1") as step_1_matching_event, - ("latest_2", - "uuid_2", - "$session_id_2", - "$window_id_2") as step_2_matching_event, - if(isNull(latest_0),(null, null, null, null),if(isNull(latest_1), step_0_matching_event, if(isNull(latest_2), step_1_matching_event, step_2_matching_event))) as final_matching_event - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - latest_1, - "uuid_1", - "$session_id_1", - "$window_id_1", - step_2, - if(latest_2 < latest_1, NULL, latest_2) as latest_2, - if(latest_2 < latest_1, NULL, "uuid_2") as "uuid_2", - if(latest_2 < latest_1, NULL, "$session_id_2") as "$session_id_2", - if(latest_2 < latest_1, NULL, "$window_id_2") as "$window_id_2" - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - last_value("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_1", - last_value("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_1", - last_value("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-05-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-05-07 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )))) - WHERE step_0 = 1 ) - WHERE toDateTime(entrance_period_start) = '2021-05-01 00:00:00' - GROUP BY aggregation_target, - entrance_period_start) - WHERE steps_completed >= 3 - ORDER BY aggregation_target - LIMIT 100 - OFFSET 0 - ' ---- -# name: TestFunnelTrendsPersons.test_funnel_trend_persons_with_no_to_step.1 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s1c'] - AND min_first_timestamp >= '2021-04-30 00:00:00' - AND max_last_timestamp <= '2021-05-08 23:59:59' - ' ---- -# name: TestFunnelTrendsPersons.test_funnel_trend_persons_with_no_to_step.2 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in ['s1c'] - AND min_first_timestamp >= '2021-04-30 00:00:00' - AND max_last_timestamp <= '2021-05-08 23:59:59' - ' ---- diff --git a/posthog/queries/funnels/test/__snapshots__/test_funnel_unordered.ambr b/posthog/queries/funnels/test/__snapshots__/test_funnel_unordered.ambr deleted file mode 100644 index 357ef55a79897..0000000000000 --- a/posthog/queries/funnels/test/__snapshots__/test_funnel_unordered.ambr +++ /dev/null @@ -1,465 +0,0 @@ -# name: TestFunnelUnorderedStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen - ' - - SELECT groupArray(value) - FROM - (SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS value, - count(*) as count - FROM events e - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - GROUP BY value - ORDER BY count DESC, value DESC - LIMIT 25 - OFFSET 0) - ' ---- -# name: TestFunnelUnorderedStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen.1 - ' - - SELECT groupArray(value) - FROM - (SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS value, - count(*) as count - FROM events e - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - GROUP BY value - ORDER BY count DESC, value DESC - LIMIT 25 - OFFSET 0) - ' ---- -# name: TestFunnelUnorderedStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen.2 - ' - - SELECT countIf(steps = 1) step_1, - countIf(steps = 2) step_2, - avg(step_1_average_conversion_time_inner) step_1_average_conversion_time, - median(step_1_median_conversion_time_inner) step_1_median_conversion_time, - prop - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - prop - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target, - prop) as max_steps, - step_1_conversion_time, - prop - FROM - (SELECT *, - arraySort([latest_0,latest_1]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target, - prop - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1 , - if(has([[''], ['Mac'], ['Chrome'], ['Safari']], prop), prop, ['Other']) as prop - FROM - (SELECT *, - if(notEmpty(arrayFilter(x -> notEmpty(x), prop_vals)), prop_vals, ['']) as prop - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'sign up', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'buy' - AND (has(['xyz'], replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', ''))), 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS prop_basic, - prop_basic as prop, - argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) over (PARTITION by aggregation_target) as prop_vals - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1) ))) - WHERE step_0 = 1 - UNION ALL SELECT *, - arraySort([latest_0,latest_1]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target, - prop - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1 , - if(has([[''], ['Mac'], ['Chrome'], ['Safari']], prop), prop, ['Other']) as prop - FROM - (SELECT *, - if(notEmpty(arrayFilter(x -> notEmpty(x), prop_vals)), prop_vals, ['']) as prop - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'buy' - AND (has(['xyz'], replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', ''))), 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'sign up', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS prop_basic, - prop_basic as prop, - argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) over (PARTITION by aggregation_target) as prop_vals - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1) ))) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps, - prop - HAVING steps = max_steps) - GROUP BY prop - ' ---- -# name: TestFunnelUnorderedStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step - ' - - SELECT groupArray(value) - FROM - (SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS value, - count(*) as count - FROM events e - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - GROUP BY value - ORDER BY count DESC, value DESC - LIMIT 25 - OFFSET 0) - ' ---- -# name: TestFunnelUnorderedStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step.1 - ' - - SELECT groupArray(value) - FROM - (SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS value, - count(*) as count - FROM events e - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - GROUP BY value - ORDER BY count DESC, value DESC - LIMIT 25 - OFFSET 0) - ' ---- -# name: TestFunnelUnorderedStepsBreakdown.test_funnel_breakdown_correct_breakdown_props_are_chosen_for_step.2 - ' - - SELECT countIf(steps = 1) step_1, - countIf(steps = 2) step_2, - avg(step_1_average_conversion_time_inner) step_1_average_conversion_time, - median(step_1_median_conversion_time_inner) step_1_median_conversion_time, - prop - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - prop - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target, - prop) as max_steps, - step_1_conversion_time, - prop - FROM - (SELECT *, - arraySort([latest_0,latest_1]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target, - prop - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1 , - if(has([[''], ['Mac'], ['Chrome'], ['Safari']], prop), prop, ['Other']) as prop - FROM - (SELECT *, - prop - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'sign up', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'buy' - AND (has(['xyz'], replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', ''))), 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS prop_basic, - if(step_0 = 1, prop_basic, []) as prop_0, - if(step_1 = 1, prop_basic, []) as prop_1, - prop_1 as prop, - groupUniqArray(prop) over (PARTITION by aggregation_target) as prop_vals - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1) ) ARRAY - JOIN prop_vals as prop - WHERE prop != [] )) - WHERE step_0 = 1 - UNION ALL SELECT *, - arraySort([latest_0,latest_1]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target, - prop - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1 , - if(has([[''], ['Mac'], ['Chrome'], ['Safari']], prop), prop, ['Other']) as prop - FROM - (SELECT *, - prop - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'buy' - AND (has(['xyz'], replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', ''))), 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'sign up', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '')) AS prop_basic, - if(step_0 = 1, prop_basic, []) as prop_0, - if(step_1 = 1, prop_basic, []) as prop_1, - prop_1 as prop, - groupUniqArray(prop) over (PARTITION by aggregation_target) as prop_vals - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1) ) ARRAY - JOIN prop_vals as prop - WHERE prop != [] )) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps, - prop - HAVING steps = max_steps) - GROUP BY prop - ' ---- -# name: TestFunnelUnorderedStepsBreakdown.test_funnel_step_multiple_breakdown_snapshot - ' - - SELECT groupArray(value) - FROM - (SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', ''), replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', '')) AS value, - count(*) as count - FROM events e - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - GROUP BY value - ORDER BY count DESC, value DESC - LIMIT 25 - OFFSET 0) - ' ---- -# name: TestFunnelUnorderedStepsBreakdown.test_funnel_step_multiple_breakdown_snapshot.1 - ' - - SELECT groupArray(value) - FROM - (SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', ''), replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', '')) AS value, - count(*) as count - FROM events e - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - GROUP BY value - ORDER BY count DESC, value DESC - LIMIT 25 - OFFSET 0) - ' ---- -# name: TestFunnelUnorderedStepsBreakdown.test_funnel_step_multiple_breakdown_snapshot.2 - ' - - SELECT countIf(steps = 1) step_1, - countIf(steps = 2) step_2, - avg(step_1_average_conversion_time_inner) step_1_average_conversion_time, - median(step_1_median_conversion_time_inner) step_1_median_conversion_time, - prop - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - prop - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target, - prop) as max_steps, - step_1_conversion_time, - prop - FROM - (SELECT *, - arraySort([latest_0,latest_1]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target, - prop - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1 , - if(has([['', ''], ['alakazam', ''], ['Safari', 'xyz'], ['Mac', ''], ['Chrome', 'xyz'], ['0', '0'], ['', 'no-mac']], prop), prop, ['Other']) as prop - FROM - (SELECT *, - if(notEmpty(arrayFilter(x -> notEmpty(x), prop_vals)), prop_vals, ['','']) as prop - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'sign up', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'buy', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', ''), replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', '')) AS prop_basic, - prop_basic as prop, - argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) over (PARTITION by aggregation_target) as prop_vals - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1) ))) - WHERE step_0 = 1 - UNION ALL SELECT *, - arraySort([latest_0,latest_1]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - step_1, - min(latest_1) over (PARTITION by aggregation_target, - prop - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1 , - if(has([['', ''], ['alakazam', ''], ['Safari', 'xyz'], ['Mac', ''], ['Chrome', 'xyz'], ['0', '0'], ['', 'no-mac']], prop), prop, ['Other']) as prop - FROM - (SELECT *, - if(notEmpty(arrayFilter(x -> notEmpty(x), prop_vals)), prop_vals, ['','']) as prop - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - pdi.person_id as person_id , - if(event = 'buy', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(event = 'sign up', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - array(replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', ''), replaceRegexpAll(JSONExtractRaw(properties, '$version'), '^"|"$', '')) AS prop_basic, - prop_basic as prop, - argMinIf(prop, timestamp, notEmpty(arrayFilter(x -> notEmpty(x), prop))) over (PARTITION by aggregation_target) as prop_vals - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['buy', 'sign up'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1) ))) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps, - prop - HAVING steps = max_steps) - GROUP BY prop - ' ---- diff --git a/posthog/queries/funnels/test/__snapshots__/test_funnel_unordered_persons.ambr b/posthog/queries/funnels/test/__snapshots__/test_funnel_unordered_persons.ambr deleted file mode 100644 index 640af4ff89917..0000000000000 --- a/posthog/queries/funnels/test/__snapshots__/test_funnel_unordered_persons.ambr +++ /dev/null @@ -1,243 +0,0 @@ -# name: TestFunnelUnorderedStepsPersons.test_unordered_funnel_does_not_return_recordings - ' - - SELECT aggregation_target AS actor_id, - array() as matching_events - FROM - (SELECT aggregation_target, - steps, - avg(step_1_conversion_time) step_1_average_conversion_time_inner, - avg(step_2_conversion_time) step_2_average_conversion_time_inner, - median(step_1_conversion_time) step_1_median_conversion_time_inner, - median(step_2_conversion_time) step_2_median_conversion_time_inner - FROM - (SELECT aggregation_target, - steps, - max(steps) over (PARTITION BY aggregation_target) as max_steps, - step_1_conversion_time, - step_2_conversion_time - FROM - (SELECT *, - arraySort([latest_0,latest_1,latest_2]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0),if(latest_0 < latest_2 AND latest_2 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1,latest_2]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time, - if(isNotNull(conversion_times[3]) - AND conversion_times[3] <= conversion_times[2] + INTERVAL 7 DAY, dateDiff('second', conversion_times[2], conversion_times[3]), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - last_value("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_1", - last_value("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_1", - last_value("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step one', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step two', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step three', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )) - WHERE step_0 = 1 - UNION ALL SELECT *, - arraySort([latest_0,latest_1,latest_2]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0),if(latest_0 < latest_2 AND latest_2 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1,latest_2]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time, - if(isNotNull(conversion_times[3]) - AND conversion_times[3] <= conversion_times[2] + INTERVAL 7 DAY, dateDiff('second', conversion_times[2], conversion_times[3]), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - last_value("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_1", - last_value("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_1", - last_value("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step two', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step three', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step one', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )) - WHERE step_0 = 1 - UNION ALL SELECT *, - arraySort([latest_0,latest_1,latest_2]) as event_times, - arraySum([if(latest_0 < latest_1 AND latest_1 <= latest_0 + INTERVAL 7 DAY, 1, 0),if(latest_0 < latest_2 AND latest_2 <= latest_0 + INTERVAL 7 DAY, 1, 0), 1]) AS steps , - arraySort([latest_0,latest_1,latest_2]) as conversion_times, - if(isNotNull(conversion_times[2]) - AND conversion_times[2] <= conversion_times[1] + INTERVAL 7 DAY, dateDiff('second', conversion_times[1], conversion_times[2]), NULL) step_1_conversion_time, - if(isNotNull(conversion_times[3]) - AND conversion_times[3] <= conversion_times[2] + INTERVAL 7 DAY, dateDiff('second', conversion_times[2], conversion_times[3]), NULL) step_2_conversion_time - FROM - (SELECT aggregation_target, timestamp, step_0, - latest_0, - "uuid_0", - "$session_id_0", - "$window_id_0", - step_1, - min(latest_1) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1, - last_value("uuid_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_1", - last_value("$session_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_1", - last_value("$window_id_1") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_1", - step_2, - min(latest_2) over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_2, - last_value("uuid_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "uuid_2", - last_value("$session_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$session_id_2", - last_value("$window_id_2") over (PARTITION by aggregation_target - ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) "$window_id_2" - FROM - (SELECT e.timestamp as timestamp, - pdi.person_id as aggregation_target, - e.uuid AS uuid, - pdi.person_id as person_id , - if(event = 'step three', 1, 0) as step_0, - if(step_0 = 1, timestamp, null) as latest_0, - if(step_0 = 1, "uuid", null) as "uuid_0", - if(step_0 = 1, "$session_id", null) as "$session_id_0", - if(step_0 = 1, "$window_id", null) as "$window_id_0", - if(event = 'step one', 1, 0) as step_1, - if(step_1 = 1, timestamp, null) as latest_1, - if(step_1 = 1, "uuid", null) as "uuid_1", - if(step_1 = 1, "$session_id", null) as "$session_id_1", - if(step_1 = 1, "$window_id", null) as "$window_id_1", - if(event = 'step two', 1, 0) as step_2, - if(step_2 = 1, timestamp, null) as latest_2, - if(step_2 = 1, "uuid", null) as "uuid_2", - if(step_2 = 1, "$session_id", null) as "$session_id_2", - if(step_2 = 1, "$window_id", null) as "$window_id_2" - FROM events e - INNER JOIN - (SELECT distinct_id, - argMax(person_id, version) as person_id - FROM person_distinct_id2 - WHERE team_id = 2 - GROUP BY distinct_id - HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id - WHERE team_id = 2 - AND event IN ['step one', 'step three', 'step two'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-01-08 23:59:59', 'UTC') - AND (step_0 = 1 - OR step_1 = 1 - OR step_2 = 1) )) - WHERE step_0 = 1 )) - GROUP BY aggregation_target, - steps - HAVING steps = max_steps) - WHERE steps IN [1, 2, 3] - ORDER BY aggregation_target - LIMIT 100 - OFFSET 0 - ' ---- -# name: TestFunnelUnorderedStepsPersons.test_unordered_funnel_does_not_return_recordings.1 - ' - - SELECT DISTINCT session_id - FROM session_replay_events - WHERE team_id = 2 - and session_id in [] - AND min_first_timestamp >= '2020-12-31 00:00:00' - AND max_last_timestamp <= '2021-01-09 23:59:59' - ' ---- diff --git a/posthog/queries/test/__snapshots__/test_trends.ambr b/posthog/queries/test/__snapshots__/test_trends.ambr index 1bdcf6adf0cf0..ee66dc30e5693 100644 --- a/posthog/queries/test/__snapshots__/test_trends.ambr +++ b/posthog/queries/test/__snapshots__/test_trends.ambr @@ -15,11 +15,21 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 2 + AND version = NULL ' --- # name: TestTrends.test_action_filtering_with_cohort.2 ' + + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 2 + ' +--- +# name: TestTrends.test_action_filtering_with_cohort.3 + ' /* celery:posthog.tasks.calculate_cohort.clear_stale_cohort */ SELECT count() FROM cohortpeople @@ -28,7 +38,7 @@ AND version < 2 ' --- -# name: TestTrends.test_action_filtering_with_cohort.3 +# name: TestTrends.test_action_filtering_with_cohort.4 ' SELECT groupArray(day_start) as date, @@ -96,11 +106,21 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 2 + AND version = NULL ' --- # name: TestTrends.test_action_filtering_with_cohort_poe_v2.2 ' + + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 2 + ' +--- +# name: TestTrends.test_action_filtering_with_cohort_poe_v2.3 + ' /* celery:posthog.tasks.calculate_cohort.clear_stale_cohort */ SELECT count() FROM cohortpeople @@ -109,7 +129,7 @@ AND version < 2 ' --- -# name: TestTrends.test_action_filtering_with_cohort_poe_v2.3 +# name: TestTrends.test_action_filtering_with_cohort_poe_v2.4 ' SELECT groupArray(day_start) as date, @@ -1027,12 +1047,22 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestTrends.test_filter_events_by_precalculated_cohort.2 ' + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 0 + ' +--- +# name: TestTrends.test_filter_events_by_precalculated_cohort.3 + ' + SELECT groupArray(day_start) as date, groupArray(count) AS total FROM @@ -1092,12 +1122,22 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestTrends.test_filter_events_by_precalculated_cohort_poe_v2.2 ' + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 0 + ' +--- +# name: TestTrends.test_filter_events_by_precalculated_cohort_poe_v2.3 + ' + SELECT groupArray(day_start) as date, groupArray(count) AS total FROM diff --git a/posthog/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_session_replay.ambr b/posthog/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_session_replay.ambr index 19e9877668818..bf80d7c66717e 100644 --- a/posthog/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_session_replay.ambr +++ b/posthog/session_recordings/queries/test/__snapshots__/test_session_recording_list_from_session_replay.ambr @@ -2906,131 +2906,6 @@ OFFSET 0 ' --- -# name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_for_recordings_by_console_text.5 - ' - - SELECT s.session_id, - any(s.team_id), - any(s.distinct_id), - min(s.min_first_timestamp) as start_time, - max(s.max_last_timestamp) as end_time, - dateDiff('SECOND', start_time, end_time) as duration, - argMinMerge(s.first_url) as first_url, - sum(s.click_count), - sum(s.keypress_count), - sum(s.mouse_activity_count), - sum(s.active_milliseconds)/1000 as active_seconds, - duration-active_seconds as inactive_seconds, - sum(s.console_log_count) as console_log_count, - sum(s.console_warn_count) as console_warn_count, - sum(s.console_error_count) as console_error_count - FROM session_replay_events s - WHERE s.team_id = 2 - AND s.min_first_timestamp >= '2020-12-31 20:00:00' - AND s.min_first_timestamp >= '2021-01-14 00:00:00' - AND s.max_last_timestamp <= '2021-01-21 20:00:00' - AND "session_id" in ['with-warns-session'] - GROUP BY session_id - HAVING 1=1 - AND (console_warn_count > 0 - OR console_error_count > 0) - ORDER BY start_time DESC - LIMIT 51 - OFFSET 0 - ' ---- -# name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_for_recordings_by_console_text.6 - ' - - SELECT distinct log_source_id as session_id - FROM log_entries PREWHERE team_id = 2 - AND timestamp >= '2020-12-31 20:00:00' - AND timestamp <= now() - AND timestamp >= '2021-01-13 12:00:00' - AND timestamp <= '2021-01-22 08:00:00' - WHERE 1=1 - AND level in ['log'] - AND positionCaseInsensitive(message, 'message 5') > 0 - ' ---- -# name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_for_recordings_by_console_text.7 - ' - - SELECT s.session_id, - any(s.team_id), - any(s.distinct_id), - min(s.min_first_timestamp) as start_time, - max(s.max_last_timestamp) as end_time, - dateDiff('SECOND', start_time, end_time) as duration, - argMinMerge(s.first_url) as first_url, - sum(s.click_count), - sum(s.keypress_count), - sum(s.mouse_activity_count), - sum(s.active_milliseconds)/1000 as active_seconds, - duration-active_seconds as inactive_seconds, - sum(s.console_log_count) as console_log_count, - sum(s.console_warn_count) as console_warn_count, - sum(s.console_error_count) as console_error_count - FROM session_replay_events s - WHERE s.team_id = 2 - AND s.min_first_timestamp >= '2020-12-31 20:00:00' - AND s.min_first_timestamp >= '2021-01-14 00:00:00' - AND s.max_last_timestamp <= '2021-01-21 20:00:00' - AND "session_id" in [] - GROUP BY session_id - HAVING 1=1 - AND (console_log_count > 0) - ORDER BY start_time DESC - LIMIT 51 - OFFSET 0 - ' ---- -# name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_for_recordings_by_console_text.8 - ' - - SELECT distinct log_source_id as session_id - FROM log_entries PREWHERE team_id = 2 - AND timestamp >= '2020-12-31 20:00:00' - AND timestamp <= now() - AND timestamp >= '2021-01-13 12:00:00' - AND timestamp <= '2021-01-22 08:00:00' - WHERE 1=1 - AND level in ['log'] - AND positionCaseInsensitive(message, 'message 5') > 0 - ' ---- -# name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_for_recordings_by_console_text.9 - ' - - SELECT s.session_id, - any(s.team_id), - any(s.distinct_id), - min(s.min_first_timestamp) as start_time, - max(s.max_last_timestamp) as end_time, - dateDiff('SECOND', start_time, end_time) as duration, - argMinMerge(s.first_url) as first_url, - sum(s.click_count), - sum(s.keypress_count), - sum(s.mouse_activity_count), - sum(s.active_milliseconds)/1000 as active_seconds, - duration-active_seconds as inactive_seconds, - sum(s.console_log_count) as console_log_count, - sum(s.console_warn_count) as console_warn_count, - sum(s.console_error_count) as console_error_count - FROM session_replay_events s - WHERE s.team_id = 2 - AND s.min_first_timestamp >= '2020-12-31 20:00:00' - AND s.min_first_timestamp >= '2021-01-14 00:00:00' - AND s.max_last_timestamp <= '2021-01-21 20:00:00' - AND "session_id" in [] - GROUP BY session_id - HAVING 1=1 - AND (console_log_count > 0) - ORDER BY start_time DESC - LIMIT 51 - OFFSET 0 - ' ---- # name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_for_recordings_with_console_errors ' @@ -3421,12 +3296,22 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_with_cohort_properties.2 ' + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 0 + ' +--- +# name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_with_cohort_properties.3 + ' + SELECT s.session_id, any(s.team_id), any(s.distinct_id), @@ -3492,12 +3377,22 @@ FROM cohortpeople WHERE team_id = 2 AND cohort_id = 2 - AND version = 0 + AND version = NULL ' --- # name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_with_events_and_cohorts.2 ' + SELECT count(DISTINCT person_id) + FROM cohortpeople + WHERE team_id = 2 + AND cohort_id = 2 + AND version = 0 + ' +--- +# name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_with_events_and_cohorts.3 + ' + SELECT s.session_id, any(s.team_id), any(s.distinct_id), @@ -3582,7 +3477,7 @@ OFFSET 0 ' --- -# name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_with_events_and_cohorts.3 +# name: TestClickhouseSessionRecordingsListFromSessionReplay.test_filter_with_events_and_cohorts.4 ' SELECT s.session_id, diff --git a/posthog/test/__snapshots__/test_feature_flag.ambr b/posthog/test/__snapshots__/test_feature_flag.ambr index a34d2ba545ae0..ae5ba59fd1194 100644 --- a/posthog/test/__snapshots__/test_feature_flag.ambr +++ b/posthog/test/__snapshots__/test_feature_flag.ambr @@ -358,6 +358,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating", @@ -567,6 +568,7 @@ "posthog_cohort"."version", "posthog_cohort"."pending_version", "posthog_cohort"."count", + "posthog_cohort"."post_to_webhook", "posthog_cohort"."created_by_id", "posthog_cohort"."created_at", "posthog_cohort"."is_calculating",