From 7e291061717d22f8925cd422eb84e0f976021a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Oberm=C3=BCller?= Date: Fri, 13 Dec 2024 13:52:09 +0100 Subject: [PATCH 1/2] refactor(dashboards): remove remaining filters from dashboard templates (#26836) --- .../test_clickhouse_experiments.ambr | 657 ++++++++++++--- .../api/test/__snapshots__/test_event.ambr | 58 +- posthog/api/test/dashboards/test_dashboard.py | 2 +- posthog/api/test/test_feature_flag.py | 404 ++++++---- posthog/helpers/dashboard_templates.py | 747 +++++++++--------- .../test/__snapshots__/test_trends.ambr | 454 ++++++++--- posthog/models/dashboard_templates.py | 265 +++++-- .../test/__snapshots__/test_trends.ambr | 496 +++++++++--- 8 files changed, 2124 insertions(+), 959 deletions(-) diff --git a/ee/clickhouse/views/test/__snapshots__/test_clickhouse_experiments.ambr b/ee/clickhouse/views/test/__snapshots__/test_clickhouse_experiments.ambr index cfb948992d66d..983cdf00b5aa0 100644 --- a/ee/clickhouse/views/test/__snapshots__/test_clickhouse_experiments.ambr +++ b/ee/clickhouse/views/test/__snapshots__/test_clickhouse_experiments.ambr @@ -1,17 +1,5 @@ # serializer version: 1 # name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results - ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; - ''' -# --- -# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results.1 ''' /* user_id:0 request:_snapshot_ */ SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '')) AS value, @@ -27,7 +15,7 @@ OFFSET 0 ''' # --- -# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results.2 +# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results.1 ''' /* user_id:0 request:_snapshot_ */ SELECT countIf(steps = 1) step_1, @@ -106,19 +94,86 @@ GROUP BY prop ''' # --- -# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_and_events_out_of_time_range_timezones +# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results.2 ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + /* user_id:0 request:_snapshot_ */ + 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 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, + prop + 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([['test'], ['control'], ['']], 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, + if(notEmpty(pdi.distinct_id), pdi.person_id, e.person_id) as aggregation_target, + if(notEmpty(pdi.distinct_id), pdi.person_id, e.person_id) as person_id, + if(event = '$pageview', 1, 0) as step_0, + if(step_0 = 1, timestamp, null) as latest_0, + if(event = '$pageleave', 1, 0) as step_1, + if(step_1 = 1, timestamp, null) as latest_1, + array(replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '')) 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 + LEFT OUTER JOIN + (SELECT distinct_id, + argMax(person_id, version) as person_id + FROM person_distinct_id2 + WHERE team_id = 99999 + AND distinct_id IN + (SELECT distinct_id + FROM events + WHERE team_id = 99999 + AND event IN ['$pageleave', '$pageview'] + AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-06 00:00:00', 'UTC') ) + GROUP BY distinct_id + HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id + WHERE team_id = 99999 + AND event IN ['$pageleave', '$pageview'] + AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-06 00:00:00', 'UTC') + AND (step_0 = 1 + OR step_1 = 1) ))) + WHERE step_0 = 1 )) + GROUP BY aggregation_target, + steps, + prop + HAVING steps = max(max_steps)) + GROUP BY prop ''' # --- -# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_and_events_out_of_time_range_timezones.1 +# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_and_events_out_of_time_range_timezones ''' /* user_id:0 request:_snapshot_ */ SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '')) AS value, @@ -134,6 +189,85 @@ OFFSET 0 ''' # --- +# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_and_events_out_of_time_range_timezones.1 + ''' + /* user_id:0 request:_snapshot_ */ + 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 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, + prop + 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([['test'], ['control']], 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, + if(notEmpty(pdi.distinct_id), pdi.person_id, e.person_id) as aggregation_target, + if(notEmpty(pdi.distinct_id), pdi.person_id, e.person_id) as person_id, + if(event = '$pageview', 1, 0) as step_0, + if(step_0 = 1, timestamp, null) as latest_0, + if(event = '$pageleave', 1, 0) as step_1, + if(step_1 = 1, timestamp, null) as latest_1, + array(replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '')) 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 + LEFT OUTER JOIN + (SELECT distinct_id, + argMax(person_id, version) as person_id + FROM person_distinct_id2 + WHERE team_id = 99999 + AND distinct_id IN + (SELECT distinct_id + FROM events + WHERE team_id = 99999 + AND event IN ['$pageleave', '$pageview'] + AND toTimeZone(timestamp, 'Europe/Amsterdam') >= toDateTime('2020-01-01 14:20:21', 'Europe/Amsterdam') + AND toTimeZone(timestamp, 'Europe/Amsterdam') <= toDateTime('2020-01-06 10:00:00', 'Europe/Amsterdam') ) + GROUP BY distinct_id + HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id + WHERE team_id = 99999 + AND event IN ['$pageleave', '$pageview'] + AND toTimeZone(timestamp, 'Europe/Amsterdam') >= toDateTime('2020-01-01 14:20:21', 'Europe/Amsterdam') + AND toTimeZone(timestamp, 'Europe/Amsterdam') <= toDateTime('2020-01-06 10:00:00', 'Europe/Amsterdam') + AND (step_0 = 1 + OR step_1 = 1) ))) + WHERE step_0 = 1 )) + GROUP BY aggregation_target, + steps, + prop + HAVING steps = max(max_steps)) + GROUP BY prop + ''' +# --- # name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_and_events_out_of_time_range_timezones.2 ''' /* user_id:0 request:_snapshot_ */ @@ -213,19 +347,181 @@ GROUP BY prop ''' # --- -# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants - ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; - ''' -# --- -# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.1 +# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants + ''' + /* user_id:0 request:_snapshot_ */ + SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '')) AS value, + count(*) as count + FROM events e + WHERE team_id = 99999 + AND event IN ['$pageleave', '$pageview'] + AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-06 00:00:00', 'UTC') + GROUP BY value + ORDER BY count DESC, value DESC + LIMIT 26 + OFFSET 0 + ''' +# --- +# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.1 + ''' + /* user_id:0 request:_snapshot_ */ + 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 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, + prop + 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([[''], ['test_1'], ['test'], ['control'], ['unknown_3'], ['unknown_2'], ['unknown_1'], ['test_2']], 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, + if(notEmpty(pdi.distinct_id), pdi.person_id, e.person_id) as aggregation_target, + if(notEmpty(pdi.distinct_id), pdi.person_id, e.person_id) as person_id, + if(event = '$pageview', 1, 0) as step_0, + if(step_0 = 1, timestamp, null) as latest_0, + if(event = '$pageleave', 1, 0) as step_1, + if(step_1 = 1, timestamp, null) as latest_1, + array(replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '')) 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 + LEFT OUTER JOIN + (SELECT distinct_id, + argMax(person_id, version) as person_id + FROM person_distinct_id2 + WHERE team_id = 99999 + AND distinct_id IN + (SELECT distinct_id + FROM events + WHERE team_id = 99999 + AND event IN ['$pageleave', '$pageview'] + AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-06 00:00:00', 'UTC') ) + GROUP BY distinct_id + HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id + WHERE team_id = 99999 + AND event IN ['$pageleave', '$pageview'] + AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-06 00:00:00', 'UTC') + AND (step_0 = 1 + OR step_1 = 1) ))) + WHERE step_0 = 1 )) + GROUP BY aggregation_target, + steps, + prop + HAVING steps = max(max_steps)) + GROUP BY prop + ''' +# --- +# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.2 + ''' + /* user_id:0 request:_snapshot_ */ + 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 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, + prop + 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([[''], ['test_1'], ['test'], ['control'], ['unknown_3'], ['unknown_2'], ['unknown_1'], ['test_2']], 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, + if(notEmpty(pdi.distinct_id), pdi.person_id, e.person_id) as aggregation_target, + if(notEmpty(pdi.distinct_id), pdi.person_id, e.person_id) as person_id, + if(event = '$pageview', 1, 0) as step_0, + if(step_0 = 1, timestamp, null) as latest_0, + if(event = '$pageleave', 1, 0) as step_1, + if(step_1 = 1, timestamp, null) as latest_1, + array(replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '')) 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 + LEFT OUTER JOIN + (SELECT distinct_id, + argMax(person_id, version) as person_id + FROM person_distinct_id2 + WHERE team_id = 99999 + AND distinct_id IN + (SELECT distinct_id + FROM events + WHERE team_id = 99999 + AND event IN ['$pageleave', '$pageview'] + AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-06 00:00:00', 'UTC') ) + GROUP BY distinct_id + HAVING argMax(is_deleted, version) = 0) AS pdi ON e.distinct_id = pdi.distinct_id + WHERE team_id = 99999 + AND event IN ['$pageleave', '$pageview'] + AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-06 00:00:00', 'UTC') + AND (step_0 = 1 + OR step_1 = 1) ))) + WHERE step_0 = 1 )) + GROUP BY aggregation_target, + steps, + prop + HAVING steps = max(max_steps)) + GROUP BY prop + ''' +# --- +# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_with_hogql_aggregation ''' /* user_id:0 request:_snapshot_ */ SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '')) AS value, @@ -241,7 +537,7 @@ OFFSET 0 ''' # --- -# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.2 +# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_with_hogql_aggregation.1 ''' /* user_id:0 request:_snapshot_ */ SELECT countIf(steps = 1) step_1, @@ -276,13 +572,13 @@ min(latest_1) over (PARTITION by aggregation_target, prop ORDER BY timestamp DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 0 PRECEDING) latest_1 , - if(has([[''], ['test_1'], ['test'], ['control'], ['unknown_3'], ['unknown_2'], ['unknown_1'], ['test_2']], prop), prop, ['Other']) as prop + if(has([['test'], ['control'], ['']], 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, - if(notEmpty(pdi.distinct_id), pdi.person_id, e.person_id) as aggregation_target, + replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(properties, '$account_id'), ''), 'null'), '^"|"$', '') as aggregation_target, if(notEmpty(pdi.distinct_id), pdi.person_id, e.person_id) as person_id, if(event = '$pageview', 1, 0) as step_0, if(step_0 = 1, timestamp, null) as latest_0, @@ -320,34 +616,6 @@ GROUP BY prop ''' # --- -# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_with_hogql_aggregation - ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; - ''' -# --- -# name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_with_hogql_aggregation.1 - ''' - /* user_id:0 request:_snapshot_ */ - SELECT array(replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '')) AS value, - count(*) as count - FROM events e - WHERE team_id = 99999 - AND event IN ['$pageleave', '$pageview'] - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-06 00:00:00', 'UTC') - GROUP BY value - ORDER BY count DESC, value DESC - LIMIT 26 - OFFSET 0 - ''' -# --- # name: ClickhouseTestFunnelExperimentResults.test_experiment_flow_with_event_results_with_hogql_aggregation.2 ''' /* user_id:0 request:_snapshot_ */ @@ -428,18 +696,6 @@ ''' # --- # name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results - ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; - ''' -# --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results.1 ''' /* user_id:0 request:_snapshot_ */ SELECT replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '') AS value, @@ -458,7 +714,7 @@ OFFSET 0 ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results.2 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results.1 ''' /* user_id:0 request:_snapshot_ */ SELECT groupArray(day_start) as date, @@ -506,7 +762,7 @@ ORDER BY breakdown_value ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results.3 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results.2 ''' /* user_id:0 request:_snapshot_ */ SELECT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^"|"$', '') AS value, @@ -526,7 +782,7 @@ OFFSET 0 ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results.4 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results.3 ''' /* user_id:0 request:_snapshot_ */ SELECT groupArray(day_start) as date, @@ -590,19 +846,71 @@ ORDER BY breakdown_value ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results.4 ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + /* user_id:0 request:_snapshot_ */ + SELECT groupArray(day_start) as date, + groupArray(count) AS total, + breakdown_value + FROM + (SELECT SUM(total) as count, + day_start, + breakdown_value + FROM + (SELECT * + FROM + (SELECT toUInt16(0) AS total, + ticks.day_start as day_start, + breakdown_value + FROM + (SELECT toStartOfDay(toDateTime('2020-01-06 00:00:00', 'UTC')) - toIntervalDay(number) as day_start + FROM numbers(6) + UNION ALL SELECT toStartOfDay(toDateTime('2020-01-01 00:00:00', 'UTC')) as day_start) as ticks + CROSS JOIN + (SELECT breakdown_value + FROM + (SELECT ['control', 'test'] as breakdown_value) ARRAY + JOIN breakdown_value) as sec + ORDER BY breakdown_value, + day_start + UNION ALL SELECT count(DISTINCT person_id) as total, + toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) as day_start, + breakdown_value + FROM + (SELECT person_id, + min(timestamp) as timestamp, + breakdown_value + FROM + (SELECT pdi.person_id as person_id, timestamp, transform(ifNull(nullIf(replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^"|"$', ''), ''), '$$_posthog_breakdown_null_$$'), (['control', 'test']), (['control', 'test']), '$$_posthog_breakdown_other_$$') as breakdown_value + FROM events e + INNER JOIN + (SELECT distinct_id, + argMax(person_id, version) as person_id + FROM person_distinct_id2 + WHERE team_id = 99999 + GROUP BY distinct_id + HAVING argMax(is_deleted, version) = 0) as pdi ON events.distinct_id = pdi.distinct_id + WHERE e.team_id = 99999 + AND event = '$feature_flag_called' + AND (((isNull(replaceRegexpAll(JSONExtractRaw(e.properties, 'exclude'), '^"|"$', '')) + OR NOT JSONHas(e.properties, 'exclude'))) + AND ((has(['control', 'test'], replaceRegexpAll(JSONExtractRaw(e.properties, '$feature_flag_response'), '^"|"$', ''))) + AND (has(['a-b-test'], replaceRegexpAll(JSONExtractRaw(e.properties, '$feature_flag'), '^"|"$', ''))))) + AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-06 00:00:00', 'UTC') ) + GROUP BY person_id, + breakdown_value) AS pdi + GROUP BY day_start, + breakdown_value)) + GROUP BY day_start, + breakdown_value + ORDER BY breakdown_value, + day_start) + GROUP BY breakdown_value + ORDER BY breakdown_value ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.1 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants ''' /* user_id:0 request:_snapshot_ */ SELECT replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '') AS value, @@ -619,7 +927,7 @@ OFFSET 0 ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.2 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.1 ''' /* user_id:0 request:_snapshot_ */ SELECT groupArray(day_start) as date, @@ -665,7 +973,7 @@ ORDER BY breakdown_value ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.3 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.2 ''' /* user_id:0 request:_snapshot_ */ SELECT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^"|"$', '') AS value, @@ -683,7 +991,7 @@ OFFSET 0 ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.4 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.3 ''' /* user_id:0 request:_snapshot_ */ SELECT [now()] AS date, @@ -692,19 +1000,16 @@ LIMIT 0 ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_out_of_timerange_timezone +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_for_three_test_variants.4 ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + /* user_id:0 request:_snapshot_ */ + SELECT [now()] AS date, + [0] AS total, + '' AS breakdown_value + LIMIT 0 ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_out_of_timerange_timezone.1 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_out_of_timerange_timezone ''' /* user_id:0 request:_snapshot_ */ SELECT replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '') AS value, @@ -721,7 +1026,7 @@ OFFSET 0 ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_out_of_timerange_timezone.2 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_out_of_timerange_timezone.1 ''' /* user_id:0 request:_snapshot_ */ SELECT groupArray(day_start) as date, @@ -767,7 +1072,7 @@ ORDER BY breakdown_value ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_out_of_timerange_timezone.3 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_out_of_timerange_timezone.2 ''' /* user_id:0 request:_snapshot_ */ SELECT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^"|"$', '') AS value, @@ -785,7 +1090,7 @@ OFFSET 0 ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_out_of_timerange_timezone.4 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_out_of_timerange_timezone.3 ''' /* user_id:0 request:_snapshot_ */ SELECT groupArray(day_start) as date, @@ -847,19 +1152,69 @@ ORDER BY breakdown_value ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_with_hogql_filter +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_out_of_timerange_timezone.4 ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + /* user_id:0 request:_snapshot_ */ + SELECT groupArray(day_start) as date, + groupArray(count) AS total, + breakdown_value + FROM + (SELECT SUM(total) as count, + day_start, + breakdown_value + FROM + (SELECT * + FROM + (SELECT toUInt16(0) AS total, + ticks.day_start as day_start, + breakdown_value + FROM + (SELECT toStartOfDay(toDateTime('2020-01-06 07:00:00', 'US/Pacific')) - toIntervalDay(number) as day_start + FROM numbers(6) + UNION ALL SELECT toStartOfDay(toDateTime('2020-01-01 02:10:00', 'US/Pacific')) as day_start) as ticks + CROSS JOIN + (SELECT breakdown_value + FROM + (SELECT ['control', 'test'] as breakdown_value) ARRAY + JOIN breakdown_value) as sec + ORDER BY breakdown_value, + day_start + UNION ALL SELECT count(DISTINCT person_id) as total, + toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'US/Pacific')) as day_start, + breakdown_value + FROM + (SELECT person_id, + min(timestamp) as timestamp, + breakdown_value + FROM + (SELECT pdi.person_id as person_id, timestamp, transform(ifNull(nullIf(replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^"|"$', ''), ''), '$$_posthog_breakdown_null_$$'), (['control', 'test']), (['control', 'test']), '$$_posthog_breakdown_other_$$') as breakdown_value + FROM events e + INNER JOIN + (SELECT distinct_id, + argMax(person_id, version) as person_id + FROM person_distinct_id2 + WHERE team_id = 99999 + GROUP BY distinct_id + HAVING argMax(is_deleted, version) = 0) as pdi ON events.distinct_id = pdi.distinct_id + WHERE e.team_id = 99999 + AND event = '$feature_flag_called' + AND ((has(['control', 'test'], replaceRegexpAll(JSONExtractRaw(e.properties, '$feature_flag_response'), '^"|"$', ''))) + AND (has(['a-b-test'], replaceRegexpAll(JSONExtractRaw(e.properties, '$feature_flag'), '^"|"$', '')))) + AND toTimeZone(timestamp, 'US/Pacific') >= toDateTime('2020-01-01 02:10:00', 'US/Pacific') + AND toTimeZone(timestamp, 'US/Pacific') <= toDateTime('2020-01-06 07:00:00', 'US/Pacific') ) + GROUP BY person_id, + breakdown_value) AS pdi + GROUP BY day_start, + breakdown_value)) + GROUP BY day_start, + breakdown_value + ORDER BY breakdown_value, + day_start) + GROUP BY breakdown_value + ORDER BY breakdown_value ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_with_hogql_filter.1 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_with_hogql_filter ''' /* user_id:0 request:_snapshot_ */ SELECT replaceRegexpAll(JSONExtractRaw(properties, '$feature/a-b-test'), '^"|"$', '') AS value, @@ -877,7 +1232,7 @@ OFFSET 0 ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_with_hogql_filter.2 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_with_hogql_filter.1 ''' /* user_id:0 request:_snapshot_ */ SELECT groupArray(day_start) as date, @@ -924,7 +1279,7 @@ ORDER BY breakdown_value ''' # --- -# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_with_hogql_filter.3 +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_with_hogql_filter.2 ''' /* user_id:0 request:_snapshot_ */ SELECT replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^"|"$', '') AS value, @@ -942,6 +1297,68 @@ OFFSET 0 ''' # --- +# name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_with_hogql_filter.3 + ''' + /* user_id:0 request:_snapshot_ */ + SELECT groupArray(day_start) as date, + groupArray(count) AS total, + breakdown_value + FROM + (SELECT SUM(total) as count, + day_start, + breakdown_value + FROM + (SELECT * + FROM + (SELECT toUInt16(0) AS total, + ticks.day_start as day_start, + breakdown_value + FROM + (SELECT toStartOfDay(toDateTime('2020-01-06 00:00:00', 'UTC')) - toIntervalDay(number) as day_start + FROM numbers(6) + UNION ALL SELECT toStartOfDay(toDateTime('2020-01-01 00:00:00', 'UTC')) as day_start) as ticks + CROSS JOIN + (SELECT breakdown_value + FROM + (SELECT ['control', 'test'] as breakdown_value) ARRAY + JOIN breakdown_value) as sec + ORDER BY breakdown_value, + day_start + UNION ALL SELECT count(DISTINCT person_id) as total, + toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) as day_start, + breakdown_value + FROM + (SELECT person_id, + min(timestamp) as timestamp, + breakdown_value + FROM + (SELECT pdi.person_id as person_id, timestamp, transform(ifNull(nullIf(replaceRegexpAll(JSONExtractRaw(properties, '$feature_flag_response'), '^"|"$', ''), ''), '$$_posthog_breakdown_null_$$'), (['control', 'test']), (['control', 'test']), '$$_posthog_breakdown_other_$$') as breakdown_value + FROM events e + INNER JOIN + (SELECT distinct_id, + argMax(person_id, version) as person_id + FROM person_distinct_id2 + WHERE team_id = 99999 + GROUP BY distinct_id + HAVING argMax(is_deleted, version) = 0) as pdi ON events.distinct_id = pdi.distinct_id + WHERE e.team_id = 99999 + AND event = '$feature_flag_called' + AND ((has(['control', 'test'], replaceRegexpAll(JSONExtractRaw(e.properties, '$feature_flag_response'), '^"|"$', ''))) + AND (has(['a-b-test'], replaceRegexpAll(JSONExtractRaw(e.properties, '$feature_flag'), '^"|"$', '')))) + AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-06 00:00:00', 'UTC') ) + GROUP BY person_id, + breakdown_value) AS pdi + GROUP BY day_start, + breakdown_value)) + GROUP BY day_start, + breakdown_value + ORDER BY breakdown_value, + day_start) + GROUP BY breakdown_value + ORDER BY breakdown_value + ''' +# --- # name: ClickhouseTestTrendExperimentResults.test_experiment_flow_with_event_results_with_hogql_filter.4 ''' /* user_id:0 request:_snapshot_ */ diff --git a/posthog/api/test/__snapshots__/test_event.ambr b/posthog/api/test/__snapshots__/test_event.ambr index c5e560c8bdba2..6ad9d56dc606c 100644 --- a/posthog/api/test/__snapshots__/test_event.ambr +++ b/posthog/api/test/__snapshots__/test_event.ambr @@ -1,14 +1,14 @@ # serializer version: 1 # name: TestEvents.test_event_property_values ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age + /* user_id:0 request:_snapshot_ */ + SELECT DISTINCT replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + WHERE team_id = 99999 + AND JSONHas(properties, 'random_prop') + AND timestamp >= '2020-01-13 00:00:00' + AND timestamp <= '2020-01-20 23:59:59' + LIMIT 10 ''' # --- # name: TestEvents.test_event_property_values.1 @@ -20,6 +20,8 @@ AND JSONHas(properties, 'random_prop') AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' + AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%qw%' + order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '')) LIMIT 10 ''' # --- @@ -32,7 +34,7 @@ AND JSONHas(properties, 'random_prop') AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' - AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%qw%' + AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%QW%' order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '')) LIMIT 10 ''' @@ -46,7 +48,7 @@ AND JSONHas(properties, 'random_prop') AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' - AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%QW%' + AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%6%' order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '')) LIMIT 10 ''' @@ -60,6 +62,7 @@ AND JSONHas(properties, 'random_prop') AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' + AND (event = 'random event') AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%6%' order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '')) LIMIT 10 @@ -74,7 +77,8 @@ AND JSONHas(properties, 'random_prop') AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' - AND (event = 'random event') + AND (event = 'foo' + OR event = 'random event') AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%6%' order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '')) LIMIT 10 @@ -89,9 +93,8 @@ AND JSONHas(properties, 'random_prop') AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' - AND (event = 'foo' - OR event = 'random event') - AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%6%' + AND (event = '404_i_dont_exist') + AND replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '') ILIKE '%qw%' order by length(replaceRegexpAll(JSONExtractRaw(properties, 'random_prop'), '^"|"$', '')) LIMIT 10 ''' @@ -113,14 +116,14 @@ # --- # name: TestEvents.test_event_property_values_materialized ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age + /* user_id:0 request:_snapshot_ */ + SELECT DISTINCT "mat_random_prop" FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + WHERE team_id = 99999 + AND notEmpty("mat_random_prop") + AND timestamp >= '2020-01-13 00:00:00' + AND timestamp <= '2020-01-20 23:59:59' + LIMIT 10 ''' # --- # name: TestEvents.test_event_property_values_materialized.1 @@ -132,6 +135,8 @@ AND notEmpty("mat_random_prop") AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' + AND "mat_random_prop" ILIKE '%qw%' + order by length("mat_random_prop") LIMIT 10 ''' # --- @@ -144,7 +149,7 @@ AND notEmpty("mat_random_prop") AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' - AND "mat_random_prop" ILIKE '%qw%' + AND "mat_random_prop" ILIKE '%QW%' order by length("mat_random_prop") LIMIT 10 ''' @@ -158,7 +163,7 @@ AND notEmpty("mat_random_prop") AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' - AND "mat_random_prop" ILIKE '%QW%' + AND "mat_random_prop" ILIKE '%6%' order by length("mat_random_prop") LIMIT 10 ''' @@ -172,6 +177,7 @@ AND notEmpty("mat_random_prop") AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' + AND (event = 'random event') AND "mat_random_prop" ILIKE '%6%' order by length("mat_random_prop") LIMIT 10 @@ -186,7 +192,8 @@ AND notEmpty("mat_random_prop") AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' - AND (event = 'random event') + AND (event = 'foo' + OR event = 'random event') AND "mat_random_prop" ILIKE '%6%' order by length("mat_random_prop") LIMIT 10 @@ -201,9 +208,8 @@ AND notEmpty("mat_random_prop") AND timestamp >= '2020-01-13 00:00:00' AND timestamp <= '2020-01-20 23:59:59' - AND (event = 'foo' - OR event = 'random event') - AND "mat_random_prop" ILIKE '%6%' + AND (event = '404_i_dont_exist') + AND "mat_random_prop" ILIKE '%qw%' order by length("mat_random_prop") LIMIT 10 ''' diff --git a/posthog/api/test/dashboards/test_dashboard.py b/posthog/api/test/dashboards/test_dashboard.py index ee802318db349..63f40588999d2 100644 --- a/posthog/api/test/dashboards/test_dashboard.py +++ b/posthog/api/test/dashboards/test_dashboard.py @@ -1313,7 +1313,7 @@ def test_create_from_template_json_can_provide_query_tile(self) -> None: "effective_privilege_level": 37, "effective_restriction_level": 21, "favorited": False, - "filters": {"filter_test_accounts": True}, + "filters": {}, "filters_hash": ANY, "hasMore": None, "id": ANY, diff --git a/posthog/api/test/test_feature_flag.py b/posthog/api/test/test_feature_flag.py index 9fff24d2f0f61..efc67f79e3f40 100644 --- a/posthog/api/test/test_feature_flag.py +++ b/posthog/api/test/test_feature_flag.py @@ -1463,73 +1463,91 @@ def test_create_feature_flag_usage_dashboard(self, mock_capture): self.assertEqual(len(tiles), 2) self.assertEqual(tiles[0].insight.name, "Feature Flag Called Total Volume") self.assertEqual( - tiles[0].insight.filters, + tiles[0].insight.query, { - "events": [ - { - "id": "$feature_flag_called", - "name": "$feature_flag_called", - "type": "events", - } - ], - "display": "ActionsLineGraph", - "insight": "TRENDS", - "interval": "day", - "breakdown": "$feature_flag_response", - "date_from": "-30d", - "properties": { - "type": "AND", - "values": [ - { - "type": "AND", - "values": [ - { - "key": "$feature_flag", - "type": "event", - "value": "alpha-feature", - } - ], - } - ], + "kind": "InsightVizNode", + "source": { + "kind": "TrendsQuery", + "series": [{"kind": "EventsNode", "name": "$feature_flag_called", "event": "$feature_flag_called"}], + "interval": "day", + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + { + "key": "$feature_flag", + "type": "event", + "value": "alpha-feature", + "operator": "exact", + } + ], + } + ], + }, + "trendsFilter": { + "display": "ActionsLineGraph", + "showLegend": False, + "yAxisScaleType": "linear", + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "showPercentStackView": False, + "aggregationAxisFormat": "numeric", + "showAlertThresholdLines": False, + }, + "breakdownFilter": {"breakdown": "$feature_flag_response", "breakdown_type": "event"}, + "filterTestAccounts": False, }, - "breakdown_type": "event", - "filter_test_accounts": False, }, ) self.assertEqual(tiles[1].insight.name, "Feature Flag calls made by unique users per variant") self.assertEqual( - tiles[1].insight.filters, + tiles[1].insight.query, { - "events": [ - { - "id": "$feature_flag_called", - "math": "dau", - "name": "$feature_flag_called", - "type": "events", - } - ], - "display": "ActionsTable", - "insight": "TRENDS", - "interval": "day", - "breakdown": "$feature_flag_response", - "date_from": "-30d", - "properties": { - "type": "AND", - "values": [ + "kind": "InsightVizNode", + "source": { + "kind": "TrendsQuery", + "series": [ { - "type": "AND", - "values": [ - { - "key": "$feature_flag", - "type": "event", - "value": "alpha-feature", - } - ], + "kind": "EventsNode", + "math": "dau", + "name": "$feature_flag_called", + "event": "$feature_flag_called", } ], + "interval": "day", + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + { + "key": "$feature_flag", + "type": "event", + "value": "alpha-feature", + "operator": "exact", + } + ], + } + ], + }, + "trendsFilter": { + "display": "ActionsTable", + "showLegend": False, + "yAxisScaleType": "linear", + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "showPercentStackView": False, + "aggregationAxisFormat": "numeric", + "showAlertThresholdLines": False, + }, + "breakdownFilter": {"breakdown": "$feature_flag_response", "breakdown_type": "event"}, + "filterTestAccounts": False, }, - "breakdown_type": "event", - "filter_test_accounts": False, }, ) @@ -1557,153 +1575,191 @@ def test_create_feature_flag_usage_dashboard(self, mock_capture): self.assertEqual(len(tiles), 4) self.assertEqual(tiles[0].insight.name, "Feature Flag Called Total Volume") self.assertEqual( - tiles[0].insight.filters, + tiles[0].insight.query, { - "events": [ - { - "id": "$feature_flag_called", - "name": "$feature_flag_called", - "type": "events", - } - ], - "display": "ActionsLineGraph", - "insight": "TRENDS", - "interval": "day", - "breakdown": "$feature_flag_response", - "date_from": "-30d", - "properties": { - "type": "AND", - "values": [ - { - "type": "AND", - "values": [ - { - "key": "$feature_flag", - "type": "event", - "value": "alpha-feature", - } - ], - } - ], + "kind": "InsightVizNode", + "source": { + "kind": "TrendsQuery", + "series": [{"kind": "EventsNode", "name": "$feature_flag_called", "event": "$feature_flag_called"}], + "interval": "day", + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + { + "key": "$feature_flag", + "type": "event", + "value": "alpha-feature", + "operator": "exact", + } + ], + } + ], + }, + "trendsFilter": { + "display": "ActionsLineGraph", + "showLegend": False, + "yAxisScaleType": "linear", + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "showPercentStackView": False, + "aggregationAxisFormat": "numeric", + "showAlertThresholdLines": False, + }, + "breakdownFilter": {"breakdown": "$feature_flag_response", "breakdown_type": "event"}, + "filterTestAccounts": False, }, - "breakdown_type": "event", - "filter_test_accounts": False, }, ) self.assertEqual(tiles[1].insight.name, "Feature Flag calls made by unique users per variant") self.assertEqual( - tiles[1].insight.filters, + tiles[1].insight.query, { - "events": [ - { - "id": "$feature_flag_called", - "math": "dau", - "name": "$feature_flag_called", - "type": "events", - } - ], - "display": "ActionsTable", - "insight": "TRENDS", - "interval": "day", - "breakdown": "$feature_flag_response", - "date_from": "-30d", - "properties": { - "type": "AND", - "values": [ + "kind": "InsightVizNode", + "source": { + "kind": "TrendsQuery", + "series": [ { - "type": "AND", - "values": [ - { - "key": "$feature_flag", - "type": "event", - "value": "alpha-feature", - } - ], + "kind": "EventsNode", + "math": "dau", + "name": "$feature_flag_called", + "event": "$feature_flag_called", } ], + "interval": "day", + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + { + "key": "$feature_flag", + "type": "event", + "value": "alpha-feature", + "operator": "exact", + } + ], + } + ], + }, + "trendsFilter": { + "display": "ActionsTable", + "showLegend": False, + "yAxisScaleType": "linear", + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "showPercentStackView": False, + "aggregationAxisFormat": "numeric", + "showAlertThresholdLines": False, + }, + "breakdownFilter": {"breakdown": "$feature_flag_response", "breakdown_type": "event"}, + "filterTestAccounts": False, }, - "breakdown_type": "event", - "filter_test_accounts": False, }, ) # enriched insights self.assertEqual(tiles[2].insight.name, "Feature Interaction Total Volume") self.assertEqual( - tiles[2].insight.filters, + tiles[2].insight.query, { - "events": [ - { - "id": "$feature_interaction", - "name": "Feature Interaction - Total", - "type": "events", - }, - { - "id": "$feature_interaction", - "math": "dau", - "name": "Feature Interaction - Unique users", - "type": "events", - }, - ], - "display": "ActionsLineGraph", - "insight": "TRENDS", - "interval": "day", - "date_from": "-30d", - "properties": { - "type": "AND", - "values": [ + "kind": "InsightVizNode", + "source": { + "kind": "TrendsQuery", + "series": [ + {"kind": "EventsNode", "name": "Feature Interaction - Total", "event": "$feature_interaction"}, { - "type": "AND", - "values": [ - { - "key": "feature_flag", - "type": "event", - "value": "alpha-feature", - } - ], - } + "kind": "EventsNode", + "math": "dau", + "name": "Feature Interaction - Unique users", + "event": "$feature_interaction", + }, ], + "interval": "day", + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + { + "key": "feature_flag", + "type": "event", + "value": "alpha-feature", + "operator": "exact", + } + ], + } + ], + }, + "trendsFilter": { + "display": "ActionsLineGraph", + "showLegend": False, + "yAxisScaleType": "linear", + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "showPercentStackView": False, + "aggregationAxisFormat": "numeric", + "showAlertThresholdLines": False, + }, + "breakdownFilter": {"breakdown_type": "event"}, + "filterTestAccounts": False, }, - "filter_test_accounts": False, }, ) self.assertEqual(tiles[3].insight.name, "Feature Viewed Total Volume") self.assertEqual( - tiles[3].insight.filters, + tiles[3].insight.query, { - "events": [ - { - "id": "$feature_view", - "name": "Feature View - Total", - "type": "events", - }, - { - "id": "$feature_view", - "math": "dau", - "name": "Feature View - Unique users", - "type": "events", - }, - ], - "display": "ActionsLineGraph", - "insight": "TRENDS", - "interval": "day", - "date_from": "-30d", - "properties": { - "type": "AND", - "values": [ + "kind": "InsightVizNode", + "source": { + "kind": "TrendsQuery", + "series": [ + {"kind": "EventsNode", "name": "Feature View - Total", "event": "$feature_view"}, { - "type": "AND", - "values": [ - { - "key": "feature_flag", - "type": "event", - "value": "alpha-feature", - } - ], - } + "kind": "EventsNode", + "math": "dau", + "name": "Feature View - Unique users", + "event": "$feature_view", + }, ], + "interval": "day", + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + { + "key": "feature_flag", + "type": "event", + "value": "alpha-feature", + "operator": "exact", + } + ], + } + ], + }, + "trendsFilter": { + "display": "ActionsLineGraph", + "showLegend": False, + "yAxisScaleType": "linear", + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "showPercentStackView": False, + "aggregationAxisFormat": "numeric", + "showAlertThresholdLines": False, + }, + "breakdownFilter": {"breakdown_type": "event"}, + "filterTestAccounts": False, }, - "filter_test_accounts": False, }, ) diff --git a/posthog/helpers/dashboard_templates.py b/posthog/helpers/dashboard_templates.py index 0e3f8a81f9536..313f8c6722a2a 100644 --- a/posthog/helpers/dashboard_templates.py +++ b/posthog/helpers/dashboard_templates.py @@ -4,22 +4,6 @@ import structlog from posthog.constants import ( - BREAKDOWN, - BREAKDOWN_TYPE, - DATE_FROM, - DISPLAY, - FILTER_TEST_ACCOUNTS, - INSIGHT, - INSIGHT_TRENDS, - INTERVAL, - PROPERTIES, - TREND_FILTER_TYPE_EVENTS, - TRENDS_BAR_VALUE, - TRENDS_BOLD_NUMBER, - TRENDS_LINEAR, - TRENDS_TABLE, - TRENDS_WORLD_MAP, - UNIQUE_USERS, AvailableFeature, ENRICHED_DASHBOARD_INSIGHT_IDENTIFIER, ) @@ -37,7 +21,7 @@ def _create_website_dashboard(dashboard: Dashboard) -> None: - dashboard.filters = {DATE_FROM: "-30d"} + dashboard.filters = {"date_from": "-30d"} if dashboard.team.organization.is_feature_available(AvailableFeature.TAGGING): tag, _ = Tag.objects.get_or_create( name="marketing", @@ -52,19 +36,28 @@ def _create_website_dashboard(dashboard: Dashboard) -> None: dashboard, name="Website Unique Users (Total)", description="Shows the number of unique users that use your app every day.", - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$pageview", - "math": UNIQUE_USERS, - "type": TREND_FILTER_TYPE_EVENTS, - } - ], - INTERVAL: "day", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: TRENDS_BOLD_NUMBER, - "compare": True, + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown_type": "event"}, + "compareFilter": {"compare": True}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "day", + "kind": "TrendsQuery", + "properties": [], + "series": [{"event": "$pageview", "kind": "EventsNode", "math": "dau", "name": "$pageview"}], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "BoldNumber", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", + }, + }, }, layouts={ "sm": {"i": "21", "x": 0, "y": 0, "w": 6, "h": 5, "minW": 3, "minH": 5}, @@ -85,40 +78,43 @@ def _create_website_dashboard(dashboard: Dashboard) -> None: dashboard, name="Organic SEO Unique Users (Total)", description="", - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$pageview", - "math": UNIQUE_USERS, - "type": TREND_FILTER_TYPE_EVENTS, - } - ], - INTERVAL: "day", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: TRENDS_BOLD_NUMBER, - "compare": True, - PROPERTIES: { - "type": "AND", - "values": [ - { - "type": "AND", - "values": [ - { - "key": "$referring_domain", - "type": "event", - "value": "google", - "operator": "icontains", - }, - { - "key": "utm_source", - "type": "event", - "value": "is_not_set", - "operator": "is_not_set", - }, - ], - } - ], + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown_type": "event"}, + "compareFilter": {"compare": True}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "day", + "kind": "TrendsQuery", + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + { + "key": "$referring_domain", + "operator": "icontains", + "type": "event", + "value": "google", + }, + {"key": "utm_source", "operator": "is_not_set", "type": "event", "value": "is_not_set"}, + ], + } + ], + }, + "series": [{"event": "$pageview", "kind": "EventsNode", "math": "dau", "name": "$pageview"}], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "BoldNumber", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", + }, }, }, layouts={ @@ -141,18 +137,27 @@ def _create_website_dashboard(dashboard: Dashboard) -> None: dashboard, name="Website Unique Users (Breakdown)", description="", - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$pageview", - "math": UNIQUE_USERS, - "type": TREND_FILTER_TYPE_EVENTS, - } - ], - INTERVAL: "week", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: "ActionsBar", + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown_type": "event"}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "week", + "kind": "TrendsQuery", + "properties": [], + "series": [{"event": "$pageview", "kind": "EventsNode", "math": "dau", "name": "$pageview"}], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "ActionsBar", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", + }, + }, }, layouts={ "sm": {"i": "23", "x": 0, "y": 5, "w": 6, "h": 5, "minW": 3, "minH": 5}, @@ -173,32 +178,38 @@ def _create_website_dashboard(dashboard: Dashboard) -> None: dashboard, name="Organic SEO Unique Users (Breakdown)", description="", - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$pageview", - "math": UNIQUE_USERS, - "type": TREND_FILTER_TYPE_EVENTS, - PROPERTIES: [ - { - "key": "$referring_domain", - "type": "event", - "value": "google", - "operator": "icontains", - }, - { - "key": "utm_source", - "type": "event", - "value": "is_not_set", - "operator": "is_not_set", - }, - ], - } - ], - INTERVAL: "week", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: "ActionsBar", + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown_type": "event"}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "week", + "kind": "TrendsQuery", + "properties": [], + "series": [ + { + "event": "$pageview", + "kind": "EventsNode", + "math": "dau", + "name": "$pageview", + "properties": [ + {"key": "$referring_domain", "operator": "icontains", "type": "event", "value": "google"}, + {"key": "utm_source", "operator": "is_not_set", "type": "event", "value": "is_not_set"}, + ], + } + ], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "ActionsBar", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", + }, + }, }, layouts={ "sm": {"i": "24", "x": 6, "y": 5, "w": 6, "h": 5, "minW": 3, "minH": 5}, @@ -213,30 +224,31 @@ def _create_website_dashboard(dashboard: Dashboard) -> None: dashboard, name="Sessions Per User", description="", - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$pageview", - "math": UNIQUE_USERS, - "name": "$pageview", - "type": TREND_FILTER_TYPE_EVENTS, - "order": 0, - PROPERTIES: [], - }, - { - "id": "$pageview", - "math": "unique_session", - "name": "$pageview", - "type": TREND_FILTER_TYPE_EVENTS, - "order": 1, - PROPERTIES: [], + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown_type": "event"}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "week", + "kind": "TrendsQuery", + "properties": [], + "series": [ + {"event": "$pageview", "kind": "EventsNode", "math": "dau", "name": "$pageview"}, + {"event": "$pageview", "kind": "EventsNode", "math": "unique_session", "name": "$pageview"}, + ], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "ActionsLineGraph", + "formula": "B/A", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", }, - ], - INTERVAL: "week", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: "ActionsLineGraph", - "formula": "B/A", + }, }, layouts={ "sm": {"i": "25", "x": 0, "y": 10, "w": 6, "h": 5, "minW": 3, "minH": 5}, @@ -257,30 +269,31 @@ def _create_website_dashboard(dashboard: Dashboard) -> None: dashboard, name="Pages Per User", description="", - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$pageview", - "math": "total", - "name": "$pageview", - "type": TREND_FILTER_TYPE_EVENTS, - "order": 0, - PROPERTIES: [], - }, - { - "id": "$pageview", - "math": UNIQUE_USERS, - "name": "$pageview", - "type": TREND_FILTER_TYPE_EVENTS, - "order": 1, - PROPERTIES: [], + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown_type": "event"}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "week", + "kind": "TrendsQuery", + "properties": [], + "series": [ + {"event": "$pageview", "kind": "EventsNode", "math": "total", "name": "$pageview"}, + {"event": "$pageview", "kind": "EventsNode", "math": "dau", "name": "$pageview"}, + ], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "ActionsLineGraph", + "formula": "A/B", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", }, - ], - INTERVAL: "week", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: "ActionsLineGraph", - "formula": "A/B", + }, }, layouts={ "sm": {"i": "26", "x": 6, "y": 10, "w": 6, "h": 5, "minW": 3, "minH": 5}, @@ -303,37 +316,36 @@ def _create_website_dashboard(dashboard: Dashboard) -> None: dashboard, name="Top Website Pages (Overall)", description="", - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$pageview", - "math": "unique_session", - "name": "$pageview", - "type": TREND_FILTER_TYPE_EVENTS, - "order": 0, - } - ], - INTERVAL: "day", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: TRENDS_BAR_VALUE, - BREAKDOWN: "$current_url", - BREAKDOWN_TYPE: "event", - PROPERTIES: { - "type": "AND", - "values": [ - { - "type": "AND", - "values": [ - { - "key": "$current_url", - "type": "event", - "value": "?", - "operator": "not_icontains", - } - ], - } - ], + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown": "$current_url", "breakdown_type": "event"}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "day", + "kind": "TrendsQuery", + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + {"key": "$current_url", "operator": "not_icontains", "type": "event", "value": "?"} + ], + } + ], + }, + "series": [{"event": "$pageview", "kind": "EventsNode", "math": "unique_session", "name": "$pageview"}], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "ActionsBarValue", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", + }, }, }, layouts={ @@ -355,43 +367,42 @@ def _create_website_dashboard(dashboard: Dashboard) -> None: dashboard, name="Top Website Pages (via Google)", description="", - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$pageview", - "math": "unique_session", - "name": "$pageview", - "type": TREND_FILTER_TYPE_EVENTS, - "order": 0, - } - ], - INTERVAL: "day", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: TRENDS_BAR_VALUE, - BREAKDOWN: "$current_url", - BREAKDOWN_TYPE: "event", - PROPERTIES: { - "type": "AND", - "values": [ - { - "type": "AND", - "values": [ - { - "key": "$current_url", - "type": "event", - "value": "?", - "operator": "not_icontains", - }, - { - "key": "$referring_domain", - "type": "event", - "value": "google", - "operator": "icontains", - }, - ], - } - ], + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown": "$current_url", "breakdown_type": "event"}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "day", + "kind": "TrendsQuery", + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + {"key": "$current_url", "operator": "not_icontains", "type": "event", "value": "?"}, + { + "key": "$referring_domain", + "operator": "icontains", + "type": "event", + "value": "google", + }, + ], + } + ], + }, + "series": [{"event": "$pageview", "kind": "EventsNode", "math": "unique_session", "name": "$pageview"}], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "ActionsBarValue", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", + }, }, }, layouts={ @@ -407,22 +418,27 @@ def _create_website_dashboard(dashboard: Dashboard) -> None: dashboard, name="Website Users by Location", description="", - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$pageview", - "math": UNIQUE_USERS, - "name": "$pageview", - "type": TREND_FILTER_TYPE_EVENTS, - "order": 0, - } - ], - INTERVAL: "day", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: TRENDS_WORLD_MAP, - BREAKDOWN: "$geoip_country_code", - BREAKDOWN_TYPE: "person", + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown": "$geoip_country_code", "breakdown_type": "person"}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "day", + "kind": "TrendsQuery", + "properties": [], + "series": [{"event": "$pageview", "kind": "EventsNode", "math": "dau", "name": "$pageview"}], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "WorldMap", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", + }, + }, }, layouts={ "sm": {"i": "29", "x": 0, "y": 23, "w": 12, "h": 8, "minW": 3, "minH": 5}, @@ -471,11 +487,9 @@ def create_from_template(dashboard: Dashboard, template: DashboardTemplate) -> N for template_tile in template.tiles: if template_tile["type"] == "INSIGHT": query = template_tile.get("query", None) - filters = template_tile.get("filters") if not query else {} _create_tile_for_insight( dashboard, name=template_tile.get("name"), - filters=filters, query=query, description=template_tile.get("description"), color=template_tile.get("color"), @@ -508,18 +522,15 @@ def _create_tile_for_text(dashboard: Dashboard, body: str, layouts: dict, color: def _create_tile_for_insight( dashboard: Dashboard, name: str, - filters: dict, description: str, layouts: dict, color: Optional[str], query: Optional[dict] = None, ) -> None: - filter_test_accounts = filters.get("filter_test_accounts", True) insight = Insight.objects.create( team=dashboard.team, name=name, description=description, - filters={**filters, "filter_test_accounts": filter_test_accounts}, is_sample=True, query=query, ) @@ -547,7 +558,7 @@ def create_dashboard_from_template(template_key: str, dashboard: Dashboard) -> N def create_feature_flag_dashboard(feature_flag, dashboard: Dashboard) -> None: - dashboard.filters = {DATE_FROM: "-30d"} + dashboard.filters = {"date_from": "-30d"} if dashboard.team.organization.is_feature_available(AvailableFeature.TAGGING): tag, _ = Tag.objects.get_or_create( name="feature flags", @@ -562,36 +573,42 @@ def create_feature_flag_dashboard(feature_flag, dashboard: Dashboard) -> None: dashboard, name="Feature Flag Called Total Volume", description="Shows the number of total calls made on feature flag with key: " + feature_flag.key, - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$feature_flag_called", - "name": "$feature_flag_called", - "type": TREND_FILTER_TYPE_EVENTS, - } - ], - INTERVAL: "day", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: TRENDS_LINEAR, - PROPERTIES: { - "type": "AND", - "values": [ - { - "type": "AND", - "values": [ - { - "key": "$feature_flag", - "type": "event", - "value": feature_flag.key, - }, - ], - } - ], + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown": "$feature_flag_response", "breakdown_type": "event"}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "day", + "kind": "TrendsQuery", + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + { + "key": "$feature_flag", + "operator": "exact", + "type": "event", + "value": feature_flag.key, + } + ], + } + ], + }, + "series": [{"event": "$feature_flag_called", "kind": "EventsNode", "name": "$feature_flag_called"}], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "ActionsLineGraph", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", + }, }, - BREAKDOWN: "$feature_flag_response", - BREAKDOWN_TYPE: "event", - FILTER_TEST_ACCOUNTS: False, }, layouts={ "sm": {"i": "21", "x": 0, "y": 0, "w": 6, "h": 5, "minW": 3, "minH": 5}, @@ -613,37 +630,49 @@ def create_feature_flag_dashboard(feature_flag, dashboard: Dashboard) -> None: name="Feature Flag calls made by unique users per variant", description="Shows the number of unique user calls made on feature flag per variant with key: " + feature_flag.key, - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$feature_flag_called", - "name": "$feature_flag_called", - "math": UNIQUE_USERS, - "type": TREND_FILTER_TYPE_EVENTS, - } - ], - INTERVAL: "day", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: TRENDS_TABLE, - PROPERTIES: { - "type": "AND", - "values": [ + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown": "$feature_flag_response", "breakdown_type": "event"}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "day", + "kind": "TrendsQuery", + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + { + "key": "$feature_flag", + "operator": "exact", + "type": "event", + "value": feature_flag.key, + } + ], + } + ], + }, + "series": [ { - "type": "AND", - "values": [ - { - "key": "$feature_flag", - "type": "event", - "value": feature_flag.key, - }, - ], + "event": "$feature_flag_called", + "kind": "EventsNode", + "math": "dau", + "name": "$feature_flag_called", } ], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "ActionsTable", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", + }, }, - BREAKDOWN: "$feature_flag_response", - BREAKDOWN_TYPE: "event", - FILTER_TEST_ACCOUNTS: False, }, layouts={ "sm": {"i": "22", "x": 6, "y": 0, "w": 6, "h": 5, "minW": 3, "minH": 5}, @@ -667,40 +696,45 @@ def add_enriched_insights_to_feature_flag_dashboard(feature_flag, dashboard: Das dashboard, name=f"{ENRICHED_DASHBOARD_INSIGHT_IDENTIFIER} Total Volume", description="Shows the total number of times this feature was viewed and interacted with", - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$feature_view", - "name": "Feature View - Total", - "type": TREND_FILTER_TYPE_EVENTS, - }, - { - "id": "$feature_view", - "name": "Feature View - Unique users", - "type": TREND_FILTER_TYPE_EVENTS, - "math": UNIQUE_USERS, + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown_type": "event"}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "day", + "kind": "TrendsQuery", + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + {"key": "feature_flag", "operator": "exact", "type": "event", "value": feature_flag.key} + ], + } + ], }, - ], - INTERVAL: "day", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: TRENDS_LINEAR, - PROPERTIES: { - "type": "AND", - "values": [ + "series": [ + {"event": "$feature_view", "kind": "EventsNode", "name": "Feature View - Total"}, { - "type": "AND", - "values": [ - { - "key": "feature_flag", - "type": "event", - "value": feature_flag.key, - }, - ], - } + "event": "$feature_view", + "kind": "EventsNode", + "math": "dau", + "name": "Feature View - Unique users", + }, ], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "ActionsLineGraph", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", + }, }, - FILTER_TEST_ACCOUNTS: False, }, layouts={}, color=None, @@ -710,40 +744,45 @@ def add_enriched_insights_to_feature_flag_dashboard(feature_flag, dashboard: Das dashboard, name="Feature Interaction Total Volume", description="Shows the total number of times this feature was viewed and interacted with", - filters={ - TREND_FILTER_TYPE_EVENTS: [ - { - "id": "$feature_interaction", - "name": "Feature Interaction - Total", - "type": TREND_FILTER_TYPE_EVENTS, - }, - { - "id": "$feature_interaction", - "name": "Feature Interaction - Unique users", - "type": TREND_FILTER_TYPE_EVENTS, - "math": UNIQUE_USERS, + query={ + "kind": "InsightVizNode", + "source": { + "breakdownFilter": {"breakdown_type": "event"}, + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "filterTestAccounts": False, + "interval": "day", + "kind": "TrendsQuery", + "properties": { + "type": "AND", + "values": [ + { + "type": "AND", + "values": [ + {"key": "feature_flag", "operator": "exact", "type": "event", "value": feature_flag.key} + ], + } + ], }, - ], - INTERVAL: "day", - INSIGHT: INSIGHT_TRENDS, - DATE_FROM: "-30d", - DISPLAY: TRENDS_LINEAR, - PROPERTIES: { - "type": "AND", - "values": [ + "series": [ + {"event": "$feature_interaction", "kind": "EventsNode", "name": "Feature Interaction - Total"}, { - "type": "AND", - "values": [ - { - "key": "feature_flag", - "type": "event", - "value": feature_flag.key, - }, - ], - } + "event": "$feature_interaction", + "kind": "EventsNode", + "math": "dau", + "name": "Feature Interaction - Unique users", + }, ], + "trendsFilter": { + "aggregationAxisFormat": "numeric", + "display": "ActionsLineGraph", + "showAlertThresholdLines": False, + "showLegend": False, + "showPercentStackView": False, + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "yAxisScaleType": "linear", + }, }, - FILTER_TEST_ACCOUNTS: False, }, layouts={}, color=None, diff --git a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambr b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambr index 4e75a4122b9bf..729923069bad6 100644 --- a/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambr +++ b/posthog/hogql_queries/insights/trends/test/__snapshots__/test_trends.ambr @@ -847,14 +847,49 @@ # --- # name: TestTrends.test_dau_with_breakdown_filtering_with_sampling ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + SELECT groupArray(1)(date)[1] AS date, + arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total, + if(ifNull(ifNull(greaterOrEquals(row_number, 25), 0), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value + FROM + (SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, + arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) + and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total, + breakdown_value AS breakdown_value, + rowNumberInAllBlocks() AS row_number + FROM + (SELECT sum(total) AS count, + day_start AS day_start, + breakdown_value AS breakdown_value + FROM + (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total, + toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start, + ifNull(nullIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value + FROM events AS e SAMPLE 1.0 + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, + person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 99999) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) + GROUP BY day_start, + breakdown_value) + GROUP BY day_start, + breakdown_value + ORDER BY day_start ASC, breakdown_value ASC) + GROUP BY breakdown_value + ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC) + WHERE isNotNull(breakdown_value) + GROUP BY breakdown_value + ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC + LIMIT 50000 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 ''' # --- # name: TestTrends.test_dau_with_breakdown_filtering_with_sampling.1 @@ -1120,7 +1155,7 @@ ''' SELECT groupArray(1)(date)[1] AS date, arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total, - if(ifNull(ifNull(greaterOrEquals(row_number, 25), 0), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value + arrayMap(i -> if(ifNull(ifNull(greaterOrEquals(row_number, 25), 0), 0), '$$_posthog_breakdown_other_$$', i), breakdown_value) AS breakdown_value FROM (SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) @@ -1130,11 +1165,11 @@ FROM (SELECT sum(total) AS count, day_start AS day_start, - breakdown_value AS breakdown_value + [ifNull(toString(breakdown_value_1), '$$_posthog_breakdown_null_$$')] AS breakdown_value FROM (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total, toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start, - ifNull(nullIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value + ifNull(nullIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value_1 FROM events AS e SAMPLE 1.0 LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, @@ -1145,15 +1180,15 @@ HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) GROUP BY day_start, - breakdown_value) + breakdown_value_1) GROUP BY day_start, - breakdown_value + breakdown_value_1 ORDER BY day_start ASC, breakdown_value ASC) GROUP BY breakdown_value - ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC) - WHERE isNotNull(breakdown_value) + ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC) + WHERE arrayExists(x -> isNotNull(x), breakdown_value) GROUP BY breakdown_value - ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC + ORDER BY if(has(breakdown_value, '$$_posthog_breakdown_other_$$'), 2, if(has(breakdown_value, '$$_posthog_breakdown_null_$$'), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC LIMIT 50000 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1, @@ -1931,18 +1966,6 @@ # --- # name: TestTrends.test_person_filtering_in_cohort_in_action ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; - ''' -# --- -# name: TestTrends.test_person_filtering_in_cohort_in_action.1 - ''' SELECT count(DISTINCT person_id) FROM cohortpeople @@ -1951,7 +1974,7 @@ AND version = NULL ''' # --- -# name: TestTrends.test_person_filtering_in_cohort_in_action.2 +# name: TestTrends.test_person_filtering_in_cohort_in_action.1 ''' /* cohort_calculation: */ SELECT count(DISTINCT person_id) @@ -1961,7 +1984,7 @@ AND version = 0 ''' # --- -# name: TestTrends.test_person_filtering_in_cohort_in_action.3 +# name: TestTrends.test_person_filtering_in_cohort_in_action.2 ''' SELECT groupArray(1)(date)[1] AS date, arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total, @@ -2011,19 +2034,57 @@ max_bytes_before_external_group_by=0 ''' # --- -# name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2 +# name: TestTrends.test_person_filtering_in_cohort_in_action.3 ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + SELECT groupArray(1)(date)[1] AS date, + arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total, + if(ifNull(ifNull(greaterOrEquals(row_number, 25), 0), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value + FROM + (SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, + arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) + and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total, + breakdown_value AS breakdown_value, + rowNumberInAllBlocks() AS row_number + FROM + (SELECT sum(total) AS count, + day_start AS day_start, + breakdown_value AS breakdown_value + FROM + (SELECT count() AS total, + toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start, + ifNull(nullIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value + FROM events AS e SAMPLE 1 + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, + person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 99999) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), and(equals(e.event, 'sign up'), ifNull(in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), + (SELECT cohortpeople.person_id AS person_id + FROM cohortpeople + WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0)))), 0))) + GROUP BY day_start, + breakdown_value) + GROUP BY day_start, + breakdown_value + ORDER BY day_start ASC, breakdown_value ASC) + GROUP BY breakdown_value + ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC) + WHERE isNotNull(breakdown_value) + GROUP BY breakdown_value + ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC + LIMIT 50000 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 ''' # --- -# name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2.1 +# name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2 ''' SELECT count(DISTINCT person_id) @@ -2033,7 +2094,7 @@ AND version = NULL ''' # --- -# name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2.2 +# name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2.1 ''' /* cohort_calculation: */ SELECT count(DISTINCT person_id) @@ -2043,6 +2104,56 @@ AND version = 0 ''' # --- +# name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2.2 + ''' + SELECT groupArray(1)(date)[1] AS date, + arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total, + if(ifNull(ifNull(greaterOrEquals(row_number, 25), 0), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value + FROM + (SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, + arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) + and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total, + breakdown_value AS breakdown_value, + rowNumberInAllBlocks() AS row_number + FROM + (SELECT sum(total) AS count, + day_start AS day_start, + breakdown_value AS breakdown_value + FROM + (SELECT count() AS total, + toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start, + ifNull(nullIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value + FROM events AS e SAMPLE 1 + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, + person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 99999) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), and(equals(e.event, 'sign up'), ifNull(in(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), + (SELECT cohortpeople.person_id AS person_id + FROM cohortpeople + WHERE and(equals(cohortpeople.team_id, 99999), equals(cohortpeople.cohort_id, 99999), equals(cohortpeople.version, 0)))), 0))) + GROUP BY day_start, + breakdown_value) + GROUP BY day_start, + breakdown_value + ORDER BY day_start ASC, breakdown_value ASC) + GROUP BY breakdown_value + ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC) + WHERE isNotNull(breakdown_value) + GROUP BY breakdown_value + ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC + LIMIT 50000 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 + ''' +# --- # name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2.3 ''' SELECT groupArray(1)(date)[1] AS date, @@ -3799,14 +3910,28 @@ # --- # name: TestTrends.test_trends_any_event_total_count ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, + arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) + and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total + FROM + (SELECT sum(total) AS count, + day_start AS day_start + FROM + (SELECT count() AS total, + toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start + FROM events AS e SAMPLE 1 + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC')))) + GROUP BY day_start) + GROUP BY day_start + ORDER BY day_start ASC) + ORDER BY arraySum(total) DESC + LIMIT 50000 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 ''' # --- # name: TestTrends.test_trends_any_event_total_count.1 @@ -3821,7 +3946,7 @@ (SELECT count() AS total, toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start FROM events AS e SAMPLE 1 - WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC')))) + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) GROUP BY day_start) GROUP BY day_start ORDER BY day_start ASC) @@ -3863,14 +3988,55 @@ # --- # name: TestTrends.test_trends_breakdown_cumulative ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + SELECT groupArray(1)(date)[1] AS date, + arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total, + if(ifNull(ifNull(greaterOrEquals(row_number, 25), 0), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value + FROM + (SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, + arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) + and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total, + breakdown_value AS breakdown_value, + rowNumberInAllBlocks() AS row_number + FROM + (SELECT day_start AS day_start, + sum(count) OVER (PARTITION BY breakdown_value + ORDER BY day_start ASC) AS count, + breakdown_value AS breakdown_value + FROM + (SELECT sum(total) AS count, + day_start AS day_start, + breakdown_value AS breakdown_value + FROM + (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total, + min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start, + ifNull(nullIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value + FROM events AS e SAMPLE 1 + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, + person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 99999) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) + GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), + breakdown_value) + GROUP BY day_start, + breakdown_value + ORDER BY day_start ASC, breakdown_value ASC) + ORDER BY day_start ASC) + GROUP BY breakdown_value + ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC) + WHERE isNotNull(breakdown_value) + GROUP BY breakdown_value + ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC + LIMIT 50000 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 ''' # --- # name: TestTrends.test_trends_breakdown_cumulative.1 @@ -3928,14 +4094,55 @@ # --- # name: TestTrends.test_trends_breakdown_cumulative_poe_v2 ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + SELECT groupArray(1)(date)[1] AS date, + arrayFold((acc, x) -> arrayMap(i -> plus(acc[i], x[i]), range(1, plus(length(date), 1))), groupArray(ifNull(total, 0)), arrayWithConstant(length(date), reinterpretAsFloat64(0))) AS total, + if(ifNull(ifNull(greaterOrEquals(row_number, 25), 0), 0), '$$_posthog_breakdown_other_$$', breakdown_value) AS breakdown_value + FROM + (SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, + arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) + and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total, + breakdown_value AS breakdown_value, + rowNumberInAllBlocks() AS row_number + FROM + (SELECT day_start AS day_start, + sum(count) OVER (PARTITION BY breakdown_value + ORDER BY day_start ASC) AS count, + breakdown_value AS breakdown_value + FROM + (SELECT sum(total) AS count, + day_start AS day_start, + breakdown_value AS breakdown_value + FROM + (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total, + min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start, + ifNull(nullIf(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), ''), '$$_posthog_breakdown_null_$$') AS breakdown_value + FROM events AS e SAMPLE 1 + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, + person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 99999) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) + GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), + breakdown_value) + GROUP BY day_start, + breakdown_value + ORDER BY day_start ASC, breakdown_value ASC) + ORDER BY day_start ASC) + GROUP BY breakdown_value + ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC) + WHERE isNotNull(breakdown_value) + GROUP BY breakdown_value + ORDER BY if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_other_$$'), 0), 2, if(ifNull(equals(breakdown_value, '$$_posthog_breakdown_null_$$'), 0), 1, 0)) ASC, arraySum(total) DESC, breakdown_value ASC + LIMIT 50000 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 ''' # --- # name: TestTrends.test_trends_breakdown_cumulative_poe_v2.1 @@ -4232,19 +4439,33 @@ # --- # name: TestTrends.test_trends_compare_day_interval_relative_range ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, + arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) + and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total + FROM + (SELECT sum(total) AS count, + day_start AS day_start + FROM + (SELECT count() AS total, + toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start + FROM events AS e SAMPLE 1 + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) + GROUP BY day_start) + GROUP BY day_start + ORDER BY day_start ASC) + ORDER BY arraySum(total) DESC + LIMIT 50000 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 ''' # --- # name: TestTrends.test_trends_compare_day_interval_relative_range.1 ''' - SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, + SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-21 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-21 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 23:59:59', 6, 'UTC'))))), 1))) AS date, arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total FROM @@ -4254,7 +4475,7 @@ (SELECT count() AS total, toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start FROM events AS e SAMPLE 1 - WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-21 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) GROUP BY day_start) GROUP BY day_start ORDER BY day_start ASC) @@ -4270,7 +4491,7 @@ # --- # name: TestTrends.test_trends_compare_day_interval_relative_range.2 ''' - SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-21 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-21 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 23:59:59', 6, 'UTC'))))), 1))) AS date, + SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total FROM @@ -4280,7 +4501,7 @@ (SELECT count() AS total, toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start FROM events AS e SAMPLE 1 - WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-21 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) GROUP BY day_start) GROUP BY day_start ORDER BY day_start ASC) @@ -4562,14 +4783,33 @@ # --- # name: TestTrends.test_trends_per_day_cumulative ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, + arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) + and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total + FROM + (SELECT day_start AS day_start, + sum(count) OVER ( + ORDER BY day_start ASC) AS count + FROM + (SELECT sum(total) AS count, + day_start AS day_start + FROM + (SELECT count() AS total, + toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_start + FROM events AS e SAMPLE 1 + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) + GROUP BY day_start) + GROUP BY day_start + ORDER BY day_start ASC) + ORDER BY day_start ASC) + ORDER BY arraySum(total) DESC + LIMIT 50000 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 ''' # --- # name: TestTrends.test_trends_per_day_cumulative.1 @@ -4605,14 +4845,40 @@ # --- # name: TestTrends.test_trends_per_day_dau_cumulative ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))))), 1))) AS date, + arrayFill(x -> ifNull(greater(x, 0), 0), arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x) + and isNull(_match_date)), _days_for_count), _index), 1))), date)) AS total + FROM + (SELECT day_start AS day_start, + sum(count) OVER ( + ORDER BY day_start ASC) AS count + FROM + (SELECT sum(total) AS count, + day_start AS day_start + FROM + (SELECT count(DISTINCT if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) AS total, + min(toStartOfDay(toTimeZone(e.timestamp, 'UTC'))) AS day_start + FROM events AS e SAMPLE 1 + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, + person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 99999) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id) + WHERE and(equals(e.team_id, 99999), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 00:00:00', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), equals(e.event, 'sign up')) + GROUP BY if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id)) + GROUP BY day_start + ORDER BY day_start ASC) + ORDER BY day_start ASC) + ORDER BY arraySum(total) DESC + LIMIT 50000 SETTINGS readonly=2, + max_execution_time=60, + allow_experimental_object_type=1, + format_csv_allow_double_quotes=0, + max_ast_elements=4000000, + max_expanded_ast_elements=4000000, + max_bytes_before_external_group_by=0 ''' # --- # name: TestTrends.test_trends_per_day_dau_cumulative.1 diff --git a/posthog/models/dashboard_templates.py b/posthog/models/dashboard_templates.py index 4826be8c9acfa..e8fb368a492ca 100644 --- a/posthog/models/dashboard_templates.py +++ b/posthog/models/dashboard_templates.py @@ -69,12 +69,29 @@ def original_template() -> "DashboardTemplate": "name": "Daily active users (DAUs)", "type": "INSIGHT", "color": "blue", - "filters": { - "events": [{"id": "$pageview", "math": "dau", "type": "events"}], - "display": "ActionsLineGraph", - "insight": "TRENDS", - "interval": "day", - "date_from": "-30d", + "query": { + "kind": "InsightVizNode", + "source": { + "kind": "TrendsQuery", + "series": [ + {"kind": "EventsNode", "math": "dau", "name": "$pageview", "event": "$pageview"} + ], + "interval": "day", + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "properties": [], + "trendsFilter": { + "display": "ActionsLineGraph", + "showLegend": False, + "yAxisScaleType": "linear", + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "showPercentStackView": False, + "aggregationAxisFormat": "numeric", + "showAlertThresholdLines": False, + }, + "breakdownFilter": {"breakdown_type": "event"}, + "filterTestAccounts": False, + }, }, "layouts": { "sm": {"h": 5, "w": 6, "x": 0, "y": 0, "minH": 5, "minW": 3}, @@ -86,18 +103,29 @@ def original_template() -> "DashboardTemplate": "name": "Weekly active users (WAUs)", "type": "INSIGHT", "color": "green", - "filters": { - "events": [ - { - "id": "$pageview", - "math": "dau", - "type": "events", - } - ], - "display": "ActionsLineGraph", - "insight": "TRENDS", - "interval": "week", - "date_from": "-90d", + "query": { + "kind": "InsightVizNode", + "source": { + "kind": "TrendsQuery", + "series": [ + {"kind": "EventsNode", "math": "dau", "name": "$pageview", "event": "$pageview"} + ], + "interval": "week", + "dateRange": {"date_from": "-90d", "explicitDate": False}, + "properties": [], + "trendsFilter": { + "display": "ActionsLineGraph", + "showLegend": False, + "yAxisScaleType": "linear", + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "showPercentStackView": False, + "aggregationAxisFormat": "numeric", + "showAlertThresholdLines": False, + }, + "breakdownFilter": {"breakdown_type": "event"}, + "filterTestAccounts": False, + }, }, "layouts": { "sm": {"h": 5, "w": 6, "x": 6, "y": 0, "minH": 5, "minW": 3}, @@ -109,12 +137,21 @@ def original_template() -> "DashboardTemplate": "name": "Retention", "type": "INSIGHT", "color": "blue", - "filters": { - "period": "Week", - "insight": "RETENTION", - "target_entity": {"id": "$pageview", "type": "events"}, - "retention_type": "retention_first_time", - "returning_entity": {"id": "$pageview", "type": "events"}, + "query": { + "kind": "InsightVizNode", + "source": { + "kind": "RetentionQuery", + "dateRange": {"date_from": "-7d", "explicitDate": False}, + "properties": [], + "retentionFilter": { + "period": "Week", + "targetEntity": {"id": "$pageview", "type": "events"}, + "retentionType": "retention_first_time", + "totalIntervals": 11, + "returningEntity": {"id": "$pageview", "type": "events"}, + }, + "filterTestAccounts": False, + }, }, "layouts": { "sm": {"h": 5, "w": 6, "x": 6, "y": 5, "minH": 5, "minW": 3}, @@ -126,13 +163,17 @@ def original_template() -> "DashboardTemplate": "name": "Growth accounting", "type": "INSIGHT", "color": "purple", - "filters": { - "events": [{"id": "$pageview", "type": "events"}], - "insight": "LIFECYCLE", - "interval": "week", - "shown_as": "Lifecycle", - "date_from": "-30d", - "entity_type": "events", + "query": { + "kind": "InsightVizNode", + "source": { + "kind": "LifecycleQuery", + "series": [{"kind": "EventsNode", "name": "$pageview", "event": "$pageview"}], + "interval": "week", + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "properties": [], + "lifecycleFilter": {"showLegend": False}, + "filterTestAccounts": False, + }, }, "layouts": { "sm": {"h": 5, "w": 6, "x": 0, "y": 5, "minH": 5, "minW": 3}, @@ -144,14 +185,29 @@ def original_template() -> "DashboardTemplate": "name": "Referring domain (last 14 days)", "type": "INSIGHT", "color": "black", - "filters": { - "events": [{"id": "$pageview", "math": "dau", "type": "events"}], - "display": "ActionsBarValue", - "insight": "TRENDS", - "interval": "day", - "breakdown": "$referring_domain", - "date_from": "-14d", - "breakdown_type": "event", + "query": { + "kind": "InsightVizNode", + "source": { + "kind": "TrendsQuery", + "series": [ + {"kind": "EventsNode", "math": "dau", "name": "$pageview", "event": "$pageview"} + ], + "interval": "day", + "dateRange": {"date_from": "-14d", "explicitDate": False}, + "properties": [], + "trendsFilter": { + "display": "ActionsBarValue", + "showLegend": False, + "yAxisScaleType": "linear", + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "showPercentStackView": False, + "aggregationAxisFormat": "numeric", + "showAlertThresholdLines": False, + }, + "breakdownFilter": {"breakdown": "$referring_domain", "breakdown_type": "event"}, + "filterTestAccounts": False, + }, }, "layouts": { "sm": {"h": 5, "w": 6, "x": 0, "y": 10, "minH": 5, "minW": 3}, @@ -163,35 +219,46 @@ def original_template() -> "DashboardTemplate": "name": "Pageview funnel, by browser", "type": "INSIGHT", "color": "green", - "filters": { - "events": [ - { - "id": "$pageview", - "type": "events", - "order": 0, - "custom_name": "First page view", + "query": { + "kind": "InsightVizNode", + "source": { + "kind": "FunnelsQuery", + "series": [ + { + "kind": "EventsNode", + "name": "$pageview", + "event": "$pageview", + "custom_name": "First page view", + }, + { + "kind": "EventsNode", + "name": "$pageview", + "event": "$pageview", + "custom_name": "Second page view", + }, + { + "kind": "EventsNode", + "name": "$pageview", + "event": "$pageview", + "custom_name": "Third page view", + }, + ], + "interval": "day", + "dateRange": {"date_from": "-7d", "explicitDate": False}, + "properties": [], + "funnelsFilter": { + "layout": "horizontal", + "exclusions": [], + "funnelVizType": "steps", + "funnelOrderType": "ordered", + "funnelStepReference": "total", + "funnelWindowInterval": 14, + "breakdownAttributionType": "first_touch", + "funnelWindowIntervalUnit": "day", }, - { - "id": "$pageview", - "type": "events", - "order": 1, - "custom_name": "Second page view", - }, - { - "id": "$pageview", - "type": "events", - "order": 2, - "custom_name": "Third page view", - }, - ], - "layout": "horizontal", - "display": "FunnelViz", - "insight": "FUNNELS", - "interval": "day", - "exclusions": [], - "breakdown_type": "event", - "breakdown": "$browser", - "funnel_viz_type": "steps", + "breakdownFilter": {"breakdown": "$browser", "breakdown_type": "event"}, + "filterTestAccounts": False, + }, }, "layouts": { "sm": {"h": 5, "w": 6, "x": 6, "y": 10, "minH": 5, "minW": 3}, @@ -214,12 +281,29 @@ def feature_flag_template(feature_flag_key: str) -> "DashboardTemplate": "name": "Daily active users (DAUs)", "type": "INSIGHT", "color": "blue", - "filters": { - "events": [{"id": "$pageview", "math": "dau", "type": "events"}], - "display": "ActionsLineGraph", - "insight": "TRENDS", - "interval": "day", - "date_from": "-30d", + "query": { + "kind": "InsightVizNode", + "source": { + "kind": "TrendsQuery", + "series": [ + {"kind": "EventsNode", "math": "dau", "name": "$pageview", "event": "$pageview"} + ], + "interval": "day", + "dateRange": {"date_from": "-30d", "explicitDate": False}, + "properties": [], + "trendsFilter": { + "display": "ActionsLineGraph", + "showLegend": False, + "yAxisScaleType": "linear", + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "showPercentStackView": False, + "aggregationAxisFormat": "numeric", + "showAlertThresholdLines": False, + }, + "breakdownFilter": {"breakdown_type": "event"}, + "filterTestAccounts": False, + }, }, "layouts": { "sm": {"h": 5, "w": 6, "x": 0, "y": 0, "minH": 5, "minW": 3}, @@ -231,18 +315,29 @@ def feature_flag_template(feature_flag_key: str) -> "DashboardTemplate": "name": "Weekly active users (WAUs)", "type": "INSIGHT", "color": "green", - "filters": { - "events": [ - { - "id": "$pageview", - "math": "dau", - "type": "events", - } - ], - "display": "ActionsLineGraph", - "insight": "TRENDS", - "interval": "week", - "date_from": "-90d", + "query": { + "kind": "InsightVizNode", + "source": { + "kind": "TrendsQuery", + "series": [ + {"kind": "EventsNode", "math": "dau", "name": "$pageview", "event": "$pageview"} + ], + "interval": "week", + "dateRange": {"date_from": "-90d", "explicitDate": False}, + "properties": [], + "trendsFilter": { + "display": "ActionsLineGraph", + "showLegend": False, + "yAxisScaleType": "linear", + "showValuesOnSeries": False, + "smoothingIntervals": 1, + "showPercentStackView": False, + "aggregationAxisFormat": "numeric", + "showAlertThresholdLines": False, + }, + "breakdownFilter": {"breakdown_type": "event"}, + "filterTestAccounts": False, + }, }, "layouts": { "sm": {"h": 5, "w": 6, "x": 6, "y": 0, "minH": 5, "minW": 3}, diff --git a/posthog/queries/test/__snapshots__/test_trends.ambr b/posthog/queries/test/__snapshots__/test_trends.ambr index 01ab1c2e0e23e..63cc1b57cf4e8 100644 --- a/posthog/queries/test/__snapshots__/test_trends.ambr +++ b/posthog/queries/test/__snapshots__/test_trends.ambr @@ -859,18 +859,6 @@ # --- # name: TestTrends.test_dau_with_breakdown_filtering_with_sampling ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; - ''' -# --- -# name: TestTrends.test_dau_with_breakdown_filtering_with_sampling.1 - ''' SELECT replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', '') AS value, count(*) as count @@ -885,6 +873,58 @@ OFFSET 0 ''' # --- +# name: TestTrends.test_dau_with_breakdown_filtering_with_sampling.1 + ''' + + SELECT groupArray(day_start) as date, + groupArray(count) AS total, + breakdown_value + FROM + (SELECT SUM(total) as count, + day_start, + breakdown_value + FROM + (SELECT * + FROM + (SELECT toUInt16(0) AS total, + ticks.day_start as day_start, + breakdown_value + FROM + (SELECT toStartOfDay(toDateTime('2020-01-04 23:59:59', 'UTC')) - toIntervalDay(number) as day_start + FROM numbers(8) + UNION ALL SELECT toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')) as day_start) as ticks + CROSS JOIN + (SELECT breakdown_value + FROM + (SELECT ['other_value', '$$_posthog_breakdown_null_$$', 'value'] as breakdown_value) ARRAY + JOIN breakdown_value) as sec + ORDER BY breakdown_value, + day_start + UNION ALL SELECT count(DISTINCT pdi.person_id) as total, + toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) as day_start, + transform(ifNull(nullIf(replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', ''), ''), '$$_posthog_breakdown_null_$$'), (['other_value', '$$_posthog_breakdown_null_$$', 'value']), (['other_value', '$$_posthog_breakdown_null_$$', 'value']), '$$_posthog_breakdown_other_$$') as breakdown_value + FROM events e SAMPLE 1.0 + INNER JOIN + (SELECT distinct_id, + argMax(person_id, version) as person_id + FROM person_distinct_id2 + WHERE team_id = 99999 + GROUP BY distinct_id + HAVING argMax(is_deleted, version) = 0) as pdi ON events.distinct_id = pdi.distinct_id + WHERE e.team_id = 99999 + AND toTimeZone(timestamp, 'UTC') >= toDateTime(toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') + AND ((event = 'sign up')) + GROUP BY day_start, + breakdown_value)) + GROUP BY day_start, + breakdown_value + ORDER BY breakdown_value, + day_start) + GROUP BY breakdown_value + ORDER BY breakdown_value + ''' +# --- # name: TestTrends.test_dau_with_breakdown_filtering_with_sampling.10 ''' /* celery:posthog.tasks.tasks.sync_insight_caching_state */ @@ -1048,6 +1088,22 @@ # name: TestTrends.test_dau_with_breakdown_filtering_with_sampling.2 ''' + SELECT replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', '') AS value, + count(*) as count + FROM events e SAMPLE 1.0 + WHERE team_id = 99999 + AND event = 'sign up' + AND toTimeZone(timestamp, 'UTC') >= toDateTime('2019-12-28 00:00:00', 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') + GROUP BY value + ORDER BY count DESC, value DESC + LIMIT 26 + OFFSET 0 + ''' +# --- +# name: TestTrends.test_dau_with_breakdown_filtering_with_sampling.3 + ''' + SELECT groupArray(day_start) as date, groupArray(count) AS total, breakdown_value @@ -1084,9 +1140,9 @@ GROUP BY distinct_id HAVING argMax(is_deleted, version) = 0) as pdi ON events.distinct_id = pdi.distinct_id WHERE e.team_id = 99999 + AND event = 'sign up' AND toTimeZone(timestamp, 'UTC') >= toDateTime(toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), 'UTC') AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') - AND ((event = 'sign up')) GROUP BY day_start, breakdown_value)) GROUP BY day_start, @@ -1097,22 +1153,6 @@ ORDER BY breakdown_value ''' # --- -# name: TestTrends.test_dau_with_breakdown_filtering_with_sampling.3 - ''' - - SELECT replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', '') AS value, - count(*) as count - FROM events e SAMPLE 1.0 - WHERE team_id = 99999 - AND event = 'sign up' - AND toTimeZone(timestamp, 'UTC') >= toDateTime('2019-12-28 00:00:00', 'UTC') - AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') - GROUP BY value - ORDER BY count DESC, value DESC - LIMIT 26 - OFFSET 0 - ''' -# --- # name: TestTrends.test_dau_with_breakdown_filtering_with_sampling.4 ''' @@ -1718,18 +1758,6 @@ # --- # name: TestTrends.test_person_filtering_in_cohort_in_action ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; - ''' -# --- -# name: TestTrends.test_person_filtering_in_cohort_in_action.1 - ''' SELECT replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', '') AS value, count(*) as count @@ -1763,7 +1791,7 @@ OFFSET 0 ''' # --- -# name: TestTrends.test_person_filtering_in_cohort_in_action.2 +# name: TestTrends.test_person_filtering_in_cohort_in_action.1 ''' SELECT groupArray(day_start) as date, @@ -1827,19 +1855,71 @@ ORDER BY breakdown_value ''' # --- -# name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2 +# name: TestTrends.test_person_filtering_in_cohort_in_action.2 ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + + SELECT groupArray(day_start) as date, + groupArray(count) AS total, + breakdown_value + FROM + (SELECT SUM(total) as count, + day_start, + breakdown_value + FROM + (SELECT * + FROM + (SELECT toUInt16(0) AS total, + ticks.day_start as day_start, + breakdown_value + FROM + (SELECT toStartOfDay(toDateTime('2020-01-04 23:59:59', 'UTC')) - toIntervalDay(number) as day_start + FROM numbers(8) + UNION ALL SELECT toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')) as day_start) as ticks + CROSS JOIN + (SELECT breakdown_value + FROM + (SELECT ['$$_posthog_breakdown_null_$$', 'value', 'other_value'] as breakdown_value) ARRAY + JOIN breakdown_value) as sec + ORDER BY breakdown_value, + day_start + UNION ALL SELECT count(*) as total, + toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) as day_start, + transform(ifNull(nullIf(replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', ''), ''), '$$_posthog_breakdown_null_$$'), (['$$_posthog_breakdown_null_$$', 'value', 'other_value']), (['$$_posthog_breakdown_null_$$', 'value', 'other_value']), '$$_posthog_breakdown_other_$$') as breakdown_value + FROM events e + INNER JOIN + (SELECT distinct_id, + argMax(person_id, version) as person_id + FROM person_distinct_id2 + WHERE team_id = 99999 + GROUP BY distinct_id + HAVING argMax(is_deleted, version) = 0) as pdi ON events.distinct_id = pdi.distinct_id + WHERE e.team_id = 99999 + AND toTimeZone(timestamp, 'UTC') >= toDateTime(toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') + AND ((event = 'sign up' + AND (pdi.person_id IN + (SELECT id + FROM person + WHERE team_id = 99999 + AND id IN + (SELECT id + FROM person + WHERE team_id = 99999 + AND ((has(['some_val'], replaceRegexpAll(JSONExtractRaw(properties, '$some_prop'), '^"|"$', '')))) ) + GROUP BY id + HAVING max(is_deleted) = 0 + AND ((has(['some_val'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$some_prop'), '^"|"$', '')))) SETTINGS optimize_aggregation_in_order = 1)))) + GROUP BY day_start, + breakdown_value)) + GROUP BY day_start, + breakdown_value + ORDER BY breakdown_value, + day_start) + GROUP BY breakdown_value + ORDER BY breakdown_value ''' # --- -# name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2.1 +# name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2 ''' SELECT replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', '') AS value, @@ -1875,6 +1955,72 @@ OFFSET 0 ''' # --- +# name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2.1 + ''' + + SELECT groupArray(day_start) as date, + groupArray(count) AS total, + breakdown_value + FROM + (SELECT SUM(total) as count, + day_start, + breakdown_value + FROM + (SELECT * + FROM + (SELECT toUInt16(0) AS total, + ticks.day_start as day_start, + breakdown_value + FROM + (SELECT toStartOfDay(toDateTime('2020-01-04 23:59:59', 'UTC')) - toIntervalDay(number) as day_start + FROM numbers(8) + UNION ALL SELECT toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')) as day_start) as ticks + CROSS JOIN + (SELECT breakdown_value + FROM + (SELECT ['$$_posthog_breakdown_null_$$', 'value', 'other_value'] as breakdown_value) ARRAY + JOIN breakdown_value) as sec + ORDER BY breakdown_value, + day_start + UNION ALL SELECT count(*) as total, + toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) as day_start, + transform(ifNull(nullIf(replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', ''), ''), '$$_posthog_breakdown_null_$$'), (['$$_posthog_breakdown_null_$$', 'value', 'other_value']), (['$$_posthog_breakdown_null_$$', 'value', 'other_value']), '$$_posthog_breakdown_other_$$') as breakdown_value + FROM events e + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, + person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 99999) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0)) AS overrides ON e.distinct_id = overrides.distinct_id + WHERE e.team_id = 99999 + AND toTimeZone(timestamp, 'UTC') >= toDateTime(toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') + AND notEmpty(e.person_id) + AND ((event = 'sign up' + AND (if(notEmpty(overrides.distinct_id), overrides.person_id, e.person_id) IN + (SELECT id + FROM person + WHERE team_id = 99999 + AND id IN + (SELECT id + FROM person + WHERE team_id = 99999 + AND ((has(['some_val'], replaceRegexpAll(JSONExtractRaw(properties, '$some_prop'), '^"|"$', '')))) ) + GROUP BY id + HAVING max(is_deleted) = 0 + AND ((has(['some_val'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$some_prop'), '^"|"$', '')))) SETTINGS optimize_aggregation_in_order = 1)))) + AND notEmpty(e.person_id) + GROUP BY day_start, + breakdown_value)) + GROUP BY day_start, + breakdown_value + ORDER BY breakdown_value, + day_start) + GROUP BY breakdown_value + ORDER BY breakdown_value + ''' +# --- # name: TestTrends.test_person_filtering_in_cohort_in_action_poe_v2.2 ''' @@ -4232,14 +4378,28 @@ # --- # name: TestTrends.test_trends_any_event_total_count ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + + SELECT groupArray(day_start) as date, + groupArray(count) AS total + FROM + (SELECT SUM(total) AS count, + day_start + FROM + (SELECT toUInt16(0) AS total, + toStartOfDay(toDateTime('2020-01-04 23:59:59', 'UTC')) - toIntervalDay(number) AS day_start + FROM numbers(dateDiff('day', toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), toDateTime('2020-01-04 23:59:59', 'UTC'))) + UNION ALL SELECT toUInt16(0) AS total, + toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')) + UNION ALL SELECT count(*) AS total, + toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) AS date + FROM events e + WHERE team_id = 99999 + AND 1 = 1 + AND toTimeZone(timestamp, 'UTC') >= toDateTime(toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') + GROUP BY date) + GROUP BY day_start + ORDER BY day_start) ''' # --- # name: TestTrends.test_trends_any_event_total_count.1 @@ -4260,7 +4420,7 @@ toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) AS date FROM events e WHERE team_id = 99999 - AND 1 = 1 + AND event = 'sign up' AND toTimeZone(timestamp, 'UTC') >= toDateTime(toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), 'UTC') AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') GROUP BY date) @@ -4296,18 +4456,6 @@ # --- # name: TestTrends.test_trends_breakdown_cumulative ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; - ''' -# --- -# name: TestTrends.test_trends_breakdown_cumulative.1 - ''' SELECT replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', '') AS value, count(*) as count @@ -4322,7 +4470,7 @@ OFFSET 0 ''' # --- -# name: TestTrends.test_trends_breakdown_cumulative.2 +# name: TestTrends.test_trends_breakdown_cumulative.1 ''' SELECT groupArray(day_start) as date, @@ -4382,19 +4530,67 @@ ORDER BY breakdown_value ''' # --- -# name: TestTrends.test_trends_breakdown_cumulative_poe_v2 +# name: TestTrends.test_trends_breakdown_cumulative.2 ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + + SELECT groupArray(day_start) as date, + groupArray(count) AS total, + breakdown_value + FROM + (SELECT SUM(total) as count, + day_start, + breakdown_value + FROM + (SELECT * + FROM + (SELECT toUInt16(0) AS total, + ticks.day_start as day_start, + breakdown_value + FROM + (SELECT toStartOfDay(toDateTime('2020-01-04 23:59:59', 'UTC')) - toIntervalDay(number) as day_start + FROM numbers(8) + UNION ALL SELECT toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')) as day_start) as ticks + CROSS JOIN + (SELECT breakdown_value + FROM + (SELECT ['$$_posthog_breakdown_null_$$', 'value', 'other_value'] as breakdown_value) ARRAY + JOIN breakdown_value) as sec + ORDER BY breakdown_value, + day_start + UNION ALL SELECT count(DISTINCT person_id) as total, + toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) as day_start, + breakdown_value + FROM + (SELECT person_id, + min(timestamp) as timestamp, + breakdown_value + FROM + (SELECT pdi.person_id as person_id, timestamp, transform(ifNull(nullIf(replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', ''), ''), '$$_posthog_breakdown_null_$$'), (['$$_posthog_breakdown_null_$$', 'value', 'other_value']), (['$$_posthog_breakdown_null_$$', 'value', 'other_value']), '$$_posthog_breakdown_other_$$') as breakdown_value + FROM events e + INNER JOIN + (SELECT distinct_id, + argMax(person_id, version) as person_id + FROM person_distinct_id2 + WHERE team_id = 99999 + GROUP BY distinct_id + HAVING argMax(is_deleted, version) = 0) as pdi ON events.distinct_id = pdi.distinct_id + WHERE e.team_id = 99999 + AND event = 'sign up' + AND toTimeZone(timestamp, 'UTC') >= toDateTime(toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') ) + GROUP BY person_id, + breakdown_value) AS pdi + GROUP BY day_start, + breakdown_value)) + GROUP BY day_start, + breakdown_value + ORDER BY breakdown_value, + day_start) + GROUP BY breakdown_value + ORDER BY breakdown_value ''' # --- -# name: TestTrends.test_trends_breakdown_cumulative_poe_v2.1 +# name: TestTrends.test_trends_breakdown_cumulative_poe_v2 ''' SELECT replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', '') AS value, @@ -4418,6 +4614,68 @@ OFFSET 0 ''' # --- +# name: TestTrends.test_trends_breakdown_cumulative_poe_v2.1 + ''' + + SELECT groupArray(day_start) as date, + groupArray(count) AS total, + breakdown_value + FROM + (SELECT SUM(total) as count, + day_start, + breakdown_value + FROM + (SELECT * + FROM + (SELECT toUInt16(0) AS total, + ticks.day_start as day_start, + breakdown_value + FROM + (SELECT toStartOfDay(toDateTime('2020-01-04 23:59:59', 'UTC')) - toIntervalDay(number) as day_start + FROM numbers(8) + UNION ALL SELECT toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')) as day_start) as ticks + CROSS JOIN + (SELECT breakdown_value + FROM + (SELECT ['$$_posthog_breakdown_null_$$', 'value', 'other_value'] as breakdown_value) ARRAY + JOIN breakdown_value) as sec + ORDER BY breakdown_value, + day_start + UNION ALL SELECT count(DISTINCT person_id) as total, + toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) as day_start, + breakdown_value + FROM + (SELECT person_id, + min(timestamp) as timestamp, + breakdown_value + FROM + (SELECT if(notEmpty(overrides.distinct_id), overrides.person_id, e.person_id) as person_id, timestamp, transform(ifNull(nullIf(replaceRegexpAll(JSONExtractRaw(properties, '$some_property'), '^"|"$', ''), ''), '$$_posthog_breakdown_null_$$'), (['$$_posthog_breakdown_null_$$', 'value', 'other_value']), (['$$_posthog_breakdown_null_$$', 'value', 'other_value']), '$$_posthog_breakdown_other_$$') as breakdown_value + FROM events e + LEFT OUTER JOIN + (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, + person_distinct_id_overrides.distinct_id AS distinct_id + FROM person_distinct_id_overrides + WHERE equals(person_distinct_id_overrides.team_id, 99999) + GROUP BY person_distinct_id_overrides.distinct_id + HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0)) AS overrides ON e.distinct_id = overrides.distinct_id + WHERE e.team_id = 99999 + AND event = 'sign up' + AND toTimeZone(timestamp, 'UTC') >= toDateTime(toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') + AND notEmpty(e.person_id) + AND notEmpty(e.person_id) ) + GROUP BY person_id, + breakdown_value) AS pdi + GROUP BY day_start, + breakdown_value)) + GROUP BY day_start, + breakdown_value + ORDER BY breakdown_value, + day_start) + GROUP BY breakdown_value + ORDER BY breakdown_value + ''' +# --- # name: TestTrends.test_trends_breakdown_cumulative_poe_v2.2 ''' @@ -4596,18 +4854,6 @@ # --- # name: TestTrends.test_trends_compare_day_interval_relative_range ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; - ''' -# --- -# name: TestTrends.test_trends_compare_day_interval_relative_range.1 - ''' SELECT groupArray(day_start) as date, groupArray(count) AS total @@ -4632,7 +4878,7 @@ ORDER BY day_start) ''' # --- -# name: TestTrends.test_trends_compare_day_interval_relative_range.2 +# name: TestTrends.test_trends_compare_day_interval_relative_range.1 ''' SELECT groupArray(day_start) as date, @@ -4658,6 +4904,32 @@ ORDER BY day_start) ''' # --- +# name: TestTrends.test_trends_compare_day_interval_relative_range.2 + ''' + + SELECT groupArray(day_start) as date, + groupArray(count) AS total + FROM + (SELECT SUM(total) AS count, + day_start + FROM + (SELECT toUInt16(0) AS total, + toStartOfDay(toDateTime('2020-01-04 23:59:59', 'UTC')) - toIntervalDay(number) AS day_start + FROM numbers(dateDiff('day', toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), toDateTime('2020-01-04 23:59:59', 'UTC'))) + UNION ALL SELECT toUInt16(0) AS total, + toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')) + UNION ALL SELECT count(*) AS total, + toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) AS date + FROM events e + WHERE team_id = 99999 + AND event = 'sign up' + AND toTimeZone(timestamp, 'UTC') >= toDateTime(toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') + GROUP BY date) + GROUP BY day_start + ORDER BY day_start) + ''' +# --- # name: TestTrends.test_trends_compare_day_interval_relative_range.3 ''' @@ -4967,14 +5239,28 @@ # --- # name: TestTrends.test_trends_per_day_cumulative ''' - /* celery:posthog.tasks.tasks.sync_insight_caching_state */ - SELECT team_id, - date_diff('second', max(timestamp), now()) AS age - FROM events - WHERE timestamp > date_sub(DAY, 3, now()) - AND timestamp < now() - GROUP BY team_id - ORDER BY age; + + SELECT groupArray(day_start) as date, + groupArray(count) AS total + FROM + (SELECT SUM(total) AS count, + day_start + FROM + (SELECT toUInt16(0) AS total, + toStartOfDay(toDateTime('2020-01-04 23:59:59', 'UTC')) - toIntervalDay(number) AS day_start + FROM numbers(dateDiff('day', toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), toDateTime('2020-01-04 23:59:59', 'UTC'))) + UNION ALL SELECT toUInt16(0) AS total, + toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')) + UNION ALL SELECT count(*) AS total, + toStartOfDay(toTimeZone(toDateTime(timestamp, 'UTC'), 'UTC')) AS date + FROM events e + WHERE team_id = 99999 + AND event = 'sign up' + AND toTimeZone(timestamp, 'UTC') >= toDateTime(toStartOfDay(toDateTime('2019-12-28 00:00:00', 'UTC')), 'UTC') + AND toTimeZone(timestamp, 'UTC') <= toDateTime('2020-01-04 23:59:59', 'UTC') + GROUP BY date) + GROUP BY day_start + ORDER BY day_start) ''' # --- # name: TestTrends.test_trends_per_day_cumulative.1 From 8f6d8808df2a1145e35d593d84fc954d6960aeed Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Fri, 13 Dec 2024 13:55:35 +0100 Subject: [PATCH 2/2] fix: noticed a flappy test (#26894) --- posthog/rbac/test/test_user_access_control.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/posthog/rbac/test/test_user_access_control.py b/posthog/rbac/test/test_user_access_control.py index d398f246589a5..d17de05dd7b44 100644 --- a/posthog/rbac/test/test_user_access_control.py +++ b/posthog/rbac/test/test_user_access_control.py @@ -281,7 +281,9 @@ def test_filters_project_queryset_based_on_acs_always_allows_org_admin(self): filtered_teams = list( self.user_access_control.filter_queryset_by_access_level(Team.objects.all(), include_all_if_admin=True) ) - assert filtered_teams == [self.team, team2, team3] + assert sorted(filtered_teams, key=lambda team: team.id) == sorted( + [self.team, team2, team3], key=lambda team: team.id + ) def test_organization_access_control(self): # A team isn't always available like for organization level routing