Skip to content

Commit

Permalink
fix(experiments): Allow standard trends query on data warehouse (Post…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber authored Feb 1, 2025
1 parent 3b67c71 commit 9f4e941
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,43 @@ def test_trends_breakdown_with_event_property(self):
assert response.results[3][1] == [0, 0, 0, 1, 0, 0, 0]
assert response.results[3][2] == "d"

def test_trends_breakdown_with_events_join_experiments_optimized(self):
table_name = self.create_parquet_file()

DataWarehouseJoin.objects.create(
team=self.team,
source_table_name=table_name,
source_table_key="prop_1",
joining_table_name="events",
joining_table_key="distinct_id",
field_name="events",
configuration={"experiments_optimized": True, "experiments_timestamp_key": "created"},
)

trends_query = TrendsQuery(
kind="TrendsQuery",
dateRange=DateRange(date_from="2023-01-01"),
series=[
DataWarehouseNode(
id=table_name,
table_name=table_name,
id_field="id",
distinct_id_field="prop_1",
timestamp_field="created",
)
],
filterTestAccounts=True,
interval="day",
trendsFilter=TrendsFilter(display=ChartDisplayType.ACTIONS_LINE_GRAPH),
)

with freeze_time("2023-01-07"):
response = self.get_response(trends_query=trends_query)

assert response.columns is not None
assert set(response.columns).issubset({"date", "total"})
assert response.results[0][1] == [1, 1, 1, 1, 0, 0, 0]

@snapshot_clickhouse_queries
def test_trends_breakdown_on_view(self):
from posthog.warehouse.models import DataWarehouseSavedQuery
Expand Down
1 change: 1 addition & 0 deletions posthog/warehouse/models/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def _join_function_for_experiments(
)
for name, chain in {
**join_to_add.fields_accessed,
"event": ["event"],
"timestamp": ["timestamp"],
"distinct_id": ["distinct_id"],
"properties": ["properties"],
Expand Down

0 comments on commit 9f4e941

Please sign in to comment.