:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(experiments): prune redundant backend tests (#64786)
Andersd3478d57e2b5
diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambr b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambrindex 798e39606f76..b3f42f7d5a9f 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambr+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_breakdown.ambr@@ -142,84 +142,6 @@use_hive_partitioning=0'''# ----# name: TestExperimentBreakdown.test_funnel_metric_with_three_breakdowns- '''- WITH base_events AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.uuid AS uuid,- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,- coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$browser'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$') AS breakdown_value_1,- coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$os'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$') AS breakdown_value_2,- coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$device_type'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$') AS breakdown_value_3,- and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,- if(equals(events.event, 'purchase'), 1, 0) AS step_1- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), or(and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), equals(events.event, 'purchase'))))),- entity_metrics AS- (SELECT base_events.entity_id AS entity_id,- if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(2, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1)]))))))))[1] AS value,- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp,- argMinIf(base_events.breakdown_value_1, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS breakdown_value_1,- argMinIf(base_events.breakdown_value_2, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS breakdown_value_2,- argMinIf(base_events.breakdown_value_3, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS breakdown_value_3- FROM base_events- GROUP BY base_events.entity_id- HAVING greater(countIf(equals(base_events.step_0, 1)), 0))- SELECT entity_metrics.variant AS variant,- entity_metrics.breakdown_value_1 AS breakdown_value_1,- entity_metrics.breakdown_value_2 AS breakdown_value_2,- entity_metrics.breakdown_value_3 AS breakdown_value_3,- count(entity_metrics.entity_id) AS num_users,- countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum,- countIf(ifNull(equals((entity_metrics.value).1, 1), 0)) AS total_sum_of_squares,- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0))) AS step_counts,- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)- and isNull(minus(2, 1))))) AS steps_event_data- FROM entity_metrics- WHERE notEmpty(variant)- GROUP BY entity_metrics.variant,- entity_metrics.breakdown_value_1,- entity_metrics.breakdown_value_2,- entity_metrics.breakdown_value_3- LIMIT 50000 SETTINGS readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestExperimentBreakdown.test_funnel_metric_with_two_breakdowns'''WITH base_events AS@@ -790,96 +712,6 @@use_hive_partitioning=0'''# ----# name: TestExperimentBreakdown.test_mean_metric_with_three_breakdowns- '''- WITH exposures AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- if(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,- min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,- max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,- argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,- argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id,- argMin(coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$browser'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$'), toTimeZone(events.timestamp, 'UTC')) AS breakdown_value_1,- argMin(coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$os'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$'), toTimeZone(events.timestamp, 'UTC')) AS breakdown_value_2,- argMin(coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$device_type'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$'), toTimeZone(events.timestamp, 'UTC')) AS breakdown_value_3- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))- GROUP BY entity_id),- metric_events AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'amount'), ''), 'null'), '^"|"$', ''), 'Float64'), 0) AS value,- coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$browser'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$') AS breakdown_value_1,- coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$os'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$') AS breakdown_value_2,- coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$device_type'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$') AS breakdown_value_3- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'purchase'))),- entity_metrics AS- (SELECT exposures.entity_id AS entity_id,- exposures.variant AS variant,- sum(coalesce(accurateCastOrNull(metric_events.value, 'Float64'), 0)) AS value,- exposures.breakdown_value_1 AS breakdown_value_1,- exposures.breakdown_value_2 AS breakdown_value_2,- exposures.breakdown_value_3 AS breakdown_value_3- FROM exposures- LEFT JOIN metric_events ON and(equals(exposures.entity_id, metric_events.entity_id), greaterOrEquals(toTimeZone(metric_events.timestamp, 'UTC'), toTimeZone(exposures.first_exposure_time, 'UTC')))- GROUP BY exposures.entity_id,- exposures.variant,- exposures.breakdown_value_1,- exposures.breakdown_value_2,- exposures.breakdown_value_3)- SELECT entity_metrics.variant AS variant,- entity_metrics.breakdown_value_1 AS breakdown_value_1,- entity_metrics.breakdown_value_2 AS breakdown_value_2,- entity_metrics.breakdown_value_3 AS breakdown_value_3,- count(entity_metrics.entity_id) AS num_users,- sum(entity_metrics.value) AS total_sum,- sum(power(entity_metrics.value, 2)) AS total_sum_of_squares- FROM entity_metrics- GROUP BY entity_metrics.variant,- entity_metrics.breakdown_value_1,- entity_metrics.breakdown_value_2,- entity_metrics.breakdown_value_3- LIMIT 50000 SETTINGS join_algorithm='grace_hash',- grace_hash_join_initial_buckets=2,- readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestExperimentBreakdown.test_mean_metric_with_two_breakdowns'''WITH exposures AS@@ -1443,123 +1275,6 @@use_hive_partitioning=0'''# ----# name: TestExperimentBreakdown.test_ratio_metric_with_three_breakdowns- '''- WITH exposures AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- if(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,- min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,- max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,- argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,- argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id,- argMin(coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$browser'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$'), toTimeZone(events.timestamp, 'UTC')) AS breakdown_value_1,- argMin(coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$os'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$'), toTimeZone(events.timestamp, 'UTC')) AS breakdown_value_2,- argMin(coalesce(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$device_type'), ''), 'null'), '^"|"$', '')), '$$_posthog_breakdown_null_$$'), toTimeZone(events.timestamp, 'UTC')) AS breakdown_value_3- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))- GROUP BY entity_id),- numerator_events AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'amount'), ''), 'null'), '^"|"$', ''), 'Float64'), 0) AS value- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'purchase'))),- denominator_events AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- coalesce(accurateCastOrNull(1, 'Float64'), 0) AS value- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'view_item'))),- numerator_agg AS- (SELECT exposures.entity_id AS entity_id,- sum(coalesce(accurateCastOrNull(numerator_events.value, 'Float64'), 0)) AS value- FROM numerator_events- JOIN exposures ON equals(exposures.entity_id, numerator_events.entity_id)- WHERE greaterOrEquals(numerator_events.timestamp, toTimeZone(exposures.first_exposure_time, 'UTC'))- GROUP BY exposures.entity_id),- denominator_agg AS- (SELECT exposures.entity_id AS entity_id,- sum(coalesce(accurateCastOrNull(denominator_events.value, 'Float64'), 0)) AS value- FROM denominator_events- JOIN exposures ON equals(exposures.entity_id, denominator_events.entity_id)- WHERE greaterOrEquals(denominator_events.timestamp, toTimeZone(exposures.first_exposure_time, 'UTC'))- GROUP BY exposures.entity_id),- entity_metrics AS- (SELECT exposures.variant AS variant,- exposures.entity_id AS entity_id,- any(coalesce(numerator_agg.value, 0)) AS numerator_value,- any(coalesce(denominator_agg.value, 0)) AS denominator_value,- exposures.breakdown_value_1 AS breakdown_value_1,- exposures.breakdown_value_2 AS breakdown_value_2,- exposures.breakdown_value_3 AS breakdown_value_3- FROM exposures- LEFT JOIN numerator_agg ON equals(exposures.entity_id, numerator_agg.entity_id)- LEFT JOIN denominator_agg ON equals(exposures.entity_id, denominator_agg.entity_id)- GROUP BY exposures.variant,- exposures.entity_id,- exposures.breakdown_value_1,- exposures.breakdown_value_2,- exposures.breakdown_value_3)- SELECT entity_metrics.variant AS variant,- entity_metrics.breakdown_value_1 AS breakdown_value_1,- entity_metrics.breakdown_value_2 AS breakdown_value_2,- entity_metrics.breakdown_value_3 AS breakdown_value_3,- count(entity_metrics.entity_id) AS num_users,- sum(entity_metrics.numerator_value) AS total_sum,- sum(power(entity_metrics.numerator_value, 2)) AS total_sum_of_squares,- sum(entity_metrics.denominator_value) AS denominator_sum,- sum(power(entity_metrics.denominator_value, 2)) AS denominator_sum_squares,- sum(multiply(entity_metrics.numerator_value, entity_metrics.denominator_value)) AS numerator_denominator_sum_product- FROM entity_metrics- GROUP BY entity_metrics.variant,- entity_metrics.breakdown_value_1,- entity_metrics.breakdown_value_2,- entity_metrics.breakdown_value_3- LIMIT 50000 SETTINGS readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestExperimentBreakdown.test_ratio_metric_with_two_breakdowns'''WITH exposures ASdiff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_data_warehouse_metric.ambr b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_data_warehouse_metric.ambrindex d98ca579a943..eca49b6f8003 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_data_warehouse_metric.ambr+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_data_warehouse_metric.ambr@@ -267,63 +267,6 @@use_hive_partitioning=0'''# ----# name: TestExperimentQueryRunner.test_query_runner_data_warehouse_metric_with_both_properties_and_fixed_properties- '''- WITH exposures AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- if(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,- min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,- max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,- argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,- argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id,- argMin(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$user_id'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC')) AS exposure_identifier- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-01-01 00:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-01-31 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))- GROUP BY entity_id),- metric_events AS- (SELECT posthog_test_usage.userid AS entity_id,- posthog_test_usage.ds AS timestamp,- coalesce(accurateCastOrNull(posthog_test_usage.usage, 'Float64'), 0) AS value- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql.experiments.queryrunner/posthog_test_usage/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `ds` Date, `userid` String, `usage` Float64, `plan` String, `region` String') AS posthog_test_usage- WHERE and(greaterOrEquals(posthog_test_usage.ds, assumeNotNull(toDateTime('2023-01-01 00:00:00', 'UTC'))), less(posthog_test_usage.ds, plus(assumeNotNull(toDateTime('2023-01-31 00:00:00', 'UTC')), toIntervalSecond(0))), and(equals(posthog_test_usage.plan, 'premium'), equals(posthog_test_usage.region, 'us-west')))),- entity_metrics AS- (SELECT exposures.entity_id AS entity_id,- exposures.variant AS variant,- sum(coalesce(accurateCastOrNull(metric_events.value, 'Float64'), 0)) AS value- FROM exposures- LEFT JOIN metric_events ON and(equals(toString(exposures.exposure_identifier), toString(metric_events.entity_id)), greaterOrEquals(metric_events.timestamp, toTimeZone(exposures.first_exposure_time, 'UTC')))- GROUP BY exposures.entity_id,- exposures.variant)- SELECT entity_metrics.variant AS variant,- count(entity_metrics.entity_id) AS num_users,- sum(entity_metrics.value) AS total_sum,- sum(power(entity_metrics.value, 2)) AS total_sum_of_squares- FROM entity_metrics- GROUP BY entity_metrics.variant- LIMIT 50000 SETTINGS join_algorithm='grace_hash',- grace_hash_join_initial_buckets=2,- format_csv_allow_double_quotes=1,- readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestExperimentQueryRunner.test_query_runner_data_warehouse_metric_with_fixed_properties'''WITH exposures AS@@ -381,63 +324,6 @@use_hive_partitioning=0'''# ----# name: TestExperimentQueryRunner.test_query_runner_data_warehouse_metric_with_no_properties- '''- WITH exposures AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- if(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,- min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,- max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,- argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,- argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id,- argMin(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$user_id'), ''), 'null'), '^"|"$', ''), toTimeZone(events.timestamp, 'UTC')) AS exposure_identifier- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-01-01 00:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2023-01-31 00:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))- GROUP BY entity_id),- metric_events AS- (SELECT posthog_test_usage.userid AS entity_id,- posthog_test_usage.ds AS timestamp,- coalesce(accurateCastOrNull(posthog_test_usage.usage, 'Float64'), 0) AS value- FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql.experiments.queryrunner/posthog_test_usage/*.csv', 'object_storage_root_user', 'object_storage_root_password', 'CSVWithNames', '`id` String, `ds` Date, `userid` String, `usage` Float64, `plan` String, `region` String') AS posthog_test_usage- WHERE and(greaterOrEquals(posthog_test_usage.ds, assumeNotNull(toDateTime('2023-01-01 00:00:00', 'UTC'))), less(posthog_test_usage.ds, plus(assumeNotNull(toDateTime('2023-01-31 00:00:00', 'UTC')), toIntervalSecond(0))))),- entity_metrics AS- (SELECT exposures.entity_id AS entity_id,- exposures.variant AS variant,- sum(coalesce(accurateCastOrNull(metric_events.value, 'Float64'), 0)) AS value- FROM exposures- LEFT JOIN metric_events ON and(equals(toString(exposures.exposure_identifier), toString(metric_events.entity_id)), greaterOrEquals(metric_events.timestamp, toTimeZone(exposures.first_exposure_time, 'UTC')))- GROUP BY exposures.entity_id,- exposures.variant)- SELECT entity_metrics.variant AS variant,- count(entity_metrics.entity_id) AS num_users,- sum(entity_metrics.value) AS total_sum,- sum(power(entity_metrics.value, 2)) AS total_sum_of_squares- FROM entity_metrics- GROUP BY entity_metrics.variant- LIMIT 50000 SETTINGS join_algorithm='grace_hash',- grace_hash_join_initial_buckets=2,- format_csv_allow_double_quotes=1,- readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestExperimentQueryRunner.test_query_runner_data_warehouse_metric_with_property_filters_0_single_property_filter'''WITH exposures ASdiff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_funnel_metric.ambr b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_funnel_metric.ambrindex a44fa4a0b66c..16bd38be2e2f 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_funnel_metric.ambr+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_funnel_metric.ambr@@ -1,137 +1,4 @@# serializer version: 1-# name: TestExperimentFunnelMetric.test_funnel_metric_duplicate_events_0_direct- '''- WITH base_events AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.uuid AS uuid,- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,- and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,- if(equals(events.event, '$pageview'), 1, 0) AS step_1,- if(equals(events.event, 'purchase'), 1, 0) AS step_2- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), or(and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), or(equals(events.event, '$pageview'), equals(events.event, 'purchase')))))),- entity_metrics AS- (SELECT base_events.entity_id AS entity_id,- if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp- FROM base_events- GROUP BY base_events.entity_id- HAVING greater(countIf(equals(base_events.step_0, 1)), 0))- SELECT entity_metrics.variant AS variant,- count(entity_metrics.entity_id) AS num_users,- countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,- countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)- and isNull(minus(3, 1))))) AS steps_event_data- FROM entity_metrics- WHERE notEmpty(variant)- GROUP BY entity_metrics.variant- LIMIT 50000 SETTINGS readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestExperimentFunnelMetric.test_funnel_metric_duplicate_events_1_precomputed- '''- WITH exposures AS- (SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,- if(greater(uniqExact(t.variant), 1), '$multiple', argMin(t.variant, toTimeZone(t.first_exposure_time, 'UTC'))) AS variant,- min(toTimeZone(t.first_exposure_time, 'UTC')) AS first_exposure_time,- max(toTimeZone(t.last_exposure_time, 'UTC')) AS last_exposure_time,- argMin(t.exposure_event_uuid, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_event_uuid,- argMin(t.exposure_session_id, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_session_id- FROM experiment_exposures_preaggregated AS t- WHERE and(equals(t.team_id, 99999), in(t.job_id, ['00000000-0000-0000-0000-000000000000']), equals(t.team_id, 99999), greaterOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), lessOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))))- GROUP BY entity_id),- metric_events AS- (SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,- toTimeZone(t.timestamp, 'UTC') AS timestamp,- t.event_uuid AS uuid,- t.session_id AS session_id,- arrayElement(t.steps, 1) AS step_0,- arrayElement(t.steps, 2) AS step_1,- arrayElement(t.steps, 3) AS step_2- FROM experiment_metric_events_preaggregated AS t- WHERE and(equals(t.team_id, 99999), in(t.job_id, ['00000000-0000-0000-0000-000000000000']), equals(t.team_id, 99999), greaterOrEquals(t.timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), lessOrEquals(t.timestamp, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))))),- entity_metrics AS- (SELECT exposures.entity_id AS entity_id,- exposures.variant AS variant,- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,- exposures.exposure_event_uuid AS exposure_event_uuid,- exposures.exposure_session_id AS exposure_session_id,- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp- FROM exposures- LEFT JOIN metric_events ON equals(exposures.entity_id, metric_events.entity_id)- GROUP BY exposures.entity_id,- exposures.variant,- exposures.exposure_event_uuid,- exposures.exposure_session_id,- toTimeZone(exposures.first_exposure_time, 'UTC'))- SELECT entity_metrics.variant AS variant,- count(entity_metrics.entity_id) AS num_users,- countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,- countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)- and isNull(minus(3, 1))))) AS steps_event_data- FROM entity_metrics- WHERE notEmpty(variant)- GROUP BY entity_metrics.variant- LIMIT 50000 SETTINGS load_balancing='in_order',- readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestExperimentFunnelMetric.test_funnel_metric_events_after_exposure_0_ordered'''WITH base_events AS@@ -275,139 +142,6 @@use_hive_partitioning=0'''# ----# name: TestExperimentFunnelMetric.test_funnel_metric_events_out_of_order_0_direct- '''- WITH base_events AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '') AS variant_value,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.uuid AS uuid,- nullIf(nullIf(events.`$session_id`, ''), 'null') AS session_id,- and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])) AS step_0,- if(equals(events.event, '$pageview'), 1, 0) AS step_1,- if(equals(events.event, 'purchase'), 1, 0) AS step_2- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), or(and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test'])), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), or(equals(events.event, '$pageview'), equals(events.event, 'purchase')))))),- entity_metrics AS- (SELECT base_events.entity_id AS entity_id,- if(greater(uniqExactIf(base_events.variant_value, equals(base_events.step_0, 1)), 1), '$multiple', anyIf(base_events.variant_value, equals(base_events.step_0, 1))) AS variant,- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(base_events.timestamp, 'UTC'), 'Float64'), base_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, base_events.step_0), multiply(2, base_events.step_1), multiply(3, base_events.step_2)]))))))))[1] AS value,- argMinIf(base_events.uuid, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_event_uuid,- argMinIf(base_events.session_id, toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_session_id,- minIf(toTimeZone(base_events.timestamp, 'UTC'), equals(base_events.step_0, 1)) AS exposure_timestamp,- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toString(base_events.session_id), ''))) AS uuid_to_session,- mapFromArrays(groupArray(coalesce(toString(base_events.uuid), '')), groupArray(coalesce(toTimeZone(base_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp- FROM base_events- GROUP BY base_events.entity_id- HAVING greater(countIf(equals(base_events.step_0, 1)), 0))- SELECT entity_metrics.variant AS variant,- count(entity_metrics.entity_id) AS num_users,- countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,- countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)- and isNull(minus(3, 1))))) AS steps_event_data- FROM entity_metrics- WHERE notEmpty(variant)- GROUP BY entity_metrics.variant- LIMIT 50000 SETTINGS readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestExperimentFunnelMetric.test_funnel_metric_events_out_of_order_1_precomputed- '''- WITH exposures AS- (SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,- if(greater(uniqExact(t.variant), 1), '$multiple', argMin(t.variant, toTimeZone(t.first_exposure_time, 'UTC'))) AS variant,- min(toTimeZone(t.first_exposure_time, 'UTC')) AS first_exposure_time,- max(toTimeZone(t.last_exposure_time, 'UTC')) AS last_exposure_time,- argMin(t.exposure_event_uuid, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_event_uuid,- argMin(t.exposure_session_id, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_session_id- FROM experiment_exposures_preaggregated AS t- WHERE and(equals(t.team_id, 99999), in(t.job_id, ['00000000-0000-0000-0000-000000000000']), equals(t.team_id, 99999), greaterOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), lessOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))))- GROUP BY entity_id),- metric_events AS- (SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,- toTimeZone(t.timestamp, 'UTC') AS timestamp,- t.event_uuid AS uuid,- t.session_id AS session_id,- arrayElement(t.steps, 1) AS step_0,- arrayElement(t.steps, 2) AS step_1,- arrayElement(t.steps, 3) AS step_2- FROM experiment_metric_events_preaggregated AS t- WHERE and(equals(t.team_id, 99999), in(t.job_id, ['00000000-0000-0000-0000-000000000000']), equals(t.team_id, 99999), greaterOrEquals(t.timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), lessOrEquals(t.timestamp, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))))),- entity_metrics AS- (SELECT exposures.entity_id AS entity_id,- exposures.variant AS variant,- arraySort(x -> minus(0, x.1), arrayMap(result -> tuple(result.1, if(and(ifNull(greaterOrEquals(result.1, 0), 0), ifNull(greater(length(result.4), result.1), 0)), if(ifNull(greater(length(arrayElement(result.4, plus(result.1, 1))), 0), 0), toString(arrayElement(result.4, plus(result.1, 1))[1]), ''), '')), aggregate_funnel_array(3, 94608000, 'first_touch', 'ordered', array(array('')), [], arraySort(t -> t.1, arrayFilter(t -> and(isNotNull(t.1), isNotNull(t.2)), groupArray(tuple(accurateCastOrNull(toTimeZone(metric_events.timestamp, 'UTC'), 'Float64'), metric_events.uuid, array(''), arrayFilter(x -> ifNull(greater(x, 0), 0), [multiply(1, metric_events.step_0), multiply(2, metric_events.step_1), multiply(3, metric_events.step_2)]))))))))[1] AS value,- exposures.exposure_event_uuid AS exposure_event_uuid,- exposures.exposure_session_id AS exposure_session_id,- toTimeZone(exposures.first_exposure_time, 'UTC') AS exposure_timestamp,- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toString(metric_events.session_id), ''))) AS uuid_to_session,- mapFromArrays(groupArray(coalesce(toString(metric_events.uuid), '')), groupArray(coalesce(toTimeZone(metric_events.timestamp, 'UTC'), toDateTime(0, 'UTC')))) AS uuid_to_timestamp- FROM exposures- LEFT JOIN metric_events ON equals(exposures.entity_id, metric_events.entity_id)- GROUP BY exposures.entity_id,- exposures.variant,- exposures.exposure_event_uuid,- exposures.exposure_session_id,- toTimeZone(exposures.first_exposure_time, 'UTC'))- SELECT entity_metrics.variant AS variant,- count(entity_metrics.entity_id) AS num_users,- countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum,- countIf(ifNull(equals((entity_metrics.value).1, 2), 0)) AS total_sum_of_squares,- tuple(countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 1), 0)), countIf(ifNull(greaterOrEquals((entity_metrics.value).1, 2), 0))) AS step_counts,- tuple(groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(1, 1)), isNull((entity_metrics.value).1)- and isNull(minus(1, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(2, 1)), isNull((entity_metrics.value).1)- and isNull(minus(2, 1)))), groupArraySampleIf(100)(if(ifNull(notEquals((entity_metrics.value).2, ''), 1), tuple(toString(entity_metrics.entity_id), entity_metrics.uuid_to_session[(entity_metrics.value).2], (entity_metrics.value).2, toString(entity_metrics.uuid_to_timestamp[(entity_metrics.value).2])), tuple(toString(entity_metrics.entity_id), toString(entity_metrics.exposure_session_id), toString(entity_metrics.exposure_event_uuid), toString(toTimeZone(entity_metrics.exposure_timestamp, 'UTC')))), ifNull(equals((entity_metrics.value).1, minus(3, 1)), isNull((entity_metrics.value).1)- and isNull(minus(3, 1))))) AS steps_event_data- FROM entity_metrics- WHERE notEmpty(variant)- GROUP BY entity_metrics.variant- LIMIT 50000 SETTINGS load_balancing='in_order',- readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestExperimentFunnelMetric.test_funnel_metric_excludes_different_feature_flags_0_direct'''WITH base_events ASdiff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_mean_metric.ambr b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_mean_metric.ambrindex b45db2d263b7..12852775585d 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_mean_metric.ambr+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_mean_metric.ambr@@ -127,134 +127,6 @@use_hive_partitioning=0'''# ----# name: TestExperimentMeanMetric.test_count_distinct_property_values_via_hogql_0_direct- '''- WITH exposures AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- if(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,- min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,- max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,- argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,- argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))- GROUP BY entity_id),- metric_events AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'category'), ''), 'null'), '^"|"$', '') AS value- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'purchase'))),- entity_metrics AS- (SELECT exposures.entity_id AS entity_id,- exposures.variant AS variant,- coalesce(accurateCastOrNull(count(DISTINCT metric_events.value), 'Float64'), 0) AS value- FROM exposures- LEFT JOIN metric_events ON and(equals(exposures.entity_id, metric_events.entity_id), greaterOrEquals(toTimeZone(metric_events.timestamp, 'UTC'), toTimeZone(exposures.first_exposure_time, 'UTC')))- GROUP BY exposures.entity_id,- exposures.variant)- SELECT entity_metrics.variant AS variant,- count(entity_metrics.entity_id) AS num_users,- sum(entity_metrics.value) AS total_sum,- sum(power(entity_metrics.value, 2)) AS total_sum_of_squares- FROM entity_metrics- GROUP BY entity_metrics.variant- LIMIT 50000 SETTINGS join_algorithm='grace_hash',- grace_hash_join_initial_buckets=2,- readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestExperimentMeanMetric.test_count_distinct_property_values_via_hogql_1_precomputed- '''- WITH exposures AS- (SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,- if(greater(uniqExact(t.variant), 1), '$multiple', argMin(t.variant, toTimeZone(t.first_exposure_time, 'UTC'))) AS variant,- min(toTimeZone(t.first_exposure_time, 'UTC')) AS first_exposure_time,- max(toTimeZone(t.last_exposure_time, 'UTC')) AS last_exposure_time,- argMin(t.exposure_event_uuid, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_event_uuid,- argMin(t.exposure_session_id, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_session_id- FROM experiment_exposures_preaggregated AS t- WHERE and(equals(t.team_id, 99999), in(t.job_id, ['00000000-0000-0000-0000-000000000000']), equals(t.team_id, 99999), greaterOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), lessOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC'))))- GROUP BY entity_id),- metric_events AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- toTimeZone(events.timestamp, 'UTC') AS timestamp,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'category'), ''), 'null'), '^"|"$', '') AS value- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2024-01-01 00:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2024-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'purchase'))),- entity_metrics AS- (SELECT exposures.entity_id AS entity_id,- exposures.variant AS variant,- coalesce(accurateCastOrNull(count(DISTINCT metric_events.value), 'Float64'), 0) AS value- FROM exposures- LEFT JOIN metric_events ON and(equals(exposures.entity_id, metric_events.entity_id), greaterOrEquals(toTimeZone(metric_events.timestamp, 'UTC'), toTimeZone(exposures.first_exposure_time, 'UTC')))- GROUP BY exposures.entity_id,- exposures.variant)- SELECT entity_metrics.variant AS variant,- count(entity_metrics.entity_id) AS num_users,- sum(entity_metrics.value) AS total_sum,- sum(power(entity_metrics.value, 2)) AS total_sum_of_squares- FROM entity_metrics- GROUP BY entity_metrics.variant- LIMIT 50000 SETTINGS join_algorithm='grace_hash',- grace_hash_join_initial_buckets=2,- load_balancing='in_order',- readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestExperimentMeanMetric.test_count_unique_property_values_via_hogql_0_direct'''WITH exposures ASdiff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_retention_metric.ambr b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_retention_metric.ambrindex 8ecd2ce5388c..e66423ee90d7 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_retention_metric.ambr+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_retention_metric.ambr@@ -1841,186 +1841,6 @@use_hive_partitioning=0'''# ----# name: TestExperimentRetentionMetric.test_retention_same_start_and_end_window_0_disable_new_query_builder- '''- WITH exposures AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- if(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,- min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,- max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,- argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,- argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))- GROUP BY entity_id),- start_events AS- (SELECT exposures.entity_id AS entity_id,- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,- argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- INNER JOIN exposures ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), exposures.entity_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'signup')), greaterOrEquals(events.timestamp, toTimeZone(exposures.first_exposure_time, 'UTC')))- GROUP BY exposures.entity_id),- completion_events AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- events.uuid AS completion_uuid,- toTimeZone(events.timestamp, 'UTC') AS completion_timestamp- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC')), toIntervalSecond(604800))), equals(events.event, 'login'))),- entity_metrics AS- (SELECT exposures.entity_id AS entity_id,- exposures.variant AS variant,- max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value- FROM exposures- INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))- GROUP BY exposures.entity_id,- exposures.variant)- SELECT entity_metrics.variant AS variant,- count(entity_metrics.entity_id) AS num_users,- sum(entity_metrics.value) AS total_sum,- sum(power(entity_metrics.value, 2)) AS total_sum_of_squares,- count(entity_metrics.entity_id) AS denominator_sum,- count(entity_metrics.entity_id) AS denominator_sum_squares,- sum(entity_metrics.value) AS numerator_denominator_sum_product- FROM entity_metrics- WHERE notEmpty(variant)- GROUP BY entity_metrics.variant- LIMIT 50000 SETTINGS readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ----# name: TestExperimentRetentionMetric.test_retention_same_start_and_end_window_1_enable_new_query_builder- '''- WITH exposures AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- if(greater(uniqExact(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', '')), 1), '$multiple', any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''))) AS variant,- min(toTimeZone(events.timestamp, 'UTC')) AS first_exposure_time,- max(toTimeZone(events.timestamp, 'UTC')) AS last_exposure_time,- argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS exposure_event_uuid,- argMin(events.`$session_id`, toTimeZone(events.timestamp, 'UTC')) AS exposure_session_id- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), lessOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC'))), and(equals(events.event, '$feature_flag_called'), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag'), ''), 'null'), '^"|"$', ''), 'test-experiment'), 0)), ifNull(notILike(toString(events__person.properties___email), '%@posthog.com%'), 1), in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$feature_flag_response'), ''), 'null'), '^"|"$', ''), ['control', 'test']))- GROUP BY entity_id),- start_events AS- (SELECT exposures.entity_id AS entity_id,- min(toTimeZone(events.timestamp, 'UTC')) AS start_timestamp,- argMin(events.uuid, toTimeZone(events.timestamp, 'UTC')) AS start_uuid- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- INNER JOIN exposures ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), exposures.entity_id)- WHERE and(equals(events.team_id, 99999), and(greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC')), toIntervalSecond(0))), equals(events.event, 'signup')), greaterOrEquals(events.timestamp, toTimeZone(exposures.first_exposure_time, 'UTC')))- GROUP BY exposures.entity_id),- completion_events AS- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,- events.uuid AS completion_uuid,- toTimeZone(events.timestamp, 'UTC') AS completion_timestamp- FROM events- LEFT OUTER JOIN- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) 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 equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 12:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2020-01-15 12:00:00', 'UTC')), toIntervalSecond(604800))), equals(events.event, 'login'))),- entity_metrics AS- (SELECT exposures.entity_id AS entity_id,- exposures.variant AS variant,- max(if(and(isNotNull(toTimeZone(completion_events.completion_timestamp, 'UTC')), greaterOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7))), lessOrEquals(toStartOfDay(toTimeZone(completion_events.completion_timestamp, 'UTC')), plus(toStartOfDay(toTimeZone(start_events.start_timestamp, 'UTC')), toIntervalDay(7)))), 1, 0)) AS value- FROM exposures- INNER JOIN start_events ON equals(exposures.entity_id, start_events.entity_id)- LEFT JOIN completion_events ON and(equals(exposures.entity_id, completion_events.entity_id), and(greaterOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), toTimeZone(start_events.start_timestamp, 'UTC')), lessOrEquals(toTimeZone(completion_events.completion_timestamp, 'UTC'), plus(toTimeZone(start_events.start_timestamp, 'UTC'), toIntervalSecond(691200)))), notEquals(completion_events.completion_uuid, start_events.start_uuid))- GROUP BY exposures.entity_id,- exposures.variant)- SELECT entity_metrics.variant AS variant,- count(entity_metrics.entity_id) AS num_users,- sum(entity_metrics.value) AS total_sum,- sum(power(entity_metrics.value, 2)) AS total_sum_of_squares,- count(entity_metrics.entity_id) AS denominator_sum,- count(entity_metrics.entity_id) AS denominator_sum_squares,- sum(entity_metrics.value) AS numerator_denominator_sum_product- FROM entity_metrics- WHERE notEmpty(variant)- GROUP BY entity_metrics.variant- LIMIT 50000 SETTINGS readonly=2,- max_execution_time=600,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=39728447488,- transform_null_in=1,- optimize_min_equality_disjunction_chain_length=4294967295,- optimize_rewrite_aggregate_function_with_if=0,- optimize_min_inequality_conjunction_chain_length=4294967295,- allow_experimental_join_condition=1,- use_hive_partitioning=0- '''-# ---# name: TestExperimentRetentionMetric.test_retention_start_event_before_exposure_not_excluded_0_direct'''WITH exposures ASdiff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_breakdown.py b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_breakdown.pyindex c09785e28691..c521a471befb 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_breakdown.py+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_breakdown.py@@ -1,9 +1,7 @@-from datetime import datetimefrom typing import castfrom freezegun import freeze_timefrom posthog.test.base import _create_event, _create_person, flush_persons_and_events, snapshot_clickhouse_queries-from unittest import skipfrom django.test import override_settings@@ -13,7 +11,6 @@ from posthog.schema import (Breakdown,BreakdownFilter,EventsNode,- ExperimentDataWarehouseNode,ExperimentFunnelMetric,ExperimentMeanMetric,ExperimentMetricMathType,@@ -849,134 +846,6 @@ class TestExperimentBreakdown(ExperimentQueryRunnerBaseTest):self.assertIsNotNone(variant.number_of_samples)self.assertEqual(variant.number_of_samples, 2) # 2 users per combination- @freeze_time("2020-01-01T12:00:00Z")- @snapshot_clickhouse_queries- def test_mean_metric_with_three_breakdowns(self):- """Test mean metric calculations work correctly with maximum (3) breakdown dimensions"""- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(feature_flag=feature_flag)- experiment.stats_config = {"method": "frequentist"}- experiment.save()-- metric = ExperimentMeanMetric(- source=EventsNode(- event="purchase",- math=ExperimentMetricMathType.SUM,- math_property="amount",- ),- breakdownFilter=BreakdownFilter(- breakdowns=[- Breakdown(property="$browser"),- Breakdown(property="$os"),- Breakdown(property="$device_type"),- ]- ),- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.metrics = [metric.model_dump(mode="json")]- experiment.save()-- feature_flag_property = f"$feature/{feature_flag.key}"-- # Control group - 16 users (2 per combination for 8 combinations)- for i in range(16):- browser = "Chrome" if i < 8 else "Safari"- os = "Windows" if i % 4 < 2 else "Mac"- device_type = "Desktop" if i % 2 == 0 else "Mobile"- amount = 10 + i # Different amounts for variety-- _create_person(distinct_ids=[f"user_control_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_control_{i}",- timestamp="2020-01-02T12:00:00Z",- properties={- feature_flag_property: "control",- "$feature_flag_response": "control",- "$feature_flag": feature_flag.key,- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_control_{i}",- timestamp="2020-01-02T12:01:00Z",- properties={- feature_flag_property: "control",- "amount": amount,- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )-- # Test group - 16 users (2 per combination)- for i in range(16):- browser = "Chrome" if i < 8 else "Safari"- os = "Windows" if i % 4 < 2 else "Mac"- device_type = "Desktop" if i % 2 == 0 else "Mobile"- amount = 12 + i # Slightly higher amounts-- _create_person(distinct_ids=[f"user_test_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_test_{i}",- timestamp="2020-01-02T12:00:00Z",- properties={- feature_flag_property: "test",- "$feature_flag_response": "test",- "$feature_flag": feature_flag.key,- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_test_{i}",- timestamp="2020-01-02T12:01:00Z",- properties={- feature_flag_property: "test",- "amount": amount,- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )-- flush_persons_and_events()-- query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)- result = cast(ExperimentQueryResponse, query_runner.calculate())-- # Verify 8 breakdown combinations (2×2×2)- assert result.breakdown_results is not None- self.assertEqual(len(result.breakdown_results), 8)-- # Spot check a specific breakdown- chrome_windows_desktop = None- assert result.breakdown_results is not None- for breakdown_result in result.breakdown_results:- if breakdown_result.breakdown_value == ["Chrome", "Windows", "Desktop"]:- chrome_windows_desktop = breakdown_result- break-- self.assertIsNotNone(chrome_windows_desktop)- assert chrome_windows_desktop is not None- self.assertEqual(chrome_windows_desktop.baseline.number_of_samples, 2)-@freeze_time("2020-01-01T12:00:00Z")@snapshot_clickhouse_queriesdef test_funnel_metric_with_two_breakdowns(self):@@ -1078,117 +947,6 @@ class TestExperimentBreakdown(ExperimentQueryRunnerBaseTest):assert result.breakdown_results is not Noneself.assertEqual(len(result.breakdown_results), 4)- @freeze_time("2020-01-01T12:00:00Z")- @snapshot_clickhouse_queries- def test_funnel_metric_with_three_breakdowns(self):- """Test funnel metrics work with 3 breakdown dimensions"""- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(feature_flag=feature_flag)- experiment.stats_config = {"method": "frequentist"}- experiment.save()-- metric = ExperimentFunnelMetric(- series=[EventsNode(event="purchase")],- breakdownFilter=BreakdownFilter(- breakdowns=[- Breakdown(property="$browser"),- Breakdown(property="$os"),- Breakdown(property="$device_type"),- ]- ),- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.metrics = [metric.model_dump(mode="json")]- experiment.save()-- feature_flag_property = f"$feature/{feature_flag.key}"-- # Control group - 24 users (3 per combination for 8 combinations)- for i in range(24):- browser = "Chrome" if i < 12 else "Safari"- os = "Windows" if i % 6 < 3 else "Mac"- device_type = "Desktop" if i % 3 == 0 else "Mobile"- completes_funnel = i % 2 == 0 # Half complete the funnel-- _create_person(distinct_ids=[f"user_control_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_control_{i}",- timestamp="2020-01-02T12:00:00Z",- properties={- feature_flag_property: "control",- "$feature_flag_response": "control",- "$feature_flag": feature_flag.key,- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )- if completes_funnel:- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_control_{i}",- timestamp="2020-01-02T12:01:00Z",- properties={- feature_flag_property: "control",- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )-- # Test group - similar pattern- for i in range(24):- browser = "Chrome" if i < 12 else "Safari"- os = "Windows" if i % 6 < 3 else "Mac"- device_type = "Desktop" if i % 3 == 0 else "Mobile"- completes_funnel = i % 2 == 1 # Different pattern-- _create_person(distinct_ids=[f"user_test_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_test_{i}",- timestamp="2020-01-02T12:00:00Z",- properties={- feature_flag_property: "test",- "$feature_flag_response": "test",- "$feature_flag": feature_flag.key,- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )- if completes_funnel:- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_test_{i}",- timestamp="2020-01-02T12:01:00Z",- properties={- feature_flag_property: "test",- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )-- flush_persons_and_events()-- query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)- result = cast(ExperimentQueryResponse, query_runner.calculate())-- assert result.breakdown_results is not None- self.assertEqual(len(result.breakdown_results), 8)-@freeze_time("2020-01-01T12:00:00Z")def test_funnel_metric_breakdown_query_builds_without_ambiguity_error(self):"""@@ -1350,150 +1108,6 @@ class TestExperimentBreakdown(ExperimentQueryRunnerBaseTest):self.assertIsNotNone(variant.sum)self.assertIsNotNone(variant.denominator_sum)- @freeze_time("2020-01-01T12:00:00Z")- @snapshot_clickhouse_queries- def test_ratio_metric_with_three_breakdowns(self):- """Test ratio metrics work with 3 breakdown dimensions"""- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(feature_flag=feature_flag)- experiment.stats_config = {"method": "frequentist"}- experiment.save()-- metric = ExperimentRatioMetric(- numerator=EventsNode(event="purchase", math=ExperimentMetricMathType.SUM, math_property="amount"),- denominator=EventsNode(event="view_item", math=ExperimentMetricMathType.TOTAL),- breakdownFilter=BreakdownFilter(- breakdowns=[- Breakdown(property="$browser"),- Breakdown(property="$os"),- Breakdown(property="$device_type"),- ]- ),- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.metrics = [metric.model_dump(mode="json")]- experiment.save()-- feature_flag_property = f"$feature/{feature_flag.key}"-- # Control group - 16 users (2 per combination)- for i in range(16):- browser = "Chrome" if i < 8 else "Safari"- os = "Windows" if i % 4 < 2 else "Mac"- device_type = "Desktop" if i % 2 == 0 else "Mobile"- view_count = 2 + (i % 4) # Vary denominator-- _create_person(distinct_ids=[f"user_control_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_control_{i}",- timestamp="2020-01-02T12:00:00Z",- properties={- feature_flag_property: "control",- "$feature_flag_response": "control",- "$feature_flag": feature_flag.key,- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_control_{i}",- timestamp="2020-01-02T12:01:00Z",- properties={- feature_flag_property: "control",- "amount": 100,- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )- for _ in range(view_count):- _create_event(- team=self.team,- event="view_item",- distinct_id=f"user_control_{i}",- timestamp="2020-01-02T12:02:00Z",- properties={- feature_flag_property: "control",- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )-- # Test group- for i in range(16):- browser = "Chrome" if i < 8 else "Safari"- os = "Windows" if i % 4 < 2 else "Mac"- device_type = "Desktop" if i % 2 == 0 else "Mobile"- view_count = 3 + (i % 3)-- _create_person(distinct_ids=[f"user_test_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_test_{i}",- timestamp="2020-01-02T12:00:00Z",- properties={- feature_flag_property: "test",- "$feature_flag_response": "test",- "$feature_flag": feature_flag.key,- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_test_{i}",- timestamp="2020-01-02T12:01:00Z",- properties={- feature_flag_property: "test",- "amount": 150,- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )- for _ in range(view_count):- _create_event(- team=self.team,- event="view_item",- distinct_id=f"user_test_{i}",- timestamp="2020-01-02T12:02:00Z",- properties={- feature_flag_property: "test",- "$browser": browser,- "$os": os,- "$device_type": device_type,- },- )-- flush_persons_and_events()-- query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)- result = cast(ExperimentQueryResponse, query_runner.calculate())-- assert result.breakdown_results is not None- self.assertEqual(len(result.breakdown_results), 8)-- # Verify 3-element breakdown values and ratio fields- for breakdown_result in result.breakdown_results:- self.assertEqual(len(breakdown_result.breakdown_value), 3)- self.assertIsNotNone(breakdown_result.baseline.sum)- self.assertIsNotNone(breakdown_result.baseline.denominator_sum)-def test_breakdown_validation_raises_error_for_more_than_three(self):"""Verify that using more than 3 breakdowns raises a ValidationError"""from pydantic import ValidationError as PydanticValidationError@@ -1644,186 +1258,6 @@ class TestExperimentBreakdown(ExperimentQueryRunnerBaseTest):self.assertTrue(chrome_windows_found, "Chrome+Windows breakdown should exist")self.assertTrue(safari_mac_found, "Safari+Mac breakdown should exist")- @skip("potential flakiness")- @freeze_time("2023-01-01T12:00:00Z")- @snapshot_clickhouse_queries- def test_data_warehouse_mean_metric_with_breakdown(self):- """Test data warehouse mean metrics work with breakdowns"""- table_name = self.create_data_warehouse_table_with_usage()- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(- feature_flag=feature_flag, start_date=datetime(2023, 1, 1), end_date=datetime(2023, 1, 31)- )- experiment.stats_config = {"method": "frequentist"}- experiment.save()-- metric = ExperimentMeanMetric(- source=ExperimentDataWarehouseNode(- table_name=table_name,- events_join_key="properties.$user_id",- data_warehouse_join_key="userid",- timestamp_field="ds",- math=ExperimentMetricMathType.SUM,- math_property="usage",- ),- breakdownFilter=BreakdownFilter(breakdowns=[Breakdown(property="plan")]),- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.metrics = [metric.model_dump(mode="json")]- experiment.save()-- feature_flag_property = f"$feature/{feature_flag.key}"-- # Control group: 6 users- for i in range(6):- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"distinct_control_{i}",- properties={- "$feature_flag_response": "control",- feature_flag_property: "control",- "$feature_flag": feature_flag.key,- "$user_id": f"user_control_{i}",- },- timestamp=datetime(2023, 1, i + 1),- )-- # Test group: 6 users- for i in range(6):- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"distinct_test_{i}",- properties={- "$feature_flag_response": "test",- feature_flag_property: "test",- "$feature_flag": feature_flag.key,- "$user_id": f"user_test_{i}",- },- timestamp=datetime(2023, 1, i + 1),- )-- flush_persons_and_events()-- query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)- result = cast(ExperimentQueryResponse, query_runner.calculate())-- # Verify breakdown by data warehouse property-- # Verify breakdown_results structure- assert result.breakdown_results is not None- self.assertGreater(len(result.breakdown_results), 0)-- for breakdown_result in result.breakdown_results:- self.assertIsNotNone(breakdown_result.baseline)- self.assertGreater(len(breakdown_result.variants), 0)-- @skip("potential flakiness")- @freeze_time("2023-01-01T12:00:00Z")- @snapshot_clickhouse_queries- def test_data_warehouse_ratio_metric_with_breakdown(self):- """Test data warehouse ratio metrics work with breakdowns"""- usage_table = self.create_data_warehouse_table_with_usage()- subscriptions_table = self.create_data_warehouse_table_with_subscriptions()-- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(- feature_flag=feature_flag, start_date=datetime(2023, 1, 1), end_date=datetime(2023, 1, 31)- )- experiment.stats_config = {"method": "frequentist"}- experiment.save()-- metric = ExperimentRatioMetric(- numerator=ExperimentDataWarehouseNode(- table_name=usage_table,- events_join_key="properties.$user_id",- data_warehouse_join_key="userid",- timestamp_field="ds",- math=ExperimentMetricMathType.SUM,- math_property="usage",- ),- denominator=ExperimentDataWarehouseNode(- table_name=subscriptions_table,- events_join_key="person.properties.email",- data_warehouse_join_key="subscription_customer.customer_email",- timestamp_field="subscription_created_at",- math=ExperimentMetricMathType.TOTAL,- ),- breakdownFilter=BreakdownFilter(breakdowns=[Breakdown(property="region")]),- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.metrics = [metric.model_dump(mode="json")]- experiment.save()-- feature_flag_property = f"$feature/{feature_flag.key}"-- # Control group- for i in range(3):- _create_person(- team=self.team, distinct_ids=[f"user_control_{i}"], properties={"email": f"user{i}@example.com"}- )- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_control_{i}",- properties={- "$feature_flag_response": "control",- feature_flag_property: "control",- "$feature_flag": feature_flag.key,- "$user_id": f"user_control_{i}",- },- timestamp=datetime(2023, 1, i + 1),- )-- # Test group- for i in range(3):- _create_person(- team=self.team, distinct_ids=[f"user_test_{i}"], properties={"email": f"test{i}@example.com"}- )- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_test_{i}",- properties={- "$feature_flag_response": "test",- feature_flag_property: "test",- "$feature_flag": feature_flag.key,- "$user_id": f"user_test_{i}",- },- timestamp=datetime(2023, 1, i + 1),- )-- flush_persons_and_events()-- query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)- result = cast(ExperimentQueryResponse, query_runner.calculate())-- # Verify breakdown structure-- # Verify ratio-specific fields per breakdown- assert result.breakdown_results is not None- for breakdown_result in result.breakdown_results:- baseline = breakdown_result.baseline- self.assertIsNotNone(baseline.sum)- self.assertIsNotNone(baseline.denominator_sum)-- for variant in breakdown_result.variants:- self.assertIsNotNone(variant.sum)- self.assertIsNotNone(variant.denominator_sum)-@parameterized.expand([("new_query_builder", True)])@freeze_time("2020-01-01T12:00:00Z")@snapshot_clickhouse_queriesdiff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_data_warehouse_metric.py b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_data_warehouse_metric.pyindex 2c4f957ece44..91e66ab40bb7 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_data_warehouse_metric.py+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_data_warehouse_metric.py@@ -849,157 +849,6 @@ class TestExperimentQueryRunner(ExperimentQueryRunnerBaseTest):self.assertEqual(control_result.number_of_samples, 7)self.assertEqual(test_result.number_of_samples, 9)- @snapshot_clickhouse_queries- def test_query_runner_data_warehouse_metric_with_both_properties_and_fixed_properties(self):- """Test that data warehouse metrics properly apply both properties and fixedProperties"""- table_name = self.create_data_warehouse_table_with_usage()-- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(- feature_flag=feature_flag, start_date=datetime(2023, 1, 1), end_date=datetime(2023, 1, 31)- )- experiment.save()-- feature_flag_property = f"$feature/{feature_flag.key}"-- metric = ExperimentMeanMetric(- source=ExperimentDataWarehouseNode(- table_name=table_name,- events_join_key="properties.$user_id",- data_warehouse_join_key="userid",- timestamp_field="ds",- math=ExperimentMetricMathType.SUM,- math_property="usage",- properties=clean_entity_properties(- [- {"key": "plan", "operator": "exact", "value": "premium", "type": "data_warehouse"},- ]- ),- fixedProperties=clean_entity_properties(- [- {"key": "region", "operator": "exact", "value": "us-west", "type": "data_warehouse"},- ]- ),- ),- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.exposure_criteria = {"filterTestAccounts": False}- experiment.metrics = [metric.model_dump(mode="json")]- experiment.save()-- # Populate exposure events- for variant, count in [("control", 7), ("test", 9)]:- for i in range(count):- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"distinct_{variant}_{i}",- properties={- "$feature_flag_response": variant,- feature_flag_property: variant,- "$feature_flag": feature_flag.key,- "$user_id": f"user_{variant}_{i}",- },- timestamp=datetime(2023, 1, i + 1),- )-- flush_persons_and_events()-- query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)- with freeze_time("2023-01-07"):- result = query_runner.calculate()-- assert result.variant_results is not None- self.assertEqual(len(result.variant_results), 1)-- control_result = result.baseline- assert control_result is not None- test_result = result.variant_results[0]- assert test_result is not None-- # Should filter to only premium plan AND us-west region- self.assertEqual(control_result.sum, 250)- self.assertEqual(test_result.sum, 375)- self.assertEqual(control_result.number_of_samples, 7)- self.assertEqual(test_result.number_of_samples, 9)-- @snapshot_clickhouse_queries- def test_query_runner_data_warehouse_metric_with_no_properties(self):- """Test that data warehouse metrics work without any property filters (baseline behavior)"""- table_name = self.create_data_warehouse_table_with_usage()-- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(- feature_flag=feature_flag, start_date=datetime(2023, 1, 1), end_date=datetime(2023, 1, 31)- )- experiment.save()-- feature_flag_property = f"$feature/{feature_flag.key}"-- metric = ExperimentMeanMetric(- source=ExperimentDataWarehouseNode(- table_name=table_name,- events_join_key="properties.$user_id",- data_warehouse_join_key="userid",- timestamp_field="ds",- math=ExperimentMetricMathType.SUM,- math_property="usage",- # No properties or fixedProperties- ),- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.exposure_criteria = {"filterTestAccounts": False}- experiment.metrics = [metric.model_dump(mode="json")]- experiment.save()-- # Populate exposure events- for variant, count in [("control", 7), ("test", 9)]:- for i in range(count):- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"distinct_{variant}_{i}",- properties={- "$feature_flag_response": variant,- feature_flag_property: variant,- "$feature_flag": feature_flag.key,- "$user_id": f"user_{variant}_{i}",- },- timestamp=datetime(2023, 1, i + 1),- )-- flush_persons_and_events()-- query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)- with freeze_time("2023-01-07"):- result = query_runner.calculate()-- assert result.variant_results is not None- self.assertEqual(len(result.variant_results), 1)-- control_result = result.baseline- assert control_result is not None- test_result = result.variant_results[0]- assert test_result is not None-- # Should include all data (no filters)- self.assertEqual(control_result.sum, 650)- self.assertEqual(test_result.sum, 1150)- self.assertEqual(control_result.number_of_samples, 7)- self.assertEqual(test_result.number_of_samples, 9)-@snapshot_clickhouse_queriesdef test_ratio_metric_with_different_join_keys(self):"""Test ratio metric where numerator and denominator use different join keys"""diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_experiment_exposures_query_runner.py b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_experiment_exposures_query_runner.pyindex 340ee9058e5a..5e4ab7287b0c 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_experiment_exposures_query_runner.py+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_experiment_exposures_query_runner.py@@ -20,7 +20,6 @@ from products.experiments.backend.hogql_queries.test.experiment_query_runner.basfrom products.experiments.backend.hogql_queries.test.experiment_query_runner.utils import (create_standard_group_test_events,)-from products.experiments.backend.models.experiment import ExperimentHoldoutfrom products.feature_flags.backend.models.feature_flag import FeatureFlag@@ -1700,109 +1699,3 @@ class TestExperimentExposuresQueryRunner(ExperimentQueryRunnerBaseTest):risk = running_runner._evaluate_bias_risk(total_exposures)assert risk is not Noneself.assertGreater(risk.multiple_variant_percentage, 0)---@override_settings(IN_UNIT_TESTING=True)-class TestExposureRunnerVariantFiltering(ExperimentQueryRunnerBaseTest):- @staticmethod- def _holdout_to_dict(holdout):- # model_to_dict includes team/created_at as Python objects, which fail pydantic- # validation. Build a minimal dict that matches ExperimentHoldoutType instead.- return {- "id": holdout.id,- "name": holdout.name,- "filters": holdout.filters,- }-- def _make_query(self, experiment):- return ExperimentExposureQuery(- kind="ExperimentExposureQuery",- experiment_id=experiment.id,- experiment_name=experiment.name,- feature_flag=model_to_dict(experiment.feature_flag),- holdout=self._holdout_to_dict(experiment.holdout) if experiment.holdout else None,- start_date=experiment.start_date.isoformat() if experiment.start_date else None,- end_date=experiment.end_date.isoformat() if experiment.end_date else None,- exposure_criteria=experiment.exposure_criteria,- )-- # Sentinel used in `excluded_variants` specs to mean "the attached holdout's pseudo-key",- # resolved to `holdout-{id}` once the holdout row exists.- _HOLDOUT_KEY = "<holdout>"-- @parameterized.expand(- [- # name, extra_variants, attach_holdout, parameters- ("no_holdout_no_exclusions", [], False, "unset"),- ("holdout_attached", [], True, "unset"),- ("excluded_variant_dropped", ["test-2"], False, {"excluded_variants": ["test-2"]}),- ("holdout_and_excluded_both_filtered", ["test-2"], True, {"excluded_variants": ["test-2"]}),- ("null_parameters_does_not_raise", [], False, None),- ("empty_excluded_variants_is_noop", [], False, {"excluded_variants": []}),- ("excluded_variants_naming_holdout_is_idempotent", [], True, {"excluded_variants": [_HOLDOUT_KEY]}),- ]- )- @freeze_time("2024-01-01T12:00:00Z")- def test_runner_variant_filtering(self, name, extra_variants, attach_holdout, parameters):- feature_flag = self.create_feature_flag(key=f"{name.replace('_', '-')}-test")- for index, variant_key in enumerate(extra_variants):- feature_flag.filters["multivariate"]["variants"].append(- {"key": variant_key, "name": f"Test {index + 2}", "rollout_percentage": 33}- )- if extra_variants:- feature_flag.save()-- experiment = self.create_experiment(feature_flag=feature_flag)-- holdout = None- if attach_holdout:- holdout = ExperimentHoldout.objects.create(- team=self.team,- name=f"Holdout {name}",- filters=[{"properties": [], "rollout_percentage": 20}],- )- experiment.holdout = holdout-- if parameters != "unset":- resolved = parameters- if isinstance(parameters, dict):- holdout_key = f"holdout-{holdout.id}" if holdout is not None else self._HOLDOUT_KEY- resolved = {- **parameters,- "excluded_variants": [- holdout_key if key == self._HOLDOUT_KEY else key- for key in parameters.get("excluded_variants", [])- ],- }- experiment.parameters = resolved- experiment.save()-- runner = ExperimentExposuresQueryRunner(team=self.team, query=self._make_query(experiment))-- # The runner always reports exactly the analyzable variants — holdout pseudo-variants- # and excluded variants are filtered out regardless of how they were specified.- assert set(runner.variants) == {"control", "test"}- if holdout is not None:- assert f"holdout-{holdout.id}" not in runner.variants- assert runner.query.holdout is not None # still available for SRM-- def test_srm_no_false_alarm_when_holdout_present_but_balanced(self):- feature_flag = self.create_feature_flag(key="srm-balanced-with-holdout-test")- holdout = ExperimentHoldout.objects.create(- team=self.team,- name="Holdout SRM",- filters=[{"properties": [], "rollout_percentage": 20}],- )- experiment = self.create_experiment(feature_flag=feature_flag)- experiment.holdout = holdout- experiment.save()- runner = ExperimentExposuresQueryRunner(team=self.team, query=self._make_query(experiment))-- # 100 exposed users at 50/50 split. Holdout key absent (matches new reality).- # total_observed = 50+50 = 100, meeting SRM_MINIMUM_SAMPLE_SIZE.- total_exposures = {"control": 50, "test": 50}- result = runner._calculate_srm(total_exposures)- assert result is not None- # Expected percentages should be the holdout-adjusted 40/40 = 50/50 of exposed- # (we drop holdout from rollout_percentages). p_value should be 1.0 for perfect balance.- assert result.p_value == 1.0diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_funnel_metric.py b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_funnel_metric.pyindex c78bc20967fa..0990992d966f 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_funnel_metric.py+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_funnel_metric.py@@ -1586,243 +1586,6 @@ class TestExperimentFunnelMetric(ExperimentQueryRunnerBaseTest):self.assertEqual(test_variant.sum, 6) # 6 successful funnelsself.assertEqual(test_variant.number_of_samples - test_variant.sum, 7) # 7 failures- @parameterized.expand(- [- ("direct", False),- ("precomputed", True),- ]- )- @freeze_time("2024-01-01T12:00:00Z")- @snapshot_clickhouse_queries- def test_funnel_metric_duplicate_events(self, name, use_precomputation):- self._setup_precomputation_test(use_precomputation)-- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(feature_flag=feature_flag)- experiment.stats_config = {"method": "frequentist"}- experiment.save()-- ff_property = f"$feature/{feature_flag.key}"-- # Create test data with sufficient sample sizes for statistics- # Control group: 8 successful funnels, 5 failures (13 total)- for i in range(13):- _create_person(distinct_ids=[f"user_control_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_control_{i}",- timestamp="2024-01-02T12:00:00Z",- properties={- "$feature_flag_response": "control",- ff_property: "control",- "$feature_flag": feature_flag.key,- },- )- _create_event(- team=self.team,- event="$pageview",- distinct_id=f"user_control_{i}",- timestamp="2024-01-02T12:01:00Z",- properties={ff_property: "control"},- )- if i < 8: # First 8 users complete the funnel- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_control_{i}",- timestamp="2024-01-02T12:02:00Z",- properties={ff_property: "control"},- )-- # Test group: 6 successful funnels, 7 failures (13 total)- for i in range(13):- _create_person(distinct_ids=[f"user_test_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_test_{i}",- timestamp="2024-01-02T12:00:00Z",- properties={- "$feature_flag_response": "test",- ff_property: "test",- "$feature_flag": feature_flag.key,- },- )- _create_event(- team=self.team,- event="$pageview",- distinct_id=f"user_test_{i}",- timestamp="2024-01-02T12:01:00Z",- properties={ff_property: "test"},- )- if i < 6: # First 6 users complete the funnel- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_test_{i}",- timestamp="2024-01-02T12:02:00Z",- properties={ff_property: "test"},- )-- flush_persons_and_events()-- action = Action.objects.create(name="purchase action", team=self.team, steps_json=[{"event": "purchase"}])- action.save()-- metric = ExperimentFunnelMetric(- series=[- EventsNode(event="$pageview"),- ActionsNode(id=action.id),- ],- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.metrics = [metric.model_dump(mode="json")]- self._save_experiment_with_precomputation(experiment, use_precomputation)-- query_runner = ExperimentQueryRunner(- query=experiment_query,- team=self.team,- )- result = query_runner.calculate()-- assert result.variant_results is not None- self.assertEqual(len(result.variant_results), 1)-- control_variant = result.baseline- assert control_variant is not None- test_variant = result.variant_results[0]- assert test_variant is not None-- self.assertEqual(control_variant.sum, 8) # 8 successful funnels- self.assertEqual(control_variant.number_of_samples - control_variant.sum, 5) # 5 failures- self.assertEqual(test_variant.sum, 6) # 6 successful funnels- self.assertEqual(test_variant.number_of_samples - test_variant.sum, 7) # 7 failures-- @parameterized.expand(- [- ("direct", False),- ("precomputed", True),- ]- )- @freeze_time("2024-01-01T12:00:00Z")- @snapshot_clickhouse_queries- def test_funnel_metric_events_out_of_order(self, name, use_precomputation):- self._setup_precomputation_test(use_precomputation)-- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(feature_flag=feature_flag)- experiment.stats_config = {"method": "frequentist"}- experiment.save()-- ff_property = f"$feature/{feature_flag.key}"-- # Control group: 8 successful funnels, 5 failures (13 total)- for i in range(13):- _create_person(distinct_ids=[f"user_control_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_control_{i}",- timestamp="2024-01-02T12:00:00Z",- properties={- "$feature_flag_response": "control",- ff_property: "control",- "$feature_flag": feature_flag.key,- },- )- _create_event(- team=self.team,- event="$pageview",- distinct_id=f"user_control_{i}",- timestamp="2024-01-02T12:01:00Z",- properties={ff_property: "control"},- )- if i < 8: # First 8 users complete the funnel- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_control_{i}",- timestamp="2024-01-02T12:02:00Z",- properties={ff_property: "control"},- )-- # Test group: 6 successful funnels, 7 failures (13 total)- for i in range(13):- _create_person(distinct_ids=[f"user_test_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_test_{i}",- timestamp="2024-01-02T12:00:00Z",- properties={- "$feature_flag_response": "test",- ff_property: "test",- "$feature_flag": feature_flag.key,- },- )- _create_event(- team=self.team,- event="$pageview",- distinct_id=f"user_test_{i}",- timestamp="2024-01-02T12:01:00Z",- properties={ff_property: "test"},- )- if i < 6: # First 6 users complete the funnel- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_test_{i}",- timestamp="2024-01-02T12:02:00Z",- properties={ff_property: "test"},- )-- flush_persons_and_events()-- action = Action.objects.create(name="purchase action", team=self.team, steps_json=[{"event": "purchase"}])- action.save()-- metric = ExperimentFunnelMetric(- series=[- EventsNode(event="$pageview"),- ActionsNode(id=action.id),- ],- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.metrics = [metric.model_dump(mode="json")]- self._save_experiment_with_precomputation(experiment, use_precomputation)-- query_runner = ExperimentQueryRunner(- query=experiment_query,- team=self.team,- )- result = query_runner.calculate()-- assert result.variant_results is not None- self.assertEqual(len(result.variant_results), 1)-- control_variant = result.baseline- assert control_variant is not None- test_variant = result.variant_results[0]- assert test_variant is not None-- self.assertEqual(control_variant.sum, 8) # 8 successful funnels- self.assertEqual(control_variant.number_of_samples - control_variant.sum, 5) # 5 failures- self.assertEqual(test_variant.sum, 6) # 6 successful funnels- self.assertEqual(test_variant.number_of_samples - test_variant.sum, 7) # 7 failures-@parameterized.expand([("direct", False),diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_mean_metric.py b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_mean_metric.pyindex 40560c256719..6719807d8cc6 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_mean_metric.py+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_mean_metric.py@@ -973,102 +973,6 @@ class TestExperimentMeanMetric(ExperimentQueryRunnerBaseTest):self.assertEqual(test_variant.sum, 4)self.assertEqual(test_variant.number_of_samples, 2)- @parameterized.expand(- [- ("direct", False),- ("precomputed", True),- ]- )- @freeze_time("2024-01-01T12:00:00Z")- @snapshot_clickhouse_queries- def test_count_distinct_property_values_via_hogql(self, name, use_precomputation):- self._setup_precomputation_test(use_precomputation)-- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(feature_flag=feature_flag)- experiment.stats_config = {"method": "frequentist"}- experiment.save()-- ff_property = f"$feature/{feature_flag.key}"-- def _create_events_for_user(variant: str, categories: list[str]) -> list[dict]:- purchase_events = [- {- "event": "purchase",- "timestamp": f"2024-01-02T12:01:{i:02d}",- "properties": {- ff_property: variant,- "category": category,- },- }- for i, category in enumerate(categories)- ]- return [- {- "event": "$feature_flag_called",- "timestamp": "2024-01-02T12:00:00",- "properties": {- "$feature_flag_response": variant,- ff_property: variant,- "$feature_flag": feature_flag.key,- },- },- *purchase_events,- ]-- journeys_for(- {- # control_1: 3 events, 2 unique categories- "control_1": _create_events_for_user("control", ["electronics", "clothing", "electronics"]),- # control_2: 2 events, 2 unique categories- "control_2": _create_events_for_user("control", ["food", "clothing"]),- # control_3: exposed but no purchases → 0 unique categories- "control_3": _create_events_for_user("control", []),- # test_1: 4 events, 3 unique categories- "test_1": _create_events_for_user("test", ["electronics", "clothing", "food", "electronics"]),- # test_2: 3 events, 1 unique category- "test_2": _create_events_for_user("test", ["food", "food", "food"]),- },- self.team,- )-- flush_persons_and_events()-- metric = ExperimentMeanMetric(- source=EventsNode(- event="purchase",- math=ExperimentMetricMathType.HOGQL,- math_hogql="count(distinct properties.category)",- ),- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.metrics = [metric.model_dump(mode="json")]- self._save_experiment_with_precomputation(experiment, use_precomputation)-- query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)- result = cast(ExperimentQueryResponse, query_runner.calculate())-- assert result.baseline is not None- assert result.variant_results is not None- self.assertEqual(len(result.variant_results), 1)-- control_variant = result.baseline- test_variant = result.variant_results[0]-- # Same expected results as uniqExact test- # control_1: 2 unique, control_2: 2 unique, control_3: 0 unique → sum = 4- self.assertEqual(control_variant.sum, 4)- self.assertEqual(control_variant.number_of_samples, 3)- # test_1: 3 unique, test_2: 1 unique → sum = 4- self.assertEqual(test_variant.sum, 4)- self.assertEqual(test_variant.number_of_samples, 2)-@parameterized.expand([("direct", False),diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_ratio_metric.py b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_ratio_metric.pyindex 209b5a14cf4a..cba6b328126b 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_ratio_metric.py+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_ratio_metric.py@@ -1,6 +1,5 @@from typing import cast-import pytestfrom freezegun import freeze_timefrom posthog.test.base import _create_event, _create_person, flush_persons_and_events, snapshot_clickhouse_queries@@ -875,144 +874,6 @@ class TestExperimentRatioMetric(ExperimentQueryRunnerBaseTest):self.assertIsNotNone(control_variant.numerator_denominator_sum_product)self.assertIsNotNone(test_variant.numerator_denominator_sum_product)- # TODO: This is skipped as SQL expressions in ratio metrics are not supported yet- # We need to handle aggregations differently there compared to what we do i mean metrics.- @pytest.mark.skip- @freeze_time("2020-01-01T12:00:00Z")- @snapshot_clickhouse_queries- def test_ratio_metric_with_hogql_math_type(self):- """Test ratio metric with revenue per distinct user id with hogql expression"""- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(feature_flag=feature_flag)- experiment.save()-- # Create a ratio metric: total revenue / total purchase events- metric = ExperimentRatioMetric(- numerator=EventsNode(- event="purchase", math=ExperimentMetricMathType.HOGQL, math_hogql="sum(toFloat(properties.amount))"- ),- denominator=EventsNode(- event="purchase", math=ExperimentMetricMathType.HOGQL, math_hogql="uniqExact(distinct_id)"- ),- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.metrics = [metric.model_dump(mode="json")]- experiment.save()-- feature_flag_property = f"$feature/{feature_flag.key}"-- # Control group: 10 visitors, 6 make purchases with varying amounts- for i in range(10):- _create_person(distinct_ids=[f"user_control_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_control_{i}",- timestamp="2020-01-02T12:00:00Z",- properties={- feature_flag_property: "control",- "$feature_flag_response": "control",- "$feature_flag": feature_flag.key,- },- )-- # First 6 users make purchases- if i < 6:- # Some users make multiple purchases to test aggregation- if i < 3:- # Users 0,1,2 make single purchases of $10 each- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_control_{i}",- timestamp="2020-01-02T12:01:00Z",- properties={feature_flag_property: "control", "amount": 10},- )- else:- # Users 3,4,5 make two purchases each of $15- for j in range(2):- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_control_{i}",- timestamp=f"2020-01-02T12:0{j + 1}:00Z",- properties={feature_flag_property: "control", "amount": 15},- )-- # Test group: 10 visitors, 8 make purchases with varying amounts- for i in range(10):- _create_person(distinct_ids=[f"user_test_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_test_{i}",- timestamp="2020-01-02T12:00:00Z",- properties={- feature_flag_property: "test",- "$feature_flag_response": "test",- "$feature_flag": feature_flag.key,- },- )-- # First 8 users make purchases- if i < 8:- if i < 4:- # Users 0,1,2,3 make single purchases of $20 each- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_test_{i}",- timestamp="2020-01-02T12:01:00Z",- properties={feature_flag_property: "test", "amount": 20},- )- else:- # Users 4,5,6,7 make two purchases each of $10- for j in range(2):- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_test_{i}",- timestamp=f"2020-01-02T12:0{j + 1}:00Z",- properties={feature_flag_property: "test", "amount": 10},- )-- flush_persons_and_events()-- query_runner = ExperimentQueryRunner(query=experiment_query, team=self.team)- result = cast(ExperimentQueryResponse, query_runner.calculate())-- assert result.baseline is not None- assert result.variant_results is not None- self.assertEqual(len(result.variant_results), 1)-- control_variant = result.baseline- test_variant = result.variant_results[0]-- # Check main metric values (numerator - total revenue)- self.assertEqual(control_variant.sum, 120) # 3×$10 + 6×$15 = $30 + $90 = $120- self.assertEqual(test_variant.sum, 160) # 4×$20 + 8×$10 = $80 + $80 = $160- self.assertEqual(control_variant.number_of_samples, 10) # 10 visitors in total- self.assertEqual(test_variant.number_of_samples, 10) # 10 visitors in total-- # Check ratio-specific fields (denominator - number of distinct user id's)- self.assertEqual(control_variant.denominator_sum, 6) # 6 distinct users make a purchase- self.assertEqual(test_variant.denominator_sum, 8) # 8 distinct users make a purchase-- # Check denominator sum squares and main-denominator sum product exist- # (specific values depend on how purchase events are aggregated per user)- self.assertIsNotNone(control_variant.denominator_sum_squares)- self.assertIsNotNone(test_variant.denominator_sum_squares)-- # Check main-denominator sum product- self.assertIsNotNone(control_variant.numerator_denominator_sum_product)- self.assertIsNotNone(test_variant.numerator_denominator_sum_product)-@parameterized.expand([("direct", False),diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_retention_metric.py b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_retention_metric.pyindex ed33a6e93e55..2c6ea7e5e87f 100644--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_retention_metric.py+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/test_retention_metric.py@@ -1454,170 +1454,6 @@ class TestExperimentRetentionMetric(ExperimentQueryRunnerBaseTest):self.assertEqual(test_variant.denominator_sum_squares, 3)self.assertEqual(test_variant.numerator_denominator_sum_product, 2)- @parameterized.expand([("disable_new_query_builder", False), ("enable_new_query_builder", True)])- @freeze_time("2020-01-01T12:00:00Z")- @snapshot_clickhouse_queries- def test_retention_same_start_and_end_window(self, name, use_new_query_builder):- """- Test that retention window [N, N] captures events exactly on day N.- This validates the fix for the half-open interval bug where [7,7] previously gave 0 results.-- User feedback: "I had to do [7,8] to capture events at exactly 7 days (10080 mins)"- Fix: Changed query from < to <= to make interval closed [start, end] instead of half-open [start, end)- """- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(feature_flag=feature_flag)- experiment.stats_config = {"method": "frequentist", "use_new_query_builder": use_new_query_builder}- experiment.save()-- # Create a retention metric with [7, 7] window (same start and end)- # This should capture events that happen exactly on day 7- metric = ExperimentRetentionMetric(- start_event=EventsNode(- event="signup",- math=ExperimentMetricMathType.TOTAL,- ),- completion_event=EventsNode(- event="login",- math=ExperimentMetricMathType.TOTAL,- ),- retention_window_start=7,- retention_window_end=7, # Same as start - should capture only day 7- retention_window_unit=FunnelConversionWindowTimeUnit.DAY,- start_handling=StartHandling.FIRST_SEEN,- )-- experiment_query = ExperimentQuery(- experiment_id=experiment.id,- kind="ExperimentQuery",- metric=metric,- )-- experiment.metrics = [metric.model_dump(mode="json")]- experiment.save()-- feature_flag_property = f"$feature/{feature_flag.key}"-- # Control group: 4 users sign up, 2 return exactly on day 7- for i in range(4):- _create_person(distinct_ids=[f"user_control_{i}"], team_id=self.team.pk)-- # Exposure event- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_control_{i}",- timestamp="2020-01-02T12:00:00Z",- properties={- feature_flag_property: "control",- "$feature_flag_response": "control",- "$feature_flag": feature_flag.key,- },- )-- # All 4 users sign up- _create_event(- team=self.team,- event="signup",- distinct_id=f"user_control_{i}",- timestamp="2020-01-02T12:01:00Z",- properties={feature_flag_property: "control"},- )-- # Users 0 and 1 return exactly on day 7 (should be captured by [7,7])- if i < 2:- _create_event(- team=self.team,- event="login",- distinct_id=f"user_control_{i}",- timestamp="2020-01-09T12:01:00Z", # Exactly 7 days later- properties={feature_flag_property: "control"},- )-- # User 2 returns on day 6 (should NOT be captured by [7,7])- elif i == 2:- _create_event(- team=self.team,- event="login",- distinct_id=f"user_control_{i}",- timestamp="2020-01-08T12:01:00Z", # 6 days later- properties={feature_flag_property: "control"},- )-- # User 3 returns on day 8 (should NOT be captured by [7,7])- elif i == 3:- _create_event(- team=self.team,- event="login",- distinct_id=f"user_control_{i}",- timestamp="2020-01-10T12:01:00Z", # 8 days later- properties={feature_flag_property: "control"},- )-- # Test group: 3 users sign up, all 3 return exactly on day 7- for i in range(3):- _create_person(distinct_ids=[f"user_test_{i}"], team_id=self.team.pk)-- # Exposure event- _create_event(- team=self.team,- event="$feature_flag_called",- distinct_id=f"user_test_{i}",- timestamp="2020-01-02T12:00:00Z",- properties={- feature_flag_property: "test",- "$feature_flag_response": "test",- "$feature_flag": feature_flag.key,- },- )-- # All 3 users sign up- _create_event(- team=self.team,- event="signup",- distinct_id=f"user_test_{i}",- timestamp="2020-01-02T12:01:00Z",- properties={feature_flag_property: "test"},- )-- # All 3 users return exactly on day 7- _create_event(- team=self.team,- event="login",- distinct_id=f"user_test_{i}",- timestamp="2020-01-09T12:01:00Z", # Exactly 7 days later- properties={feature_flag_property: "test"},- )-- flush_persons_and_events()-- runner = ExperimentQueryRunner(query=experiment_query, team=self.team)- result = runner.calculate()-- assert isinstance(result, ExperimentQueryResponse)- assert result.baseline is not None- assert result.variant_results is not None- assert len(result.variant_results) == 1-- control_variant = result.baseline- test_variant = result.variant_results[0]-- # Control: 4 started, 2 retained (50% - only those on exactly day 7)- self.assertEqual(control_variant.number_of_samples, 4)- self.assertEqual(control_variant.sum, 2)-- # Test: 3 started, 3 retained (100% - all on exactly day 7)- self.assertEqual(test_variant.number_of_samples, 3)- self.assertEqual(test_variant.sum, 3)-- # Verify ratio-specific fields- self.assertEqual(control_variant.denominator_sum, 4)- self.assertEqual(control_variant.denominator_sum_squares, 4)- self.assertEqual(control_variant.numerator_denominator_sum_product, 2)- self.assertEqual(test_variant.denominator_sum, 3)- self.assertEqual(test_variant.denominator_sum_squares, 3)- self.assertEqual(test_variant.numerator_denominator_sum_product, 3)-@parameterized.expand([("direct", False),diff --git a/products/experiments/backend/hogql_queries/test/test_dw_funnel_integration.py b/products/experiments/backend/hogql_queries/test/test_dw_funnel_integration.pydeleted file mode 100644index c94c4caf4820..000000000000--- a/products/experiments/backend/hogql_queries/test/test_dw_funnel_integration.py+++ /dev/null@@ -1,170 +0,0 @@-"""-Integration tests for datawarehouse funnel metrics.--Tests DW funnel validation with comprehensive edge cases.-Query builder tests are in test_funnel_validation.py.-"""--import pytest--from rest_framework.exceptions import ValidationError--from posthog.schema import EventsNode, ExperimentDataWarehouseNode, ExperimentFunnelMetric, StepOrderValue--from products.experiments.backend.hogql_queries.funnel_validation import FunnelDWValidator---class TestFunnelDWValidation:- """Test FunnelDWValidator validation logic."""-- def test_valid_funnel_with_dw_step(self):- """Valid funnel with DW step should not raise."""- metric = ExperimentFunnelMetric(- series=[- EventsNode(event="pageview"),- ExperimentDataWarehouseNode(- table_name="revenue",- timestamp_field="purchase_date",- data_warehouse_join_key="user_id",- events_join_key="properties.$user_id",- ),- ],- funnel_order_type=StepOrderValue.ORDERED,- )-- FunnelDWValidator.validate_funnel_metric(metric)-- def test_valid_funnel_without_dw_steps(self):- """Funnel without DW steps should skip validation."""- metric = ExperimentFunnelMetric(- series=[- EventsNode(event="pageview"),- EventsNode(event="purchase"),- ],- funnel_order_type=StepOrderValue.ORDERED,- )-- FunnelDWValidator.validate_funnel_metric(metric)-- @pytest.mark.parametrize(- "missing_field,expected_error",- [- ("table_name", "table_name is required"),- ("timestamp_field", "timestamp_field is required"),- ("data_warehouse_join_key", "data_warehouse_join_key is required"),- ("events_join_key", "events_join_key is required"),- ],- )- def test_missing_required_field(self, missing_field, expected_error):- """Missing required field should raise ValidationError with appropriate message."""- fields = {- "table_name": "revenue",- "timestamp_field": "purchase_date",- "data_warehouse_join_key": "user_id",- "events_join_key": "properties.$user_id",- }- # Blank out the missing field- fields[missing_field] = ""-- metric = ExperimentFunnelMetric(- series=[- EventsNode(event="pageview"),- ExperimentDataWarehouseNode(**fields),- ],- funnel_order_type=StepOrderValue.ORDERED,- )-- with pytest.raises(ValidationError) as exc_info:- FunnelDWValidator.validate_funnel_metric(metric)- assert expected_error in str(exc_info.value)-- def test_inconsistent_join_keys(self):- """Different events_join_keys should raise ValueError."""- metric = ExperimentFunnelMetric(- series=[- EventsNode(event="pageview"),- ExperimentDataWarehouseNode(- table_name="revenue",- timestamp_field="purchase_date",- data_warehouse_join_key="user_id",- events_join_key="properties.$user_id", # First join key- ),- ExperimentDataWarehouseNode(- table_name="subscriptions",- timestamp_field="subscribed_at",- data_warehouse_join_key="customer_email",- events_join_key="properties.$email", # Different join key- ),- ],- funnel_order_type=StepOrderValue.ORDERED,- )-- with pytest.raises(ValidationError) as exc_info:- FunnelDWValidator.validate_funnel_metric(metric)- assert "same join key" in str(exc_info.value)-- def test_too_many_dw_steps(self):- """Exceeding MAX_DW_STEPS should raise ValidationError."""- dw_steps = [- ExperimentDataWarehouseNode(- table_name=f"table_{i}",- timestamp_field="ts",- data_warehouse_join_key="user_id",- events_join_key="properties.$user_id",- )- for i in range(FunnelDWValidator.MAX_DW_STEPS + 1)- ]-- metric = ExperimentFunnelMetric(- series=dw_steps,- funnel_order_type=StepOrderValue.ORDERED,- )-- with pytest.raises(ValidationError) as exc_info:- FunnelDWValidator.validate_funnel_metric(metric)- assert "Too many datawarehouse steps" in str(exc_info.value)-- def test_too_many_distinct_tables(self):- """Exceeding MAX_DISTINCT_DW_TABLES should raise ValidationError."""- dw_steps = [- ExperimentDataWarehouseNode(- table_name=f"table_{i}", # Different table for each step- timestamp_field="ts",- data_warehouse_join_key="user_id",- events_join_key="properties.$user_id",- )- for i in range(FunnelDWValidator.MAX_DISTINCT_DW_TABLES + 1)- ]-- metric = ExperimentFunnelMetric(- series=dw_steps,- funnel_order_type=StepOrderValue.ORDERED,- )-- with pytest.raises(ValidationError) as exc_info:- FunnelDWValidator.validate_funnel_metric(metric)- assert "Too many distinct datawarehouse tables" in str(exc_info.value)-- def test_multiple_errors_reported(self):- """Multiple missing fields should all be reported in error message."""- metric = ExperimentFunnelMetric(- series=[- EventsNode(event="pageview"),- ExperimentDataWarehouseNode(- table_name="", # Missing- timestamp_field="", # Missing- data_warehouse_join_key="", # Missing- events_join_key="", # Missing- ),- ],- funnel_order_type=StepOrderValue.ORDERED,- )-- with pytest.raises(ValidationError) as exc_info:- FunnelDWValidator.validate_funnel_metric(metric)-- error_msg = str(exc_info.value)- assert "table_name is required" in error_msg- assert "timestamp_field is required" in error_msg- assert "data_warehouse_join_key is required" in error_msg- assert "events_join_key is required" in error_msgdiff --git a/products/experiments/backend/hogql_queries/test/test_experiment_funnels_query_runner.py b/products/experiments/backend/hogql_queries/test/test_experiment_funnels_query_runner.pyindex ccacf3845ac0..9d3536610817 100644--- a/products/experiments/backend/hogql_queries/test/test_experiment_funnels_query_runner.py+++ b/products/experiments/backend/hogql_queries/test/test_experiment_funnels_query_runner.py@@ -186,75 +186,6 @@ class TestExperimentFunnelsQueryRunner(ClickhouseTestMixin, APIBaseTest):self.assertAlmostEqual(result.credible_intervals["test"][0], 0.5, delta=0.1)self.assertAlmostEqual(result.credible_intervals["test"][1], 0.9, delta=0.1)- @freeze_time("2020-01-01T12:00:00Z")- def test_query_runner_v2(self):- feature_flag = self.create_feature_flag()- experiment = self.create_experiment(feature_flag=feature_flag)- experiment.save()-- feature_flag_property = f"$feature/{feature_flag.key}"-- funnels_query = FunnelsQuery(- series=[EventsNode(event="$pageview"), EventsNode(event="purchase")],- dateRange={"date_from": "2020-01-01", "date_to": "2020-01-14"},- )- experiment_query = ExperimentFunnelsQuery(- experiment_id=experiment.id,- kind="ExperimentFunnelsQuery",- funnels_query=funnels_query,- )-- experiment.metrics = [{"type": "primary", "query": experiment_query.model_dump()}]- experiment.save()-- for variant, purchase_count in [("control", 6), ("test", 8)]:- for i in range(10):- _create_person(distinct_ids=[f"user_{variant}_{i}"], team_id=self.team.pk)- _create_event(- team=self.team,- event="$pageview",- distinct_id=f"user_{variant}_{i}",- timestamp="2020-01-02T12:00:00Z",- properties={feature_flag_property: variant},- )- if i < purchase_count:- _create_event(- team=self.team,- event="purchase",- distinct_id=f"user_{variant}_{i}",- timestamp="2020-01-02T12:01:00Z",- properties={feature_flag_property: variant},- )-- flush_persons_and_events()-- query_runner = ExperimentFunnelsQueryRunner(- query=ExperimentFunnelsQuery(**experiment.metrics[0]["query"]), team=self.team- )- result = query_runner.calculate()-- self.assertEqual(len(result.variants), 2)-- control_variant = next(variant for variant in result.variants if variant.key == "control")- test_variant = next(variant for variant in result.variants if variant.key == "test")-- self.assertEqual(control_variant.success_count, 6)- self.assertEqual(control_variant.failure_count, 4)- self.assertEqual(test_variant.success_count, 8)- self.assertEqual(test_variant.failure_count, 2)-- self.assertAlmostEqual(result.probability["control"], 0.2, delta=0.1)- self.assertAlmostEqual(result.probability["test"], 0.8, delta=0.1)-- self.assertEqual(result.significant, False)- self.assertEqual(result.significance_code, ExperimentSignificanceCode.NOT_ENOUGH_EXPOSURE)- self.assertEqual(result.expected_loss, 1.0)-- self.assertAlmostEqual(result.credible_intervals["control"][0], 0.3, delta=0.1)- self.assertAlmostEqual(result.credible_intervals["control"][1], 0.8, delta=0.1)- self.assertAlmostEqual(result.credible_intervals["test"][0], 0.5, delta=0.1)- self.assertAlmostEqual(result.credible_intervals["test"][1], 0.9, delta=0.1)-@pytest.mark.flaky(reruns=9)@freeze_time("2020-01-01T12:00:00Z")def test_query_runner_standard_flow(self):diff --git a/products/experiments/backend/hogql_queries/test/test_funnel_step_builder_integration.py b/products/experiments/backend/hogql_queries/test/test_funnel_step_builder_integration.pyindex 2de4e29f7728..41f807409bff 100644--- a/products/experiments/backend/hogql_queries/test/test_funnel_step_builder_integration.py+++ b/products/experiments/backend/hogql_queries/test/test_funnel_step_builder_integration.py@@ -18,61 +18,6 @@ from products.experiments.backend.hogql_queries.funnel_step_builder import Funneclass TestFunnelStepBuilderIntegration(BaseTest):"""Test FunnelStepBuilder integration with experiment queries."""- def test_boolean_columns_integration(self):- """Test that boolean columns are generated correctly for integration."""- series: list[EventsNode | ActionsNode | ExperimentDataWarehouseNode] = [- EventsNode(event="pageview"),- EventsNode(event="purchase"),- ]-- builder = FunnelStepBuilder(series, self.team)- exposure_filter = parse_expr("event = '$feature_flag_called'")-- # Generate boolean columns- columns = builder.build_boolean_columns(exposure_filter)-- # Verify we got the right number of columns- assert len(columns) == 3 # step_0 + 2 metric steps-- # Verify they're all ast.Alias nodes (ready for SELECT clause)- for col in columns:- assert isinstance(col, ast.Alias)- assert col.alias.startswith("step_")-- def test_constant_columns_integration(self):- """Test that constant columns are generated correctly for UNION ALL queries."""- series: list[EventsNode | ActionsNode | ExperimentDataWarehouseNode] = [- EventsNode(event="pageview"),- ExperimentDataWarehouseNode(- table_name="revenue",- timestamp_field="ds",- data_warehouse_join_key="user_id",- events_join_key="properties.$user_id",- ),- ]-- builder = FunnelStepBuilder(series, self.team)-- # Generate constant columns for exposure step- exposure_columns = builder.build_constant_columns(active_step_index=0)- assert len(exposure_columns) == 3- assert isinstance(exposure_columns[0].expr, ast.Constant)- assert exposure_columns[0].expr.value == 1 # step_0 active- assert isinstance(exposure_columns[1].expr, ast.Constant)- assert exposure_columns[1].expr.value == 0- assert isinstance(exposure_columns[2].expr, ast.Constant)- assert exposure_columns[2].expr.value == 0-- # Generate constant columns for DW step (step 2)- dw_columns = builder.build_constant_columns(active_step_index=2)- assert len(dw_columns) == 3- assert isinstance(dw_columns[0].expr, ast.Constant)- assert dw_columns[0].expr.value == 0- assert isinstance(dw_columns[1].expr, ast.Constant)- assert dw_columns[1].expr.value == 0- assert isinstance(dw_columns[2].expr, ast.Constant)- assert dw_columns[2].expr.value == 1 # step_2 active-def test_mixed_node_types_integration(self):"""Test that FunnelStepBuilder handles mixed EventsNode and ActionsNode."""# Create an action first@@ -115,25 +60,3 @@ class TestFunnelStepBuilderIntegration(BaseTest):assert len(metric.series) == 2assert isinstance(metric.series[0], EventsNode)assert isinstance(metric.series[1], ExperimentDataWarehouseNode)-- def test_datawarehouse_node_rejected_in_boolean_mode(self):- """Verify DW nodes are properly rejected when building boolean columns."""- series: list[EventsNode | ActionsNode | ExperimentDataWarehouseNode] = [- EventsNode(event="pageview"),- ExperimentDataWarehouseNode(- table_name="revenue",- timestamp_field="ds",- data_warehouse_join_key="user_id",- events_join_key="properties.$user_id",- ),- ]-- builder = FunnelStepBuilder(series, self.team)- exposure_filter = parse_expr("event = '$feature_flag_called'")-- # Should raise ValueError when trying to build boolean columns with DW node- with self.assertRaises(ValueError) as context:- builder.build_boolean_columns(exposure_filter)-- assert "Cannot build boolean filter" in str(context.exception)- assert "ExperimentDataWarehouseNode" in str(context.exception)diff --git a/products/experiments/backend/hogql_queries/test/test_hogql_aggregation_integration.py b/products/experiments/backend/hogql_queries/test/test_hogql_aggregation_integration.pyindex 960b241a0a46..ccd69b88b46e 100644--- a/products/experiments/backend/hogql_queries/test/test_hogql_aggregation_integration.py+++ b/products/experiments/backend/hogql_queries/test/test_hogql_aggregation_integration.py@@ -5,7 +5,6 @@ from posthog.schema import EventsNode, ExperimentMeanMetric, ExperimentMetricMatfrom posthog.hogql import astfrom products.experiments.backend.hogql_queries.base_query_utils import get_metric_value-from products.experiments.backend.hogql_queries.hogql_aggregation_utils import extract_aggregation_and_inner_exprclass TestHogQLAggregationIntegration(BaseTest):@@ -39,29 +38,3 @@ class TestHogQLAggregationIntegration(BaseTest):# Should return the field expression directlyself.assertIsInstance(result_no_agg, ast.Field)self.assertEqual(result_no_agg.chain, ["properties", "revenue"]) # type: ignore[attr-defined]-- def test_hogql_aggregation_examples(self):- """Test various HogQL aggregation examples that users might input."""-- test_cases = [- # (input_expression, expected_aggregation, description)- ("sum(properties.revenue - properties.expense)", "sum", "Revenue minus expense"),- ("avg(properties.price * properties.quantity)", "avg", "Average of price times quantity"),- ("count(distinct properties.user_id)", "count", "Distinct user count"),- ("min(properties.score)", "min", "Minimum score"),- ("max(toFloat(properties.value))", "max", "Maximum converted value"),- ("properties.simple_value", None, "Simple property access"),- ("properties.a + properties.b", None, "Simple arithmetic"),- ]-- for expr_str, expected_agg, description in test_cases:- with self.subTest(expression=expr_str, description=description):- aggregation, inner_expr, _, _ = extract_aggregation_and_inner_expr(expr_str)-- if expected_agg is None:- self.assertIsNone(aggregation, f"Expected no aggregation for: {expr_str}")- else:- self.assertEqual(aggregation, expected_agg, f"Wrong aggregation for: {expr_str}")-- # Inner expression should never be None- self.assertIsNotNone(inner_expr, f"Inner expression should not be None for: {expr_str}")diff --git a/products/experiments/backend/temporal/test_models.py b/products/experiments/backend/temporal/test_models.pydeleted file mode 100644index 8540b5822d07..000000000000--- a/products/experiments/backend/temporal/test_models.py+++ /dev/null@@ -1,34 +0,0 @@-from products.experiments.backend.temporal.models import (- ExperimentMetricsRecalculationWorkflowInputs,- ExperimentMetricToRecalculate,- MetricRecalculationResult,- RecalculationProgressUpdate,-)---def test_workflow_inputs_holds_recalculation_id():- inputs = ExperimentMetricsRecalculationWorkflowInputs(recalculation_id="abc")- assert inputs.recalculation_id == "abc"---def test_metric_to_recalculate_fields():- metric = ExperimentMetricToRecalculate(experiment_id=1, metric_uuid="u", metric_type="primary")- assert metric.experiment_id == 1- assert metric.metric_uuid == "u"- assert metric.metric_type == "primary"---def test_result_defaults():- result = MetricRecalculationResult(metric_uuid="u", success=True)- assert result.success is True- assert result.error_step is None- assert result.error_message is None---def test_progress_update_defaults():- update = RecalculationProgressUpdate(recalculation_id="abc")- assert update.status is None- assert update.total_metrics is None- assert update.metric_uuids is None- assert update.mark_started is False- assert update.mark_completed is Falsediff --git a/products/experiments/backend/temporal/test_recalculation_metrics.py b/products/experiments/backend/temporal/test_recalculation_metrics.pyindex 03d9bdfe1d2c..c6d86481d4af 100644--- a/products/experiments/backend/temporal/test_recalculation_metrics.py+++ b/products/experiments/backend/temporal/test_recalculation_metrics.py@@ -24,17 +24,6 @@ def test_registered_on_general_purpose_queue():assert is_task_queue_supported(settings.GENERAL_PURPOSE_TASK_QUEUE, ExperimentsRecalculationMetricsInterceptor)-def test_metric_names_defined():- assert (- "experiment_metrics_recalculation_activity_execution_latency"- in EXPERIMENT_METRICS_RECALCULATION_LATENCY_HISTOGRAM_METRICS- )- assert (- "experiment_metrics_recalculation_workflow_execution_latency"- in EXPERIMENT_METRICS_RECALCULATION_LATENCY_HISTOGRAM_METRICS- )--def test_buckets_sorted_ascending_and_floats():buckets = EXPERIMENT_METRICS_RECALCULATION_LATENCY_HISTOGRAM_BUCKETSassert buckets == sorted(buckets)diff --git a/products/experiments/backend/test/test_api.py b/products/experiments/backend/test/test_api.pydeleted file mode 100644index 64fc1576233f..000000000000--- a/products/experiments/backend/test/test_api.py+++ /dev/null@@ -1,122 +0,0 @@-"""-Tests for experiment facade API.--These tests verify that the facade correctly wraps the existing-ExperimentService and converts between Django models and DTOs.--NOTE: Tests for feature_flag_filters format were removed in PR #4-to keep the facade simple. Only the parameters format is tested here.-"""--import pytest-from posthog.test.base import BaseTest-from unittest.mock import patch--from products.experiments.backend.facade.api import create_experiment-from products.experiments.backend.facade.contracts import CreateExperimentInput, Experiment-from products.experiments.backend.models.experiment import Experiment as ExperimentModel-from products.feature_flags.backend.models.feature_flag import FeatureFlag as FeatureFlagModel---class TestCreateExperiment(BaseTest):- def test_create_experiment_with_parameters_format(self):- """Test creating experiment using parameters format."""- input_dto = CreateExperimentInput(- name="Test Experiment",- feature_flag_key="test-flag",- parameters={- "feature_flag_variants": [- {"key": "control", "name": "Control", "rollout_percentage": 50},- {"key": "test", "name": "Test", "rollout_percentage": 50},- ]- },- )-- result = create_experiment(team=self.team, user=self.user, input_dto=input_dto)-- # Verify output DTO structure- assert isinstance(result, Experiment)- assert result.name == "Test Experiment"- assert result.feature_flag_key == "test-flag"- assert result.is_draft is True-- # Verify database objects were created- experiment = ExperimentModel.objects.get(id=result.id)- assert experiment.name == "Test Experiment"- assert experiment.feature_flag.key == "test-flag"-- # Verify feature flag created- flag = FeatureFlagModel.objects.get(id=result.feature_flag_id)- assert flag.name == "Feature Flag for Experiment Test Experiment"- assert len(flag.filters["multivariate"]["variants"]) == 2-- def test_create_experiment_with_existing_flag(self):- """Test creating experiment with existing feature flag."""- # Create flag first- existing_flag = FeatureFlagModel.objects.create(- team=self.team,- created_by=self.user,- key="existing-flag",- filters={- "groups": [{"properties": [], "rollout_percentage": 100}],- "multivariate": {- "variants": [- {"key": "control", "rollout_percentage": 50},- {"key": "test", "rollout_percentage": 50},- ]- },- },- )-- input_dto = CreateExperimentInput(- name="Existing Flag Experiment",- feature_flag_key="existing-flag",- )-- result = create_experiment(team=self.team, user=self.user, input_dto=input_dto)-- assert result.feature_flag_id == existing_flag.id- assert result.feature_flag_key == "existing-flag"-- def test_create_experiment_is_transactional(self):- """Test that experiment creation is transactional."""- # Patch Experiment.objects.create to fail after flag creation- with patch("products.experiments.backend.models.experiment.Experiment.objects.create") as mock_create:- mock_create.side_effect = Exception("Experiment creation failed")-- input_dto = CreateExperimentInput(- name="Transactional Test",- feature_flag_key="transaction-flag",- parameters={"feature_flag_variants": [{"key": "control", "rollout_percentage": 100}]},- )-- with pytest.raises(Exception, match="Experiment creation failed"):- create_experiment(team=self.team, user=self.user, input_dto=input_dto)-- # Verify rollback - flag should not exist despite being created first- assert not FeatureFlagModel.objects.filter(key="transaction-flag").exists()- assert not ExperimentModel.objects.filter(name="Transactional Test").exists()-- def test_output_dto_immutability(self):- """Test that returned DTO is immutable."""- input_dto = CreateExperimentInput(- name="Immutable Test",- feature_flag_key="immutable-flag",- parameters={"feature_flag_variants": [{"key": "control", "rollout_percentage": 100}]},- )-- result = create_experiment(team=self.team, user=self.user, input_dto=input_dto)-- with pytest.raises(AttributeError):- result.name = "Modified" # type: ignore-- def test_output_dto_hashability(self):- """Test that returned DTO is hashable."""- input_dto = CreateExperimentInput(- name="Hashable Test",- feature_flag_key="hashable-flag",- parameters={"feature_flag_variants": [{"key": "control", "rollout_percentage": 100}]},- )-- result = create_experiment(team=self.team, user=self.user, input_dto=input_dto)- assert hash(result) is not Nonediff --git a/products/experiments/backend/test/test_experiment_service.py b/products/experiments/backend/test/test_experiment_service.pyindex 1344b6db0799..2e239855f1cc 100644--- a/products/experiments/backend/test/test_experiment_service.py+++ b/products/experiments/backend/test/test_experiment_service.py@@ -138,15 +138,6 @@ class TestExperimentService(APIBaseTest):# Stats config defaults# ------------------------------------------------------------------- def test_stats_config_defaults_bayesian(self):- self._create_flag(key="stats-test")- service = self._service()-- experiment = service.create_experiment(name="Stats Test", feature_flag_key="stats-test")-- assert experiment.stats_config is not None- assert experiment.stats_config["method"] == "bayesian"-def test_stats_config_defaults_from_team(self):config = get_or_create_team_extension(self.team, TeamExperimentsConfig)config.default_experiment_stats_method = "frequentist"@@ -259,14 +250,6 @@ class TestExperimentService(APIBaseTest):assert isinstance(experiment.metrics[0]["fingerprint"], str)assert len(experiment.metrics[0]["fingerprint"]) == 64 # SHA256 hex- def test_no_fingerprints_when_no_metrics(self):- self._create_flag(key="no-metrics")- service = self._service()-- experiment = service.create_experiment(name="No Metrics", feature_flag_key="no-metrics")-- assert experiment.metrics == []-# ------------------------------------------------------------------# Metric ordering# ------------------------------------------------------------------@@ -920,40 +903,6 @@ class TestExperimentService(APIBaseTest):# Service contract fields# ------------------------------------------------------------------- def test_description_and_type_passed_through(self):- self._create_flag(key="passthrough")- service = self._service()-- experiment = service.create_experiment(- name="Passthrough Test",- feature_flag_key="passthrough",- description="A description",- type="web",- )-- assert experiment.description == "A description"- assert experiment.type == "web"-- def test_parameters_passed_through(self):- self._create_flag(key="params-test")- service = self._service()-- params = {- "feature_flag_variants": [- {"key": "control", "name": "Control", "rollout_percentage": 50},- {"key": "test", "name": "Test", "rollout_percentage": 50},- ],- "minimum_detectable_effect": 30,- }-- experiment = service.create_experiment(- name="Params Test",- feature_flag_key="params-test",- parameters=params,- )-- assert experiment.parameters == params-def test_create_experiment_with_all_fields(self):service = self._service()now = timezone.now()@@ -1145,19 +1094,6 @@ class TestExperimentService(APIBaseTest):experiment.refresh_from_db()assert experiment.status == "running"- def test_create_experiment_with_unknown_field_raises_type_error(self):- self._create_flag(key="unknown-key-flag")- service = self._service()-- with self.assertRaises(TypeError) as ctx:- service.create_experiment(- name="Unknown Key",- feature_flag_key="unknown-key-flag",- unknown_field="boom", # type: ignore[call-arg]- )-- assert "unexpected keyword argument 'unknown_field'" in str(ctx.exception)-# ------------------------------------------------------------------# Update experiment# ------------------------------------------------------------------