From de82d67def6fbf7c8f7c69a0540174600ba130fc Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 4 Dec 2024 14:02:09 -0800 Subject: [PATCH] Add a test describing payments -> persons -> events --- .../test_experiment_trends_query_runner.py | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/posthog/hogql_queries/experiments/test/test_experiment_trends_query_runner.py b/posthog/hogql_queries/experiments/test/test_experiment_trends_query_runner.py index 8837bfeab8607..bf88cfab44f0c 100644 --- a/posthog/hogql_queries/experiments/test/test_experiment_trends_query_runner.py +++ b/posthog/hogql_queries/experiments/test/test_experiment_trends_query_runner.py @@ -17,7 +17,7 @@ OBJECT_STORAGE_SECRET_ACCESS_KEY, XDIST_SUFFIX, ) -from posthog.test.base import APIBaseTest, ClickhouseTestMixin, _create_event, flush_persons_and_events +from posthog.test.base import APIBaseTest, ClickhouseTestMixin, _create_event, _create_person, flush_persons_and_events from freezegun import freeze_time from typing import cast from django.utils import timezone @@ -135,12 +135,20 @@ def create_data_warehouse_table_with_payments(self): datetime(2023, 1, 7), ] ) - distinct_id = pa.array(["user_control_0", "user_test_1", "user_test_2", "user_test_3", "user_extra"]) + email = pa.array( + [ + "user_control_0@example.com", + "user_test_1@example.com", + "user_test_2@example.com", + "user_test_3@example.com", + "user_extra@example.com", + ] + ) amount = pa.array([100, 50, 75, 80, 90]) - names = ["id", "dw_timestamp", "dw_distinct_id", "amount"] + names = ["id", "dw_timestamp", "dw_email", "amount"] pq.write_to_dataset( - pa.Table.from_arrays([id, timestamp, distinct_id, amount], names=names), + pa.Table.from_arrays([id, timestamp, email, amount], names=names), path_to_s3_object, filesystem=fs, use_dictionary=True, @@ -164,7 +172,7 @@ def create_data_warehouse_table_with_payments(self): columns={ "id": "String", "dw_timestamp": "DateTime64(3, 'UTC')", - "dw_distinct_id": "String", + "dw_email": "String", "amount": "Int64", }, credential=credential, @@ -173,7 +181,16 @@ def create_data_warehouse_table_with_payments(self): DataWarehouseJoin.objects.create( team=self.team, source_table_name=table_name, - source_table_key="dw_distinct_id", + source_table_key="dw_email", + joining_table_name="persons", + joining_table_key="properties.email", + field_name="persons", + ) + + DataWarehouseJoin.objects.create( + team=self.team, + source_table_name="persons", + source_table_key="id", joining_table_name="events", joining_table_key="distinct_id", field_name="events", @@ -504,7 +521,7 @@ def test_query_runner_with_data_warehouse_series(self): series=[ DataWarehouseNode( id=table_name, - distinct_id_field="dw_distinct_id", + distinct_id_field="persons.id", id_field="id", table_name=table_name, timestamp_field="dw_timestamp", @@ -533,6 +550,11 @@ def test_query_runner_with_data_warehouse_series(self): properties={feature_flag_property: variant}, timestamp=datetime(2023, 1, i + 1), ) + _create_person( + team=self.team, + distinct_ids=[f"user_{variant}_{i}"], + properties={"email": f"user_{variant}_{i}@example.com"}, + ) # "user_test_3" first exposure (feature_flag_property="control") is on 2023-01-03 # "user_test_3" relevant exposure (feature_flag_property="test") is on 2023-01-04