: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(persons): retire the legacy properties timeline filter (#119597)
Thomas Obermüllerc7c382e48342
diff --git a/posthog/api/person.py b/posthog/api/person.pyindex 983f47096324..7a9e39ac2e4e 100644--- a/posthog/api/person.py+++ b/posthog/api/person.py@@ -57,7 +57,6 @@ from posthog.models import Person, Team, Userfrom posthog.models.activity_logging.activity_log import Change, Detail, load_activity, log_activityfrom posthog.models.activity_logging.activity_page import activity_page_response, parse_activity_page_paramsfrom posthog.models.async_deletion import AsyncDeletion, DeletionType-from posthog.models.filters.properties_timeline_filter import PropertiesTimelineFilterfrom posthog.models.person.bulk_delete import (delete_persons_profile,queue_person_event_deletion,@@ -1710,18 +1709,9 @@ class PersonViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):)# PRAGMA: Methods for getting Persons via clickhouse queries- @extend_schema(- methods=["GET"],- deprecated=True,- parameters=[_PERSON_ID_PARAMETER],- responses={200: PropertiesTimelineResponseSerializer},- summary="Get a person's properties timeline from legacy filter parameters",- description="Reads a legacy insight filter from the query string. Send a POST with the data point's actors query instead.",- )- @extend_schema(- methods=["POST"],+ @validated_request(+ request_serializer=PropertiesTimelineRequestSerializer,parameters=[_PERSON_ID_PARAMETER],- request=PropertiesTimelineRequestSerializer,responses={200: PropertiesTimelineResponseSerializer},summary="Get a person's properties timeline for an insight data point",description=(@@ -1729,21 +1719,15 @@ class PersonViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):"properties are the person properties that the insight's query uses."),)- @action(methods=["GET", "POST"], detail=True, required_scopes=["person:read"])- def properties_timeline(self, request: request.Request, *args: Any, **kwargs: Any) -> Response:+ @action(methods=["POST"], detail=True, required_scopes=["person:read"])+ def properties_timeline(self, request: ValidatedRequest, *args: Any, **kwargs: Any) -> Response:if request.user.is_anonymous or not self.team:return response.Response(data=[])person = self.get_object()tag_queries(product=ProductKey.PERSONS, feature=Feature.QUERY)- if request.method == "GET":- filter = PropertiesTimelineFilter(request=request, team=self.team)- return response.Response(data=PropertiesTimeline().run_for_filter(filter, self.team, person))-- serializer = PropertiesTimelineRequestSerializer(data=request.data)- serializer.is_valid(raise_exception=True)try:- properties_timeline = PropertiesTimeline().run(serializer.validated_data["query"], self.team, person)+ properties_timeline = PropertiesTimeline().run(request.validated_data["query"], self.team, person)except ExposedHogQLError as error:# Covers both `QueryError` and the `SyntaxError` a malformed HogQL filter parses into.raise ValidationError({"query": [str(error)]})diff --git a/posthog/api/test/__snapshots__/test_properties_timeline.ambr b/posthog/api/test/__snapshots__/test_properties_timeline.ambrdeleted file mode 100644index 142ab3d9c555..000000000000--- a/posthog/api/test/__snapshots__/test_properties_timeline.ambr+++ /dev/null@@ -1,481 +0,0 @@-# serializer version: 1-# name: TestPersonPropertiesTimeline.test_timeline_for_existing_actor_with_six_events_but_only_two_relevant_changes- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''))) AS relevant_property_values,- lagInFrame(toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', '')))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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: TestPersonPropertiesTimeline.test_timeline_for_existing_actor_with_six_events_but_only_two_relevant_changes_without_events- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''))) AS relevant_property_values,- lagInFrame(toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', '')))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC'))))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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: TestPersonPropertiesTimeline.test_timeline_for_existing_actor_with_six_events_but_only_two_relevant_changes_without_filters- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- '' AS relevant_property_values,- lagInFrame('') OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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: TestPersonPropertiesTimeline.test_timeline_for_existing_actor_with_three_events_and_return_to_previous_value- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''))) AS relevant_property_values,- lagInFrame(toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', '')))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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: TestPersonPropertiesTimeline.test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_at_single_day_point- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''))) AS relevant_property_values,- lagInFrame(toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', '')))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-02 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-02 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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: TestPersonPropertiesTimeline.test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_at_single_hour_point- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''))) AS relevant_property_values,- lagInFrame(toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', '')))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-02 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-02 01:00:00.000000', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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: TestPersonPropertiesTimeline.test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_at_single_month_point- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''))) AS relevant_property_values,- lagInFrame(toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', '')))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-31 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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: TestPersonPropertiesTimeline.test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_using_relative_date_from- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''))) AS relevant_property_values,- lagInFrame(toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', '')))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-02 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-09 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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: TestPersonPropertiesTimeline.test_timeline_for_new_actor_with_one_event_before_range- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''))) AS relevant_property_values,- lagInFrame(toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', '')))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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: TestPersonPropertiesTimeline.test_timeline_for_new_actor_with_one_event_in_range- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''))) AS relevant_property_values,- lagInFrame(toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', '')))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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: TestPersonPropertiesTimeline.test_timeline_with_two_events_in_range_using_breakdown- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'foo'), ''), 'null'), '^"|"$', ''))) AS relevant_property_values,- lagInFrame(toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'foo'), ''), 'null'), '^"|"$', '')))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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: TestPersonPropertiesTimeline.test_timeline_with_two_events_in_range_using_filter_on_series- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- events.person_properties AS properties,- toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'foo'), ''), 'null'), '^"|"$', ''))) AS relevant_property_values,- lagInFrame(toString(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'bar'), ''), 'null'), '^"|"$', ''), replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.person_properties, 'foo'), ''), 'null'), '^"|"$', '')))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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- '''-# ---diff --git a/posthog/api/test/__snapshots__/test_properties_timeline.new_events_schema.ambr b/posthog/api/test/__snapshots__/test_properties_timeline.new_events_schema.ambrdeleted file mode 100644index a1f628d5af05..000000000000--- a/posthog/api/test/__snapshots__/test_properties_timeline.new_events_schema.ambr+++ /dev/null@@ -1,517 +0,0 @@-# serializer version: 1-# name: TestPersonPropertiesTimeline.test_timeline_for_existing_actor_with_six_events_but_only_two_relevant_changes[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))))) AS relevant_property_values,- lagInFrame(toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar))))))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ----# name: TestPersonPropertiesTimeline.test_timeline_for_existing_actor_with_six_events_but_only_two_relevant_changes_without_events[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))))) AS relevant_property_values,- lagInFrame(toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar))))))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC'))))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ----# name: TestPersonPropertiesTimeline.test_timeline_for_existing_actor_with_six_events_but_only_two_relevant_changes_without_filters[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- '' AS relevant_property_values,- lagInFrame('') OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ----# name: TestPersonPropertiesTimeline.test_timeline_for_existing_actor_with_three_events_and_return_to_previous_value[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))))) AS relevant_property_values,- lagInFrame(toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar))))))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ----# name: TestPersonPropertiesTimeline.test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_at_single_day_point[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))))) AS relevant_property_values,- lagInFrame(toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar))))))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-02 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-02 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ----# name: TestPersonPropertiesTimeline.test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_at_single_hour_point[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))))) AS relevant_property_values,- lagInFrame(toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar))))))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-02 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-02 01:00:00.000000', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ----# name: TestPersonPropertiesTimeline.test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_at_single_month_point[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))))) AS relevant_property_values,- lagInFrame(toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar))))))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-31 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ----# name: TestPersonPropertiesTimeline.test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_using_relative_date_from[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))))) AS relevant_property_values,- lagInFrame(toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar))))))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-02 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-09 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ----# name: TestPersonPropertiesTimeline.test_timeline_for_new_actor_with_one_event_before_range[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))))) AS relevant_property_values,- lagInFrame(toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar))))))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ----# name: TestPersonPropertiesTimeline.test_timeline_for_new_actor_with_one_event_in_range[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))))) AS relevant_property_values,- lagInFrame(toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar))))))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ----# name: TestPersonPropertiesTimeline.test_timeline_with_two_events_in_range_using_breakdown[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))), if(notEquals(toJSONString(events.person_properties.^foo), '{}'), toJSONString(events.person_properties.^foo), if(isNull(nullIf(toString(events.person_properties.foo), '')), NULL, if(and(in(ascii(toString(events.person_properties.foo)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.foo)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.foo), '[]'), '{}'), toString(events.person_properties.foo)))))) AS relevant_property_values,- lagInFrame(toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))), if(notEquals(toJSONString(events.person_properties.^foo), '{}'), toJSONString(events.person_properties.^foo), if(isNull(nullIf(toString(events.person_properties.foo), '')), NULL, if(and(in(ascii(toString(events.person_properties.foo)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.foo)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.foo), '[]'), '{}'), toString(events.person_properties.foo))))))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ----# name: TestPersonPropertiesTimeline.test_timeline_with_two_events_in_range_using_filter_on_series[new_events_schema]- '''- /* user_id:0 request:_snapshot_ */- SELECT timestamp AS timestamp,- properties AS properties,- minus(end_event_number, start_event_number) AS relevant_event_count- FROM- (SELECT timestamp AS timestamp,- properties AS properties,- start_event_number AS start_event_number,- leadInFrame(start_event_number, 1, plus(total_events, 1)) OVER (- ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number- FROM- (SELECT toTimeZone(events.timestamp, 'UTC') AS timestamp,- concat('{', arrayStringConcat(arrayMap(kv -> concat(toJSONString(kv.1), ':', kv.2), arrayFilter(kv -> not (kv.2 = '""'- and kv.1 in ('$browser', '$browser_language', '$browser_version', '$device_type', '$geoip_city_name', '$geoip_continent_code', '$geoip_continent_name', '$geoip_country_code', '$geoip_country_name', '$geoip_subdivision_1_name', '$geoip_time_zone', '$initial_browser', '$initial_browser_language', '$initial_browser_version', '$initial_device_type', '$initial_geoip_city_name', '$initial_geoip_continent_code', '$initial_geoip_continent_name', '$initial_geoip_country_code', '$initial_geoip_country_name', '$initial_geoip_subdivision_1_name', '$initial_geoip_time_zone', '$initial_os', '$initial_os_version', '$os', '$os_version')), JSONExtractKeysAndValuesRaw(toJSONString(events.person_properties)))), ','), '}') AS properties,- toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))), if(notEquals(toJSONString(events.person_properties.^foo), '{}'), toJSONString(events.person_properties.^foo), if(isNull(nullIf(toString(events.person_properties.foo), '')), NULL, if(and(in(ascii(toString(events.person_properties.foo)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.foo)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.foo), '[]'), '{}'), toString(events.person_properties.foo)))))) AS relevant_property_values,- lagInFrame(toString(tuple(if(notEquals(toJSONString(events.person_properties.^bar), '{}'), toJSONString(events.person_properties.^bar), if(isNull(nullIf(toString(events.person_properties.bar), '')), NULL, if(and(in(ascii(toString(events.person_properties.bar)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.bar)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.bar), '[]'), '{}'), toString(events.person_properties.bar)))), if(notEquals(toJSONString(events.person_properties.^foo), '{}'), toJSONString(events.person_properties.^foo), if(isNull(nullIf(toString(events.person_properties.foo), '')), NULL, if(and(in(ascii(toString(events.person_properties.foo)), tuple(91, 123)), in(ascii(toJSONString(events.person_properties.foo)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.person_properties.foo), '[]'), '{}'), toString(events.person_properties.foo))))))) OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,- row_number() OVER (- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS start_event_number,- count() OVER () AS total_events- FROM events_json AS events- WHERE and(equals(events.team_id, 99999), equals(events.person_id, toUUIDOrNull('12345678-0000-0000-0000-000000000001')), greaterOrEquals(events.timestamp, toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), lessOrEquals(events.timestamp, toDateTime64('2020-01-05 23:59:59.999999', 6, 'UTC')), equals(events.event, '$pageview')))- WHERE or(equals(start_event_number, 1), ifNull(notEquals(relevant_property_values, previous_relevant_property_values), isNotNull(relevant_property_values)- or isNotNull(previous_relevant_property_values))))- ORDER BY timestamp ASC- LIMIT 100 SETTINGS readonly=2,- max_execution_time=60,- allow_experimental_object_type=1,- max_ast_elements=4000000,- max_expanded_ast_elements=4000000,- max_bytes_before_external_group_by=0,- 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,- json_type_escape_dots_in_keys=1,- output_format_json_escape_forward_slashes=0- '''-# ---diff --git a/posthog/api/test/test_properties_timeline.py b/posthog/api/test/test_properties_timeline.pyindex 8d39433beebf..c226e6637dc5 100644--- a/posthog/api/test/test_properties_timeline.py+++ b/posthog/api/test/test_properties_timeline.py@@ -1,9 +1,7 @@import jsonimport uuidimport random-from typing import Optional-import time_machinefrom posthog.test.base import (APIBaseTest,ClickhouseTestMixin,@@ -11,7 +9,6 @@ from posthog.test.base import (_create_person,also_test_with_materialized_columns,flush_persons_and_events,- snapshot_clickhouse_queries,)from django.test import SimpleTestCase@@ -23,6 +20,7 @@ from rest_framework.renderers import JSONRendererfrom posthog.schema import (Breakdown,BreakdownFilter,+ ChartDisplayType,Compare,CompareFilter,DateRange,@@ -36,6 +34,7 @@ from posthog.schema import (PropertyGroupFilterValue,PropertyOperator,StickinessQuery,+ TrendsFilter,TrendsQuery,)@@ -43,7 +42,6 @@ from posthog.hogql.errors import ExposedHogQLErrorfrom posthog.api.person import PropertiesTimelineRequestSerializerfrom posthog.hogql_queries.properties_timeline.properties_timeline import PropertiesTimeline, PropertiesTimelineResult-from posthog.models.filters.mixins.base import BreakdownTypefrom posthog.models.person.util import get_person_by_uuidMATERIALIZED_COLUMN_KWARGS = {"person_properties": ["foo", "bar"]}@@ -73,31 +71,6 @@ class TestPersonPropertiesTimeline(ClickhouseTestMixin, APIBaseTest):person_properties=actor_properties,)- def _get_timeline_result(- self,- *,- events: Optional[list] = None,- actions: Optional[list] = None,- properties: Optional[list] = None,- breakdown: Optional[str] = None,- breakdown_type: Optional[BreakdownType] = None,- date_from: Optional[str],- date_to: Optional[str],- display: str = "ActionsTable",- interval: Optional[str] = None,- expected_status: int = status.HTTP_200_OK,- ) -> PropertiesTimelineResult:- url = (- f"/api/person/{TEST_PERSON_ID}/properties_timeline"- f"?events={json.dumps(events or [])}&actions={json.dumps(actions or [])}"- f"&properties={json.dumps(properties or [])}&display={display}"- f"&date_from={date_from or ''}&date_to={date_to or ''}&interval={interval or ''}"- f"&breakdown={breakdown or ''}&breakdown_type={(breakdown_type or 'person') if breakdown else ''}"- )- properties_timeline = self.client.get(url)- self.assertEqual(properties_timeline.status_code, expected_status)- return properties_timeline.json()-def _get_query_timeline_result(self, query: InsightActorsQuery) -> PropertiesTimelineResult:person = get_person_by_uuid(self.team.pk, str(TEST_PERSON_ID))assert person is not None@@ -264,712 +237,116 @@ class TestPersonPropertiesTimeline(ClickhouseTestMixin, APIBaseTest):with self.assertRaises(ExposedHogQLError):PropertiesTimeline().run(query, self.team, person)- @also_test_with_materialized_columns(**MATERIALIZED_COLUMN_KWARGS)- @snapshot_clickhouse_queries- def test_timeline_for_new_actor_with_one_event_in_range(self):+ def _create_six_events_with_two_bar_changes(self):self._create_person({"foo": "abc", "bar": 123})self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123},- timestamp="2020-01-01T00:00:00Z", # Exactly the same as date_from- )- flush_persons_and_events()-- timeline = self._get_timeline_result(- events=[- {- "id": "$pageview",- }- ],- properties=[{"key": "bar", "value": "xyz", "type": "person"}],- date_from="2020-01-01",- date_to="2020-01-05",- )-- self.assertEqual(- timeline,- {- "points": [- {- "properties": {"foo": "abc", "bar": 123},- "relevant_event_count": 1,- "timestamp": "2020-01-01T00:00:00Z",- }- ],- "crucial_property_keys": ["bar"],- "effective_date_from": "2020-01-01T00:00:00+00:00",- "effective_date_to": "2020-01-05T23:59:59.999999+00:00",- },+ event="$pageview", actor_properties={"foo": "abc", "bar": 456}, timestamp="2020-01-01T00:00:00Z")-- @also_test_with_materialized_columns(**MATERIALIZED_COLUMN_KWARGS)- @snapshot_clickhouse_queries- def test_timeline_for_new_actor_with_one_event_before_range(self):- self._create_person({"foo": "abc", "bar": 123})self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123},- timestamp="2019-12-27T00:00:00Z", # Before date_from- )- flush_persons_and_events()-- timeline = self._get_timeline_result(- events=[- {- "id": "$pageview",- }- ],- properties=[{"key": "bar", "value": "xyz", "type": "person"}],- date_from="2020-01-01",- date_to="2020-01-05",- )-- self.assertEqual(- timeline,- {- "points": [], # No relevant events in range- "crucial_property_keys": ["bar"],- "effective_date_from": "2020-01-01T00:00:00+00:00",- "effective_date_to": "2020-01-05T23:59:59.999999+00:00",- },+ event="whatever", actor_properties={"foo": "abc", "bar": 123}, timestamp="2020-01-02T00:00:00Z")-- @also_test_with_materialized_columns(**MATERIALIZED_COLUMN_KWARGS)- @snapshot_clickhouse_queries- def test_timeline_with_two_events_in_range_using_filter_on_series(self):- self._create_person({"foo": "abc", "bar": 123})self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123},- timestamp="2020-01-01T00:00:00Z", # Exactly the same as date_from+ event="$pageview", actor_properties={"foo": "abc", "bar": 123}, timestamp="2020-01-02T01:00:00Z")self._create_event(- event="$pageview",- actor_properties={"foo": "klm", "bar": 123},- timestamp="2020-01-01T21:37:00Z",- )- flush_persons_and_events()-- timeline = self._get_timeline_result(- events=[- {- "id": "$pageview",- "properties": [- {- "key": "foo",- "type": "person",- "value": ["whatever"],- "operator": "exact",- },- {- "key": "fin",- "type": "event",- "value": ["anything"],- "operator": "exact",- },- ],- }- ],- properties=[{"key": "bar", "value": "xyz", "type": "person"}],- date_from="2020-01-01",- date_to="2020-01-05",- )-- self.assertEqual(- timeline,- {- "points": [- {- "properties": {"foo": "abc", "bar": 123},- "relevant_event_count": 1,- "timestamp": "2020-01-01T00:00:00Z",- },- {- "properties": {"foo": "klm", "bar": 123},- "relevant_event_count": 1,- "timestamp": "2020-01-01T21:37:00Z",- },- ],- "crucial_property_keys": ["bar", "foo"],- "effective_date_from": "2020-01-01T00:00:00+00:00",- "effective_date_to": "2020-01-05T23:59:59.999999+00:00",- },+ event="$pageview", actor_properties={"foo": "abc", "bar": 123}, timestamp="2020-01-03T01:00:00Z")-- @also_test_with_materialized_columns(**MATERIALIZED_COLUMN_KWARGS)- @snapshot_clickhouse_queries- def test_timeline_with_two_events_in_range_using_breakdown(self):- self._create_person({"foo": "abc", "bar": 123})self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123},- timestamp="2020-01-01T00:00:00Z", # Exactly the same as date_from+ event="$pageview", actor_properties={"foo": "abc", "bar": 123}, timestamp="2020-01-04T19:00:00Z")self._create_event(- event="$pageview",- actor_properties={"foo": "klm", "bar": 123},- timestamp="2020-01-01T21:37:00Z",+ event="$pageview", actor_properties={"foo": "abc", "bar": 789}, timestamp="2020-01-04T19:00:01Z")flush_persons_and_events()- timeline = self._get_timeline_result(- events=[- {- "id": "$pageview",- }- ],- breakdown="foo",- properties=[{"key": "bar", "value": "xyz", "type": "person"}],- date_from="2020-01-01",- date_to="2020-01-05",- )-- self.assertEqual(- timeline,- {- "points": [- {- "properties": {"foo": "abc", "bar": 123},- "relevant_event_count": 1,- "timestamp": "2020-01-01T00:00:00Z",- },- {- "properties": {"foo": "klm", "bar": 123},- "relevant_event_count": 1,- "timestamp": "2020-01-01T21:37:00Z",- },- ],- "crucial_property_keys": ["bar", "foo"],- "effective_date_from": "2020-01-01T00:00:00+00:00",- "effective_date_to": "2020-01-05T23:59:59.999999+00:00",- },- )-- @snapshot_clickhouse_queries- @also_test_with_materialized_columns(**MATERIALIZED_COLUMN_KWARGS)- def test_timeline_for_existing_actor_with_three_events_and_return_to_previous_value(self):- self._create_person({"foo": "abc", "bar": 123})- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 456}, # Initial bar- timestamp="2020-01-02T00:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123}, # Changed bar- timestamp="2020-01-03T00:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={- "foo": "abc",- "bar": 456,- }, # Changed bar back to initial value- timestamp="2020-01-04T00:00:00Z",- )- flush_persons_and_events()-- timeline = self._get_timeline_result(- events=[- {- "id": "$pageview",- }- ],- properties=[{"key": "bar", "value": "xyz", "type": "person"}],- date_from="2020-01-01",- date_to="2020-01-05",- )-- self.assertEqual(- timeline,- {- "points": [- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-02T00:00:00Z",- },- {- "properties": {"foo": "abc", "bar": 123},- "relevant_event_count": 1,- "timestamp": "2020-01-03T00:00:00Z",- },- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-04T00:00:00Z",- },- ],- "crucial_property_keys": ["bar"],- "effective_date_from": "2020-01-01T00:00:00+00:00",- "effective_date_to": "2020-01-05T23:59:59.999999+00:00",- },- )-- @snapshot_clickhouse_queries- @also_test_with_materialized_columns(- person_properties=["bar"],- )- def test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_at_single_day_point(self):- self._create_person(properties={"foo": "abc", "bar": 123})- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 456}, # Initial bar- timestamp="2020-01-02T00:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123}, # Changed bar- timestamp="2020-01-02T07:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={- "foo": "abc",- "bar": 456,- }, # Changed bar back to initial value- timestamp="2020-01-02T14:00:00Z",- )- flush_persons_and_events()-- timeline = self._get_timeline_result(- events=[- {- "id": "$pageview",- }- ],- properties=[{"key": "bar", "value": "xyz", "type": "person"}],- display="ActionsLineGraph",- date_from="2020-01-02T00:00:00Z",- date_to="2020-01-02T00:00:00Z",- # For some legacy reason data point-specific date_from and date_to are the same in the persons modal- # The backend needs interval to offset date_from properly- interval="day",- )-- self.assertEqual(- timeline,- {- "points": [- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-02T00:00:00Z",- },- {- "properties": {"foo": "abc", "bar": 123},- "relevant_event_count": 1,- "timestamp": "2020-01-02T07:00:00Z",- },- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-02T14:00:00Z",- },- ],- "crucial_property_keys": ["bar"],- "effective_date_from": "2020-01-02T00:00:00+00:00",- "effective_date_to": "2020-01-02T23:59:59.999999+00:00",- },- )-- @snapshot_clickhouse_queries- @also_test_with_materialized_columns(- person_properties=["bar"],- )- def test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_at_single_hour_point(self):- self._create_person(properties={"foo": "abc", "bar": 123})- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 456}, # Initial bar- timestamp="2020-01-02T00:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123}, # Changed bar- timestamp="2020-01-02T00:20:00Z",- )- self._create_event(- event="$pageview",- actor_properties={- "foo": "abc",- "bar": 456,- }, # Changed bar back to initial value- timestamp="2020-01-02T00:40:00Z",- )- flush_persons_and_events()-- timeline = self._get_timeline_result(- events=[- {- "id": "$pageview",- }- ],- properties=[{"key": "bar", "value": "xyz", "type": "person"}],- display="ActionsLineGraph",- date_from="2020-01-02T00:00:00Z",- date_to="2020-01-02T00:00:00Z",- interval="hour",- )-- self.assertEqual(- timeline,- {- "points": [- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-02T00:00:00Z",- },- {- "properties": {"foo": "abc", "bar": 123},- "relevant_event_count": 1,- "timestamp": "2020-01-02T00:20:00Z",- },- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-02T00:40:00Z",- },+ @parameterized.expand(+ [+ (+ "pageviews_with_key_property",+ EventsNode(event="$pageview"),+ [PersonPropertyFilter(key="bar", value="xyz", operator=PropertyOperator.EXACT)],+ ["bar"],+ [+ ({"foo": "abc", "bar": 456}, 1, "2020-01-01T00:00:00Z"),+ ({"foo": "abc", "bar": 123}, 3, "2020-01-02T01:00:00Z"),+ ({"foo": "abc", "bar": 789}, 1, "2020-01-04T19:00:01Z"),],- "crucial_property_keys": ["bar"],- "effective_date_from": "2020-01-02T00:00:00+00:00",- "effective_date_to": "2020-01-02T01:00:00+00:00",- },- )-- @snapshot_clickhouse_queries- @also_test_with_materialized_columns(- person_properties=["bar"],- )- def test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_at_single_month_point(- self,- ):- self._create_person(properties={"foo": "abc", "bar": 123})- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 456}, # Initial bar- timestamp="2020-01-01T00:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123}, # Changed bar- timestamp="2020-01-02T00:20:00Z",- )- self._create_event(- event="$pageview",- actor_properties={- "foo": "abc",- "bar": 456,- }, # Changed bar back to initial value- timestamp="2020-01-31T00:40:00Z",- )- flush_persons_and_events()-- timeline = self._get_timeline_result(- events=[- {- "id": "$pageview",- }- ],- properties=[{"key": "bar", "value": "xyz", "type": "person"}],- display="ActionsLineGraph",- date_from="2020-01-01",- date_to="2020-01-01",- interval="month",- )-- self.assertEqual(- timeline,- {- "points": [- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-01T00:00:00Z",- },- {- "properties": {"foo": "abc", "bar": 123},- "relevant_event_count": 1,- "timestamp": "2020-01-02T00:20:00Z",- },- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-31T00:40:00Z",- },+ ),+ (+ "pageviews_without_key_properties",+ EventsNode(event="$pageview"),+ None,+ [],+ [({"foo": "abc", "bar": 456}, 5, "2020-01-01T00:00:00Z")],+ ),+ (+ "all_events_with_key_property",+ EventsNode(event=None),+ [PersonPropertyFilter(key="bar", value="xyz", operator=PropertyOperator.EXACT)],+ ["bar"],+ [+ ({"foo": "abc", "bar": 456}, 1, "2020-01-01T00:00:00Z"),+ ({"foo": "abc", "bar": 123}, 4, "2020-01-02T00:00:00Z"),+ ({"foo": "abc", "bar": 789}, 1, "2020-01-04T19:00:01Z"),],- "crucial_property_keys": ["bar"],- "effective_date_from": "2020-01-01T00:00:00+00:00",- "effective_date_to": "2020-01-31T23:59:59.999999+00:00",- },- )-- @snapshot_clickhouse_queries- @also_test_with_materialized_columns(- person_properties=["bar"],+ ),+ ])- def test_timeline_for_existing_person_with_three_events_and_return_to_previous_value_using_relative_date_from(+ def test_query_timeline_counts_series_events_between_key_property_changes(self,+ _name: str,+ series: EventsNode,+ properties: list[PersonPropertyFilter] | None,+ expected_keys: list[str],+ expected_points: list[tuple[dict, int, str]],):- self._create_person(properties={"foo": "abc", "bar": 123})- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 456}, # Initial bar- timestamp="2020-01-02T00:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123}, # Changed bar- timestamp="2020-01-02T00:20:00Z",- )- self._create_event(- event="$pageview",- actor_properties={- "foo": "abc",- "bar": 456,- }, # Changed bar back to initial value- timestamp="2020-01-06T00:40:00Z",- )- flush_persons_and_events()-- with time_machine.travel("2020-01-09T21:37:00Z", tick=False):- timeline = self._get_timeline_result(- events=[- {- "id": "$pageview",- }- ],- properties=[{"key": "bar", "value": "xyz", "type": "person"}],- date_from="-7d",- date_to=None,- )-- self.assertEqual(- timeline,- {- "points": [- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-02T00:00:00Z",- },- {- "properties": {"foo": "abc", "bar": 123},- "relevant_event_count": 1,- "timestamp": "2020-01-02T00:20:00Z",- },- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-06T00:40:00Z",- },- ],- "crucial_property_keys": ["bar"],- "effective_date_from": "2020-01-02T00:00:00+00:00",- "effective_date_to": "2020-01-09T23:59:59.999999+00:00",- },- )-- @snapshot_clickhouse_queries- @also_test_with_materialized_columns(**MATERIALIZED_COLUMN_KWARGS)- def test_timeline_for_existing_actor_with_six_events_but_only_two_relevant_changes(self):- self._create_person({"foo": "abc", "bar": 123})- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 456},- timestamp="2020-01-01T00:00:00Z", # Exactly the same as date_from- )- self._create_event(- event="whatever", # This event is not a $pageview, so it must be ignored here- actor_properties={"foo": "abc", "bar": 123}, # Changed bar- timestamp="2020-01-02T00:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123}, # Changed bar- timestamp="2020-01-02T01:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123},- timestamp="2020-01-03T01:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123},- timestamp="2020-01-04T19:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 789}, # Changed bar- timestamp="2020-01-04T19:00:01Z",- )- flush_persons_and_events()+ self._create_six_events_with_two_bar_changes()- timeline = self._get_timeline_result(- events=[- {- "id": "$pageview",- }- ],- properties=[{"key": "bar", "value": "xyz", "type": "person"}],- date_from="2020-01-01",- date_to="2020-01-05",+ source = TrendsQuery(+ series=[series],+ properties=properties,+ dateRange=DateRange(date_from="2020-01-01", date_to="2020-01-05"),+ trendsFilter=TrendsFilter(display=ChartDisplayType.BOLD_NUMBER),)+ timeline = self._get_query_timeline_result(InsightActorsQuery(source=source))self.assertEqual(timeline,{"points": [- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-01T00:00:00Z",- },- {- "properties": {"foo": "abc", "bar": 123},- "relevant_event_count": 3,- "timestamp": "2020-01-02T01:00:00Z",- },- {- "properties": {"foo": "abc", "bar": 789},- "relevant_event_count": 1,- "timestamp": "2020-01-04T19:00:01Z",- },+ {"properties": properties_at_point, "relevant_event_count": count, "timestamp": timestamp}+ for properties_at_point, count, timestamp in expected_points],- "crucial_property_keys": ["bar"],+ "crucial_property_keys": expected_keys,"effective_date_from": "2020-01-01T00:00:00+00:00","effective_date_to": "2020-01-05T23:59:59.999999+00:00",},)- @snapshot_clickhouse_queries- def test_timeline_for_existing_actor_with_six_events_but_only_two_relevant_changes_without_filters(self):- self._create_person({"foo": "abc", "bar": 123})- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 456},- timestamp="2020-01-01T00:00:00Z", # Exactly the same as date_from- )- self._create_event(- event="whatever", # This event is not a $pageview, but this doesn't matter here anyway- actor_properties={"foo": "abc", "bar": 123}, # Changed bar- timestamp="2020-01-01T01:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123}, # Changed bar- timestamp="2020-01-02T01:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123},- timestamp="2020-01-03T01:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123},- timestamp="2020-01-04T19:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 789}, # Changed bar- timestamp="2020-01-04T19:00:01Z",- )- flush_persons_and_events()-- timeline = self._get_timeline_result(- events=[- {- "id": "$pageview",- }- ],- date_from="2020-01-01",- date_to="2020-01-05",- )-- self.assertEqual(- timeline, # Without filters, NO changes are relevant- {- "points": [- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 5,- "timestamp": "2020-01-01T00:00:00Z",- },- ],- "crucial_property_keys": [],- "effective_date_from": "2020-01-01T00:00:00+00:00",- "effective_date_to": "2020-01-05T23:59:59.999999+00:00",- },- )-- @snapshot_clickhouse_queries- def test_timeline_for_existing_actor_with_six_events_but_only_two_relevant_changes_without_events(self):+ @also_test_with_materialized_columns(**MATERIALIZED_COLUMN_KWARGS)+ def test_query_timeline_shows_return_to_previous_value(self):self._create_person({"foo": "abc", "bar": 123})self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 456},- timestamp="2020-01-01T00:00:00Z", # Exactly the same as date_from- )- self._create_event(- event="whatever", # This event is not a $pageview, but with no events/actions specified, it will be counted- actor_properties={"foo": "abc", "bar": 123}, # Changed bar- timestamp="2020-01-01T01:00:00Z",+ event="$pageview", actor_properties={"foo": "abc", "bar": 456}, timestamp="2020-01-02T00:00:00Z")self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123}, # Changed bar- timestamp="2020-01-02T01:00:00Z",+ event="$pageview", actor_properties={"foo": "abc", "bar": 123}, timestamp="2020-01-02T07:00:00Z")self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123},- timestamp="2020-01-03T01:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 123},- timestamp="2020-01-04T19:00:00Z",- )- self._create_event(- event="$pageview",- actor_properties={"foo": "abc", "bar": 789}, # Changed bar- timestamp="2020-01-04T19:00:01Z",+ event="$pageview", actor_properties={"foo": "abc", "bar": 456}, timestamp="2020-01-02T14:00:00Z")flush_persons_and_events()- timeline = self._get_timeline_result(- properties=[{"key": "bar", "value": "xyz", "type": "person"}],- date_from="2020-01-01",- date_to="2020-01-05",+ source = TrendsQuery(+ series=[EventsNode(event="$pageview")],+ properties=[PersonPropertyFilter(key="bar", value="xyz", operator=PropertyOperator.EXACT)],+ dateRange=DateRange(date_from="2020-01-01", date_to="2020-01-05"),)+ timeline = self._get_query_timeline_result(InsightActorsQuery(source=source, day="2020-01-02"))self.assertEqual(- timeline,- {- "points": [- {- "properties": {"foo": "abc", "bar": 456},- "relevant_event_count": 1,- "timestamp": "2020-01-01T00:00:00Z",- },- {- "properties": {"foo": "abc", "bar": 123},- "relevant_event_count": 4,- "timestamp": "2020-01-01T01:00:00Z", # whatever event- },- {- "properties": {"foo": "abc", "bar": 789},- "relevant_event_count": 1,- "timestamp": "2020-01-04T19:00:01Z",- },- ],- "crucial_property_keys": ["bar"],- "effective_date_from": "2020-01-01T00:00:00+00:00",- "effective_date_to": "2020-01-05T23:59:59.999999+00:00",- },+ [(point["properties"]["bar"], point["timestamp"]) for point in timeline["points"]],+ [(456, "2020-01-02T00:00:00Z"), (123, "2020-01-02T07:00:00Z"), (456, "2020-01-02T14:00:00Z")],)diff --git a/posthog/hogql_queries/properties_timeline/properties_timeline.py b/posthog/hogql_queries/properties_timeline/properties_timeline.pyindex 9a7f3e3b40ac..02bd351c433d 100644--- a/posthog/hogql_queries/properties_timeline/properties_timeline.py+++ b/posthog/hogql_queries/properties_timeline/properties_timeline.py@@ -1,10 +1,6 @@import jsonimport datetime-from datetime import timedelta-from typing import Any, TypedDict, Union, cast-from zoneinfo import ZoneInfo--from dateutil.relativedelta import relativedelta+from typing import Any, TypedDict, Unionfrom posthog.schema import (ActionsNode,@@ -26,44 +22,21 @@ from posthog.hogql.parser import parse_selectfrom posthog.hogql.property import action_to_exprfrom posthog.hogql.query import execute_hogql_query-from posthog.constants import NON_TIME_SERIES_DISPLAY_TYPES, TREND_FILTER_TYPE_ACTIONSfrom posthog.dataclasses import frozen-from posthog.hogql_queries.properties_timeline.query_date_range import QueryDateRange-from posthog.models.entity import Entity-from posthog.models.filters.properties_timeline_filter import PropertiesTimelineFilterfrom posthog.models.group.group import Groupfrom posthog.models.person.person import Person-from posthog.models.property.util import count_hogql_properties, extract_tables_and_properties+from posthog.models.property.util import count_hogql_propertiesfrom posthog.models.team.team import Teamfrom products.actions.backend.models.action import Actionfrom products.product_analytics.backend.facade import queries as product_analytics_queries-def offset_time_series_date_by_interval(- date: datetime.datetime, *, filter: PropertiesTimelineFilter, team: Team-) -> datetime.datetime:- """If the insight is time-series, offset date according to the interval of the filter."""- if filter.display in NON_TIME_SERIES_DISPLAY_TYPES:- return date- if filter.interval == "month":- date = (date + relativedelta(months=1) - timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0)- elif filter.interval == "week":- date = (date + timedelta(weeks=1) - timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0)- elif filter.interval == "hour":- date = date + timedelta(hours=1)- else: # "day" is the default interval- date = date.replace(hour=23, minute=59, second=59, microsecond=999999)- if date.tzinfo is None:- date = date.replace(tzinfo=ZoneInfo(team.timezone))- return date--@frozenclass _TimelineScope:"""The actor's events that the timeline reads, and the properties whose changes it tracks."""- entity_exprs: tuple[ast.Expr, ...]+ series_expr: ast.Expr | Nonecrucial_property_keys: tuple[str, ...]aggregation_group_type_index: int | Nonedate_from: datetime.datetime@@ -196,32 +169,6 @@ ORDER BY timestamp ASCclass PropertiesTimeline:- def extract_crucial_property_keys(self, filter: PropertiesTimelineFilter, team_id: int) -> set[str]:- is_filter_relevant = lambda property_type, property_group_type_index: (- (property_type == "person")- if filter.aggregation_group_type_index is None- else (property_type == "group" and property_group_type_index == filter.aggregation_group_type_index)- )-- property_filters = list(filter.property_groups.flat)- for event in filter.entities:- property_filters.extend(event.property_groups.flat)- all_property_identifiers = extract_tables_and_properties(property_filters, team_id=team_id)-- crucial_property_keys = {- property_key- for property_key, property_type, property_group_type_index in all_property_identifiers- if is_filter_relevant(property_type, property_group_type_index)- }-- if filter.breakdown and filter.breakdown_type == "person":- if isinstance(filter.breakdown, list):- crucial_property_keys.update(cast(list[str], filter.breakdown))- else:- crucial_property_keys.add(filter.breakdown)-- return crucial_property_keys-def _actor_properties_chain(self, aggregation_group_type_index: int | None) -> list[Union[str, int]]:# Read the actor's properties as frozen on the event (persons-on-events columns), so the# timeline reflects the values at the time of each event rather than current values.@@ -229,22 +176,9 @@ class PropertiesTimeline:return ["poe", "properties"]return [f"goe_{aggregation_group_type_index}", "properties"]- def _entity_expr(self, entity: Entity, team: Team) -> ast.Expr:- # Only the entity's event/action identity filters the timeline events — the entity's ad-hoc- # property filters are not applied here (they only feed crucial-property-key extraction), matching- # the legacy behavior.- if entity.type == TREND_FILTER_TYPE_ACTIONS:- action = Action.objects.get(pk=cast(Union[int, str], entity.id), team=team)- return action_to_expr(action)- return ast.CompareOperation(- op=ast.CompareOperationOp.Eq,- left=ast.Field(chain=["event"]),- right=ast.Constant(value=entity.id),- )-def _series_expr(self, series: EventsNode | ActionsNode, team: Team) -> ast.Expr | None:- # Like `_entity_expr`, only the series' event or action selects events. Its property filters- # name key properties, and filtering on them would hide the changes the timeline shows.+ # Only the series' event or action selects events. Its property filters name key properties,+ # and filtering on them would hide the changes the timeline shows.if isinstance(series, ActionsNode):action = Action.objects.filter(pk=series.id, team__project_id=team.project_id).first()return action_to_expr(action) if action is not None else ast.Constant(value=False)@@ -256,29 +190,6 @@ class PropertiesTimeline:right=ast.Constant(value=series.event),)- def _scope_from_filter(self, filter: PropertiesTimelineFilter, team: Team) -> _TimelineScope:- if filter._date_from is not None and filter._date_to is not None and filter._date_from == filter._date_to:- # A single-point range is widened by one interval so the window actually spans some events.- filter = filter.shallow_clone(- {- "date_to": offset_time_series_date_by_interval(- cast(datetime.datetime, filter.date_from),- filter=filter,- team=team,- )- }- )-- query_date_range = QueryDateRange(filter, team)- return _TimelineScope(- entity_exprs=tuple(self._entity_expr(entity, team) for entity in filter.entities),- crucial_property_keys=tuple(sorted(self.extract_crucial_property_keys(filter, team_id=team.pk))),- aggregation_group_type_index=filter.aggregation_group_type_index,- date_from=query_date_range.date_from_param.replace(tzinfo=team.timezone_info),- date_to=query_date_range.date_to_param.replace(tzinfo=team.timezone_info),- date_to_inclusive=True,- )-def _scope_from_query(self, query: InsightActorsQuery, team: Team) -> _TimelineScope:source = query.sourceif not isinstance(source, TrendsQuery):@@ -295,9 +206,8 @@ class PropertiesTimeline:)# The facade imports the trends runner on first attribute access, which keeps it off the startup import path.window = product_analytics_queries.trends_actors_date_window(team=team, query=query)- series_expr = self._series_expr(series, team)return _TimelineScope(- entity_exprs=(series_expr,) if series_expr is not None else (),+ series_expr=self._series_expr(series, team),crucial_property_keys=tuple(sorted(crucial_property_keys)),aggregation_group_type_index=aggregation_group_type_index,date_from=window.date_from.astimezone(team.timezone_info),@@ -309,11 +219,6 @@ class PropertiesTimeline:"""The actor's key property values over the window of the Trends data point that `query` selects."""return self._run(self._scope_from_query(query, team), team, actor)- def run_for_filter(- self, filter: PropertiesTimelineFilter, team: Team, actor: Union[Person, Group]- ) -> PropertiesTimelineResult:- return self._run(self._scope_from_filter(filter, team), team, actor)-def _run(self, scope: _TimelineScope, team: Team, actor: Union[Person, Group]) -> PropertiesTimelineResult:actor_properties_chain = self._actor_properties_chain(scope.aggregation_group_type_index)# Serialize the crucial property values to a single string for change detection. A tuple would@@ -349,10 +254,8 @@ class PropertiesTimeline:right=ast.Constant(value=scope.date_to),),]- if scope.entity_exprs:- where_exprs.append(- ast.Or(exprs=list(scope.entity_exprs)) if len(scope.entity_exprs) > 1 else scope.entity_exprs[0]- )+ if scope.series_expr is not None:+ where_exprs.append(scope.series_expr)query = parse_select(PROPERTIES_TIMELINE_HOGQL,diff --git a/posthog/hogql_queries/properties_timeline/query_date_range.py b/posthog/hogql_queries/properties_timeline/query_date_range.pydeleted file mode 100644index ded7b1a7c108..000000000000--- a/posthog/hogql_queries/properties_timeline/query_date_range.py+++ /dev/null@@ -1,248 +0,0 @@-from datetime import datetime, timedelta-from functools import cached_property-from typing import Any, Literal, Optional-from zoneinfo import ZoneInfo--from django.utils import timezone--from dateutil.relativedelta import relativedelta-from rest_framework.exceptions import ValidationError--from posthog.interval_specs import UnsupportedIntervalError, get_trunc_func-from posthog.models.filters.base_filter import BaseFilter-from posthog.models.filters.mixins.interval import IntervalMixin-from posthog.models.filters.properties_timeline_filter import PropertiesTimelineFilter-from posthog.models.team import Team-from posthog.models.team.team import WeekStartDay-from posthog.utils import DEFAULT_DATE_FROM_DAYS, relative_date_parse, relative_date_parse_with_delta_mapping--TIME_IN_SECONDS: dict[str, Any] = {- "hour": 3600,- "day": 3600 * 24,- "week": 3600 * 24 * 7,- "month": 3600 * 24 * 30, # TODO: Let's get rid of this lie! Months are not all 30 days long-}---def get_trunc_func_ch(period: Optional[str]) -> str:- try:- return get_trunc_func(period)- except UnsupportedIntervalError:- raise ValidationError(f"Period {period} is unsupported.")---def get_start_of_interval_sql(- interval: str,- *,- team: Team,- source: str = "timestamp",- ensure_datetime: bool = False,-) -> str:- trunc_func = get_trunc_func_ch(interval)- if source.startswith("%(") and source.endswith(")s"):- source = f"toDateTime({source}, %(timezone)s)"- elif "%(timezone)s" not in source:- source = f"toTimeZone(toDateTime({source}, 'UTC'), %(timezone)s)"- trunc_func_args = [source]- if trunc_func == "toStartOfWeek":- trunc_func_args.append((WeekStartDay(team.week_start_day or 0)).clickhouse_mode)- interval_sql = f"{trunc_func}({', '.join(trunc_func_args)})"- # For larger intervals dates are returned instead of datetimes, and we always want datetimes for comparisons- return f"toDateTime({interval_sql}, %(timezone)s)" if ensure_datetime else interval_sql---class QueryDateRange:- """Translation of the raw `date_from` and `date_to` filter values to datetimes.-- A raw `date_from` and `date_to` value can either be:- - unset, in which case `date_from` takes the timestamp of the earliest event in the project and `date_to` equals now- - a string, which can be a datetime in any format supported by dateutil.parser.isoparse()- - a datetime already (only for filters constructed internally)- """-- _filter: PropertiesTimelineFilter- _team: Team- _table: str- _should_round: Optional[bool]- _earliest_timestamp_fallback: Optional[datetime]-- def __init__(- self,- filter: PropertiesTimelineFilter,- team: Team,- should_round: Optional[bool] = None,- table="",- earliest_timestamp_fallback: Optional[datetime] = None,- ) -> None:- filter.team = team # This is a dirty - but the easiest - way to get the team into the filter- self._filter = filter- self._team = team- self._table = f"{table}." if table else ""- self._should_round = should_round- self._earliest_timestamp_fallback = earliest_timestamp_fallback-- @cached_property- def date_to_param(self) -> datetime:- date_to = self._now- delta_mapping = None- position: str | None = None- if isinstance(self._filter._date_to, str):- date_to, delta_mapping, position = relative_date_parse_with_delta_mapping(- self._filter._date_to, self._team.timezone_info- )- elif isinstance(self._filter._date_to, datetime):- date_to = self._localize_to_team(self._filter._date_to)-- is_relative = not self._filter._date_to or delta_mapping is not None- if not self._filter.use_explicit_dates:- if not self.is_hourly(self._filter._date_to):- date_to = date_to.replace(hour=23, minute=59, second=59, microsecond=999999)- elif is_relative and not position:- date_to = date_to.replace(minute=59, second=59, microsecond=999999)-- return date_to-- def get_earliest_timestamp(self):- if self._earliest_timestamp_fallback:- return self._earliest_timestamp_fallback-- # Imported here to avoid a circular import at module load (timestamp_utils pulls in HogQL).- from posthog.hogql_queries.utils.timestamp_utils import get_earliest_timestamp_unfiltered # noqa: PLC0415-- return get_earliest_timestamp_unfiltered(self._team)-- @property- def date_from_param(self) -> datetime:- date_from: datetime- if self._filter._date_from == "all":- date_from = self.get_earliest_timestamp()- elif isinstance(self._filter._date_from, str):- date_from = relative_date_parse(self._filter._date_from, self._team.timezone_info)- elif isinstance(self._filter._date_from, datetime):- date_from = self._localize_to_team(self._filter._date_from)- else:- date_from = self._now.replace(hour=0, minute=0, second=0, microsecond=0) - relativedelta(- days=DEFAULT_DATE_FROM_DAYS- )-- if not self.is_hourly(self._filter._date_from) and not self._filter.use_explicit_dates:- date_from = date_from.replace(hour=0, minute=0, second=0, microsecond=0)-- # For legacy insights, if filtering by days (e.g. -7d), clamp to the start of the day- elif (- hasattr(self._filter, "interval")- and self._filter.interval == "hour"- and isinstance(self._filter._date_from, str)- and "d" in self._filter._date_from- ):- date_from = date_from.replace(hour=0, minute=0, second=0, microsecond=0)-- return date_from-- @cached_property- def _now(self):- return self._localize_to_team(timezone.now())-- def _localize_to_team(self, target: datetime):- return target.astimezone(ZoneInfo(self._team.timezone))-- @cached_property- def date_to_clause(self):- return self._get_timezone_aware_date_condition("date_to")-- @cached_property- def date_from_clause(self):- return self._get_timezone_aware_date_condition("date_from")-- @cached_property- def date_to(self) -> tuple[str, dict]:- date_to_query = self.date_to_clause- date_to = self.date_to_param-- date_to_param = {- "date_to": date_to.strftime("%Y-%m-%d %H:%M:%S"),- "timezone": self._team.timezone,- }-- return date_to_query, date_to_param-- @cached_property- def date_from(self) -> tuple[str, dict]:- date_from_query = self.date_from_clause- date_from = self.date_from_param-- date_from_param = {- "date_from": date_from.strftime("%Y-%m-%d %H:%M:%S"),- "timezone": self._team.timezone,- }-- return date_from_query, date_from_param-- def _get_timezone_aware_date_condition(self, date_param: Literal["date_from", "date_to"]) -> str:- operator = ">=" if date_param == "date_from" else "<="- event_timestamp_expr = self._normalize_datetime(column=f"{self._table}timestamp")- date_expr = self._normalize_datetime(param=date_param)- if operator == ">=" and self.should_round: # Round date_from to start of interval if `should_round` is true- if not (isinstance(self._filter, BaseFilter) and isinstance(self._filter, IntervalMixin)):- raise ValueError("Cannot round with a filter that's not based on BaseFilter with IntervalMixin")- date_expr = get_start_of_interval_sql(- self._filter.interval,- team=self._team,- source=date_expr,- ensure_datetime=True,- )- return f"AND {event_timestamp_expr} {operator} {date_expr}"-- @staticmethod- def _normalize_datetime(*, column: Optional[str] = None, param: Optional[str] = None) -> str:- """Return expression with datetime normalized to project timezone.-- If normalizing a column (such as `events.timestamp`) provide the column expression as `column`- (e.g. `"events.timestamp"`). Stored data is already of type `DateTime('UTC')` already, so we just- need to convert that to the project TZ.- If normalizing a parameter (such as `%(date_from)s`) provide the parameter name as `param` (e.g. `"date_from"`).- Such parameters are strings, so they need to be parsed. They're assumed to already be in the project TZ.- """- if column and param:- raise ValueError("Must provide either column or param, not both")- if column:- return f"toTimeZone({column}, %(timezone)s)"- elif param:- return f"toDateTime(%({param})s, %(timezone)s)"- else:- raise ValueError("Must provide either column or param")-- @cached_property- def delta(self) -> timedelta:- return self.date_to_param - self.date_from_param-- @cached_property- def num_intervals(self) -> int:- if not hasattr(self._filter, "interval"):- return 1- if self._filter.interval == "month":- rel_delta = relativedelta(self.date_to_param, self.date_from_param)- return (rel_delta.years * 12) + rel_delta.months + 1-- return int(self.delta.total_seconds() / TIME_IN_SECONDS[self._filter.interval]) + 1-- @cached_property- def should_round(self) -> bool:- if self._should_round is not None:- return self._should_round-- if not hasattr(self._filter, "interval") or self._filter.use_explicit_dates:- return False-- round_interval = False- if self._filter.interval in ["week", "month"]:- round_interval = True- else:- round_interval = self.delta.total_seconds() >= TIME_IN_SECONDS[self._filter.interval] * 2-- return round_interval-- def is_hourly(self, target):- if not hasattr(self._filter, "interval"):- return False- return self._filter.interval == "hour" or (target and isinstance(target, str) and "h" in target)diff --git a/posthog/hogql_queries/properties_timeline/test/__init__.py b/posthog/hogql_queries/properties_timeline/test/__init__.pydeleted file mode 100644index e69de29bb2d1..000000000000diff --git a/posthog/hogql_queries/properties_timeline/test/test_query_date_range.py b/posthog/hogql_queries/properties_timeline/test/test_query_date_range.pydeleted file mode 100644index 06aacbd05ff9..000000000000--- a/posthog/hogql_queries/properties_timeline/test/test_query_date_range.py+++ /dev/null@@ -1,131 +0,0 @@-import time_machine-from posthog.test.base import APIBaseTest--from posthog.hogql_queries.properties_timeline.query_date_range import QueryDateRange-from posthog.models.filters.properties_timeline_filter import PropertiesTimelineFilter---class TestQueryDateRange(APIBaseTest):- def test_parsed_date(self):- with time_machine.travel("2021-08-25T00:00:00.000Z", tick=False):- filter = PropertiesTimelineFilter(- data={- "date_from": "-48h",- "interval": "day",- "events": [{"id": "sign up"}, {"id": "no events"}],- }- )-- query_date_range = QueryDateRange(filter=filter, team=self.team, should_round=False)- parsed_date_from, date_from_params = query_date_range.date_from- parsed_date_to, date_to_params = query_date_range.date_to-- self.assertEqual(- parsed_date_from % date_from_params,- "AND toTimeZone(timestamp, UTC) >= toDateTime(2021-08-23 00:00:00, UTC)",- )- self.assertEqual(- parsed_date_to % date_to_params,- "AND toTimeZone(timestamp, UTC) <= toDateTime(2021-08-25 23:59:59, UTC)",- )-- def test_parsed_date_hour(self):- with time_machine.travel("2021-08-25T00:00:00.000Z", tick=False):- filter = PropertiesTimelineFilter(- data={- "date_from": "-48h",- "interval": "hour",- "events": [{"id": "sign up"}, {"id": "no events"}],- }- )-- query_date_range = QueryDateRange(filter=filter, team=self.team, should_round=False)- parsed_date_from, date_from_params = query_date_range.date_from- parsed_date_to, date_to_params = query_date_range.date_to-- self.assertEqual(- parsed_date_from % date_from_params,- "AND toTimeZone(timestamp, UTC) >= toDateTime(2021-08-23 00:00:00, UTC)",- )- self.assertEqual(- parsed_date_to % date_to_params,- "AND toTimeZone(timestamp, UTC) <= toDateTime(2021-08-25 00:59:59, UTC)",- ) # ensure last hour is included-- def test_parsed_date_middle_of_hour(self):- with time_machine.travel("2021-08-25T00:00:00.000Z", tick=False):- filter = PropertiesTimelineFilter(- data={- "date_from": "2021-08-23 05:00:00",- "date_to": "2021-08-26 07:00:00",- "interval": "hour",- "events": [{"id": "sign up"}, {"id": "no events"}],- }- )-- query_date_range = QueryDateRange(filter=filter, team=self.team, should_round=False)- parsed_date_from, date_from_params = query_date_range.date_from- parsed_date_to, date_to_params = query_date_range.date_to-- self.assertEqual(- parsed_date_from % date_from_params,- "AND toTimeZone(timestamp, UTC) >= toDateTime(2021-08-23 05:00:00, UTC)",- )- self.assertEqual(- parsed_date_to % date_to_params,- "AND toTimeZone(timestamp, UTC) <= toDateTime(2021-08-26 07:00:00, UTC)",- ) # ensure last hour is included-- def test_parsed_date_week_rounded(self):- with time_machine.travel("2021-08-25T00:00:00.000Z", tick=False):- filter = PropertiesTimelineFilter(- data={- "date_from": "-7d",- "interval": "week",- "events": [{"id": "sign up"}, {"id": "no events"}],- }- )-- query_date_range = QueryDateRange(filter=filter, team=self.team)- parsed_date_from, date_from_params = query_date_range.date_from- parsed_date_to, date_to_params = query_date_range.date_to-- self.assertEqual(- parsed_date_from % {**filter.hogql_context.values, **date_from_params},- "AND toTimeZone(timestamp, UTC) >= toDateTime(toStartOfWeek(toDateTime(2021-08-18 00:00:00, UTC), 0), UTC)",- )- self.assertEqual(- parsed_date_to % {**filter.hogql_context.values, **date_to_params},- "AND toTimeZone(timestamp, UTC) <= toDateTime(2021-08-25 23:59:59, UTC)",- )-- def test_is_hourly(self):- with time_machine.travel("2021-08-25T00:00:00.000Z", tick=False):- filter = PropertiesTimelineFilter(- data={- "date_from": "-48h",- "interval": "day",- "events": [{"id": "sign up"}, {"id": "no events"}],- }- )-- query_date_range = QueryDateRange(filter=filter, team=self.team)-- self.assertFalse(query_date_range.is_hourly("-48d"))- self.assertTrue(query_date_range.is_hourly("-48h"))- self.assertFalse(query_date_range.is_hourly(None))-- with time_machine.travel("2021-08-25T00:00:00.000Z", tick=False):- filter = PropertiesTimelineFilter(- data={- "date_from": "-48h",- "interval": "hour",- "events": [{"id": "sign up"}, {"id": "no events"}],- }- )-- query_date_range = QueryDateRange(filter=filter, team=self.team)-- self.assertTrue(query_date_range.is_hourly("-48d"))- self.assertTrue(query_date_range.is_hourly("-48h"))- self.assertTrue(query_date_range.is_hourly(None))diff --git a/posthog/hogql_queries/utils/query_date_range.py b/posthog/hogql_queries/utils/query_date_range.pyindex a26acc667f41..c83c36a20925 100644--- a/posthog/hogql_queries/utils/query_date_range.py+++ b/posthog/hogql_queries/utils/query_date_range.py@@ -40,7 +40,6 @@ def compare_interval_length(return ORDERED_INTERVALS.index(interval1) >= ORDERED_INTERVALS.index(interval2)-# Originally similar to the legacy QueryDateRange (now posthog/hogql_queries/properties_timeline/query_date_range.py) but rewritten to be used in HogQL queriesclass QueryDateRange:"""Translation of the raw `date_from` and `date_to` filter values to datetimes."""diff --git a/posthog/hogql_queries/utils/query_previous_period_date_range.py b/posthog/hogql_queries/utils/query_previous_period_date_range.pyindex 46357ce4beb2..0abca678e4eb 100644--- a/posthog/hogql_queries/utils/query_previous_period_date_range.py+++ b/posthog/hogql_queries/utils/query_previous_period_date_range.py@@ -20,7 +20,6 @@ _PREVIOUS_CALENDAR_UNITS = {}-# Originally similar to the legacy QueryDateRange (now posthog/hogql_queries/properties_timeline/query_date_range.py) but rewritten to be used in HogQL queriesclass QueryPreviousPeriodDateRange(QueryDateRange):"""Translation of the raw `date_from` and `date_to` filter values to datetimes."""diff --git a/posthog/models/entity/entity.py b/posthog/models/entity/entity.pyindex 5a4df118d43a..21c8ad856cdf 100644--- a/posthog/models/entity/entity.py+++ b/posthog/models/entity/entity.py@@ -71,9 +71,9 @@ class Entity(PropertyMixin):math_property_revenue_currency: Optional["RevenueCurrencyPropertyConfig"]math_hogql: Optional[str]math_group_type_index: Optional[GroupTypeIndex]- # Index is not set at all by default (meaning: access = AttributeError) - it's populated in EntitiesMixin.entities+ # Index is not set at all by default (meaning: access = AttributeError) - it's populated in parse_entities# Used for identifying entities within a single query during query building,- # which generally uses Entity objects processed by EntitiesMixin+ # which generally uses Entity objects processed by parse_entities# The clean room way to do this would be passing the index _alongside_ the object, but OOP abuse is much less workindex: intdiff --git a/posthog/models/filters/__init__.py b/posthog/models/filters/__init__.pyindex 7aca236ce85c..e69de29bb2d1 100644--- a/posthog/models/filters/__init__.py+++ b/posthog/models/filters/__init__.py@@ -1,5 +0,0 @@-from .properties_timeline_filter import PropertiesTimelineFilter--__all__ = [- "PropertiesTimelineFilter",-]diff --git a/posthog/models/filters/base_filter.py b/posthog/models/filters/base_filter.pydeleted file mode 100644index 2eeb037f3a12..000000000000--- a/posthog/models/filters/base_filter.py+++ /dev/null@@ -1,104 +0,0 @@-import json-import inspect-from typing import TYPE_CHECKING, Any, Optional--from rest_framework import request-from rest_framework.exceptions import ValidationError--from posthog.constants import PROPERTIES-from posthog.models.utils import sane_repr-from posthog.utils import encode_get_request_params--from .mixins.common import BaseParamMixin--if TYPE_CHECKING:- from posthog.hogql.context import HogQLContext-- from posthog.models.team.team import Team---class BaseFilter(BaseParamMixin):- _data: dict- team: Optional["Team"]- kwargs: dict- hogql_context: "HogQLContext"-- def __init__(- self,- data: Optional[dict[str, Any]] = None,- request: Optional[request.Request] = None,- *,- team: Optional["Team"] = None,- **kwargs,- ) -> None:- if request:- properties = {}- if request.GET.get(PROPERTIES):- try:- properties = json.loads(request.GET[PROPERTIES])- except json.decoder.JSONDecodeError:- raise ValidationError("Properties are unparsable!")- elif request.data and request.data.get(PROPERTIES):- properties = request.data[PROPERTIES]-- data = {- **request.GET.dict(),- **request.data,- **(data if data else {}),- **({PROPERTIES: properties}),- }- elif data is None:- raise ValueError("You need to define either a data dict or a request")-- self._data = data- self.kwargs = kwargs- self.team = team-- # Deferred: hogql.context pulls the HogQL/schema layer, and the legacy filter- # classes load at django.setup() in every process via the models package.- from posthog.hogql.context import HogQLContext # noqa: PLC0415-- # Set the HogQL context for the request- self.hogql_context = self.kwargs.get(- "hogql_context",- HogQLContext(- within_non_hogql_query=True,- team_id=self.team.pk if self.team else None,- team=self.team if self.team else None,- ),- )- if self.team:- self.hogql_context.modifiers.personsOnEventsMode = self.team.person_on_events_mode-- def to_dict(self) -> dict[str, Any]:- ret = {}-- for _, func in inspect.getmembers(self, inspect.ismethod):- if hasattr(func, "include_dict"): # provided by @include_dict decorator- ret.update(func())-- return ret-- def to_params(self) -> dict[str, str]:- return encode_get_request_params(data=self.to_dict())-- def toJSON(self):- return json.dumps(self.to_dict(), default=lambda o: o.__dict__, sort_keys=True, indent=4)-- def shallow_clone(self, overrides: dict[str, Any]):- "Clone the filter's data while sharing the HogQL context"- return type(self)(- data={**self._data, **overrides},- **{**self.kwargs, "team": self.team, "hogql_context": self.hogql_context},- )-- def query_tags(self) -> dict[str, Any]:- ret = {}-- for _, func in inspect.getmembers(self, inspect.ismethod):- if hasattr(func, "include_query_tags"): # provided by @include_query_tags decorator- ret.update(func())-- return ret-- __repr__ = sane_repr("_data", "kwargs", include_id=False)diff --git a/posthog/models/filters/mixins/base.py b/posthog/models/filters/mixins/base.pyindex cbcdc33318c8..86e8e12be2b8 100644--- a/posthog/models/filters/mixins/base.py+++ b/posthog/models/filters/mixins/base.py@@ -1,8 +1,2 @@-from typing import Literal--BreakdownType = Literal["event", "person", "cohort", "group", "session", "hogql"]-IntervalType = Literal["hour", "day", "week", "month"]--class BaseParamMixin:_data: dictdiff --git a/posthog/models/filters/mixins/common.py b/posthog/models/filters/mixins/common.pydeleted file mode 100644index 3588a5401116..000000000000--- a/posthog/models/filters/mixins/common.py+++ /dev/null@@ -1,374 +0,0 @@-import json-import datetime-from functools import cached_property-from math import ceil-from typing import Any, Literal, Optional, Union-from zoneinfo import ZoneInfo--from django.utils import timezone--from dateutil.relativedelta import relativedelta-from rest_framework.exceptions import ValidationError--from posthog.hogql.constants import BREAKDOWN_VALUES_LIMIT, BREAKDOWN_VALUES_LIMIT_FOR_COUNTRIES--from posthog.constants import (- ACTIONS,- BREAKDOWN,- BREAKDOWN_ATTRIBUTION_TYPE,- BREAKDOWN_ATTRIBUTION_VALUE,- BREAKDOWN_GROUP_TYPE_INDEX,- BREAKDOWN_HIDE_OTHER_AGGREGATION,- BREAKDOWN_HISTOGRAM_BIN_COUNT,- BREAKDOWN_LIMIT,- BREAKDOWN_NORMALIZE_URL,- BREAKDOWN_TYPE,- BREAKDOWNS,- DATA_WAREHOUSE_ENTITIES,- DATE_FROM,- DATE_TO,- DISPLAY,- DISPLAY_TYPES,- EVENTS,- EXPLICIT_DATE,- INSIGHT,- INSIGHT_TO_DISPLAY,- INSIGHT_TRENDS,- TREND_FILTER_TYPE_ACTIONS,- TREND_FILTER_TYPE_DATA_WAREHOUSE,- TREND_FILTER_TYPE_EVENTS,- TRENDS_WORLD_MAP,- BreakdownAttributionType,-)-from posthog.models.entity import Entity-from posthog.models.filters.mixins.base import BaseParamMixin, BreakdownType-from posthog.models.filters.mixins.utils import include_dict, include_query_tags, process_bool-from posthog.models.filters.utils import GroupTypeIndex, validate_group_type_index-from posthog.utils import DEFAULT_DATE_FROM_DAYS, relative_date_parse_with_delta_mapping---class BreakdownMixin(BaseParamMixin):- @cached_property- def breakdown(self) -> Optional[Union[str, list[Union[str, int]]]]:- breakdown = self._data.get(BREAKDOWN)-- if not isinstance(breakdown, str):- return breakdown-- try:- return json.loads(breakdown)- except (TypeError, json.decoder.JSONDecodeError):- return breakdown-- @cached_property- def breakdown_attribution_type(self) -> Optional[BreakdownAttributionType]:- attribution_type = self._data.get(BREAKDOWN_ATTRIBUTION_TYPE)- if not attribution_type:- return BreakdownAttributionType.FIRST_TOUCH-- return attribution_type-- @cached_property- def breakdown_attribution_value(self) -> Optional[int]:- attribution_value = self._data.get(BREAKDOWN_ATTRIBUTION_VALUE)-- if attribution_value is None and self.breakdown_attribution_type == BreakdownAttributionType.STEP:- raise ValueError(f'Missing required parameter "{BREAKDOWN_ATTRIBUTION_VALUE}" for attribution type "step"')-- return int(attribution_value) if attribution_value is not None else None-- @cached_property- def breakdowns(self) -> Optional[list[dict[str, Any]]]:- breakdowns = self._data.get(BREAKDOWNS)-- try:- if isinstance(breakdowns, list):- return breakdowns- elif isinstance(breakdowns, str):- return json.loads(breakdowns)- else:- return breakdowns-- except (TypeError, json.decoder.JSONDecodeError):- raise ValidationError(detail="breakdowns must be a list of items, each with property and type")-- @cached_property- def _breakdown_limit(self) -> Optional[int]:- if BREAKDOWN_LIMIT in self._data:- try:- return int(self._data[BREAKDOWN_LIMIT])- except (ValueError, TypeError):- pass- return None-- @property- def breakdown_limit_or_default(self) -> int:- return self._breakdown_limit or (- BREAKDOWN_VALUES_LIMIT_FOR_COUNTRIES- if getattr(self, "display", None) == TRENDS_WORLD_MAP- else BREAKDOWN_VALUES_LIMIT- )-- @cached_property- def using_histogram(self) -> bool:- return self.breakdown_histogram_bin_count is not None-- @cached_property- def breakdown_histogram_bin_count(self) -> Optional[int]:- if BREAKDOWN_HISTOGRAM_BIN_COUNT in self._data:- try:- return int(self._data[BREAKDOWN_HISTOGRAM_BIN_COUNT])- except (ValueError, TypeError):- pass- return None-- @cached_property- def breakdown_hide_other_aggregation(self) -> Optional[bool]:- if BREAKDOWN_HIDE_OTHER_AGGREGATION in self._data:- try:- return self._data[BREAKDOWN_HIDE_OTHER_AGGREGATION] in ("True", "true", True)- except (ValueError, TypeError):- pass- return None-- @include_dict- def breakdown_to_dict(self):- result: dict = {}- if self.breakdown:- result[BREAKDOWN] = self.breakdown- if self.breakdowns:- result[BREAKDOWNS] = self.breakdowns- if self._breakdown_limit:- result[BREAKDOWN_LIMIT] = self._breakdown_limit- if self.breakdown_attribution_type:- result[BREAKDOWN_ATTRIBUTION_TYPE] = self.breakdown_attribution_type- if self.breakdown_attribution_value is not None:- result[BREAKDOWN_ATTRIBUTION_VALUE] = self.breakdown_attribution_value- if self.breakdown_histogram_bin_count is not None:- result[BREAKDOWN_HISTOGRAM_BIN_COUNT] = self.breakdown_histogram_bin_count- if self.breakdown_hide_other_aggregation is not None:- result[BREAKDOWN_HIDE_OTHER_AGGREGATION] = self.breakdown_hide_other_aggregation- if self.breakdown_normalize_url is not None:- result[BREAKDOWN_NORMALIZE_URL] = self.breakdown_normalize_url- return result-- @cached_property- def breakdown_type(self) -> Optional[BreakdownType]:- return self._data.get(BREAKDOWN_TYPE, None)-- @cached_property- def breakdown_group_type_index(self) -> Optional[GroupTypeIndex]:- value = self._data.get(BREAKDOWN_GROUP_TYPE_INDEX, None)- return validate_group_type_index(BREAKDOWN_GROUP_TYPE_INDEX, value)-- @include_dict- def breakdown_type_and_group_to_dict(self):- if self.breakdown_type == "group":- return {- BREAKDOWN_TYPE: self.breakdown_type,- BREAKDOWN_GROUP_TYPE_INDEX: self.breakdown_group_type_index,- }- elif self.breakdown_type:- return {BREAKDOWN_TYPE: self.breakdown_type}- else:- return {}-- @cached_property- def breakdown_normalize_url(self) -> bool:- """- When breaking down by $current_url or $pathname, we ignore trailing slashes, question marks, and hashes.- """- bool_to_test = self._data.get("breakdown_normalize_url", False)- return process_bool(bool_to_test)-- @include_query_tags- def breakdown_query_tags(self):- if self.breakdown_type:- return {"breakdown_by": [self.breakdown_type]}-- return {}---class InsightMixin(BaseParamMixin):- @cached_property- def insight(self) -> Literal["TRENDS", "FUNNELS", "RETENTION", "PATHS", "LIFECYCLE", "STICKINESS"]:- return self._data.get(INSIGHT, INSIGHT_TRENDS).upper()-- @include_dict- def insight_to_dict(self):- return {"insight": self.insight}---class DisplayDerivedMixin(InsightMixin):- @cached_property- def display(self) -> Literal[DISPLAY_TYPES]:- return self._data.get(DISPLAY, INSIGHT_TO_DISPLAY[self.insight])-- @include_dict- def display_to_dict(self):- return {"display": self.display}---class DateMixin(BaseParamMixin):- date_from_delta_mapping: Optional[dict[str, int]]- date_to_delta_mapping: Optional[dict[str, int]]-- @cached_property- def _date_from(self) -> Optional[Union[str, datetime.datetime]]:- return self._data.get(DATE_FROM, None)-- @cached_property- def _date_to(self) -> Optional[Union[str, datetime.datetime]]:- return self._data.get(DATE_TO, None)-- @cached_property- def date_from(self) -> Optional[datetime.datetime]:- self.date_from_delta_mapping = None- if self._date_from:- if self._date_from == "all":- return None- elif isinstance(self._date_from, str):- date, delta_mapping, _position = relative_date_parse_with_delta_mapping(- self._date_from,- self.team.timezone_info, # type: ignore- always_truncate=True,- )- self.date_from_delta_mapping = delta_mapping- return date- else:- return self._date_from- return timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) - relativedelta(- days=DEFAULT_DATE_FROM_DAYS- )-- @cached_property- def date_to(self) -> datetime.datetime:- self.date_to_delta_mapping = None- if not self._date_to:- return timezone.now()- else:- if isinstance(self._date_to, str):- try:- return datetime.datetime.strptime(self._date_to, "%Y-%m-%d").replace(- hour=23,- minute=59,- second=59,- microsecond=999999,- tzinfo=ZoneInfo("UTC"),- )- except ValueError:- try:- return datetime.datetime.strptime(self._date_to, "%Y-%m-%d %H:%M:%S").replace(- tzinfo=ZoneInfo("UTC")- )- except ValueError:- (- date,- delta_mapping,- _position,- ) = relative_date_parse_with_delta_mapping(- self._date_to,- self.team.timezone_info, # type: ignore- always_truncate=True,- )- self.date_to_delta_mapping = delta_mapping- return date- else:- return self._date_to-- @cached_property- def use_explicit_dates(self) -> bool:- return process_bool(self._data.get(EXPLICIT_DATE))-- @include_dict- def date_to_dict(self) -> dict:- result_dict = {}- if self._date_from:- result_dict.update(- {- "date_from": self._date_from.isoformat()- if isinstance(self._date_from, datetime.datetime)- else self._date_from- }- )- else:- result_dict.update({"date_from": f"-{DEFAULT_DATE_FROM_DAYS}d"})-- if self._date_to:- result_dict.update(- {- "date_to": self._date_to.isoformat()- if isinstance(self._date_to, datetime.datetime)- else self._date_to- }- )-- if self.use_explicit_dates:- result_dict.update({EXPLICIT_DATE: "true"})-- return result_dict-- @include_query_tags- def query_tags_dates(self):- if self.date_from and self.date_to:- delta = self.date_to - self.date_from- delta_days = ceil(delta.total_seconds() / datetime.timedelta(days=1).total_seconds())- return {"query_time_range_days": delta_days}- return {}---class EntitiesMixin(BaseParamMixin):- @cached_property- def entities(self) -> list[Entity]:- processed_entities: list[Entity] = []- if self._data.get(ACTIONS):- actions = self._data.get(ACTIONS, [])- if isinstance(actions, str):- actions = json.loads(actions)-- processed_entities.extend([Entity({**entity, "type": TREND_FILTER_TYPE_ACTIONS}) for entity in actions])- if self._data.get(EVENTS):- events = self._data.get(EVENTS, [])- if isinstance(events, str):- events = json.loads(events)- processed_entities.extend([Entity({**entity, "type": TREND_FILTER_TYPE_EVENTS}) for entity in events])- if self._data.get(DATA_WAREHOUSE_ENTITIES):- data_warehouse_entities = self._data.get(DATA_WAREHOUSE_ENTITIES, [])- if isinstance(data_warehouse_entities, str):- data_warehouse_entities = json.loads(data_warehouse_entities)- processed_entities.extend(- [Entity({**entity, "type": TREND_FILTER_TYPE_DATA_WAREHOUSE}) for entity in data_warehouse_entities]- )-- processed_entities.sort(key=lambda entity: entity.order if entity.order else -1)- # Set sequential index values on entities- for index, entity in enumerate(processed_entities):- entity.index = index- return processed_entities-- @include_query_tags- def query_tags_entities(self):- return {"number_of_entities": len(self.entities)}-- @cached_property- def actions(self) -> list[Entity]:- return [entity for entity in self.entities if entity.type == TREND_FILTER_TYPE_ACTIONS]-- @cached_property- def events(self) -> list[Entity]:- return [entity for entity in self.entities if entity.type == TREND_FILTER_TYPE_EVENTS]-- @cached_property- def data_warehouse_entities(self) -> list[Entity]:- return [entity for entity in self.entities if entity.type == TREND_FILTER_TYPE_DATA_WAREHOUSE]-- @include_dict- def entities_to_dict(self):- return {- **({"events": [entity.to_dict() for entity in self.events]} if len(self.events) > 0 else {}),- **({"actions": [entity.to_dict() for entity in self.actions]} if len(self.actions) > 0 else {}),- }-- @include_query_tags- def entities_query_tags(self):- return {"entity_math": list({entity.math for entity in self.entities if entity.math})}diff --git a/posthog/models/filters/mixins/groups.py b/posthog/models/filters/mixins/groups.pydeleted file mode 100644index 60e291d4fa7c..000000000000--- a/posthog/models/filters/mixins/groups.py+++ /dev/null@@ -1,22 +0,0 @@-from functools import cached_property-from typing import Optional--from posthog.constants import AGGREGATION_GROUP_TYPE_INDEX-from posthog.models.filters.mixins.common import BaseParamMixin-from posthog.models.filters.mixins.utils import include_dict-from posthog.models.filters.utils import GroupTypeIndex, validate_group_type_index---class GroupsAggregationMixin(BaseParamMixin):- @cached_property- def aggregation_group_type_index(self) -> Optional[GroupTypeIndex]:- value = self._data.get(AGGREGATION_GROUP_TYPE_INDEX)- return validate_group_type_index(AGGREGATION_GROUP_TYPE_INDEX, value)-- @include_dict- def aggregation_group_type_index_to_dict(self):- return (- {AGGREGATION_GROUP_TYPE_INDEX: self.aggregation_group_type_index}- if self.aggregation_group_type_index is not None- else {}- )diff --git a/posthog/models/filters/mixins/interval.py b/posthog/models/filters/mixins/interval.pydeleted file mode 100644index 85e20b4a6aa5..000000000000--- a/posthog/models/filters/mixins/interval.py+++ /dev/null@@ -1,31 +0,0 @@-from functools import cached_property-from typing import cast--from posthog.constants import INTERVAL-from posthog.models.filters.mixins.base import IntervalType-from posthog.models.filters.mixins.common import DateMixin-from posthog.models.filters.mixins.utils import include_dict---class IntervalMixin(DateMixin): # Interval doesn't make sense without a date range- """See https://clickhouse.tech/docs/en/sql-reference/data-types/special-data-types/interval/."""-- SUPPORTED_INTERVAL_TYPES = ["hour", "day", "week", "month"]-- @cached_property- def interval(self) -> IntervalType:- interval_candidate = self._data.get(INTERVAL)- if not interval_candidate:- return "day"- if not isinstance(interval_candidate, str):- raise ValueError(f"Interval must be a string!")- interval_candidate = interval_candidate.lower()- if interval_candidate == "minute":- return "hour" # Handle legacy minute-by-minute insights- if interval_candidate not in self.SUPPORTED_INTERVAL_TYPES:- raise ValueError(f"Interval {interval_candidate} does not belong to SUPPORTED_INTERVAL_TYPES!")- return cast(IntervalType, interval_candidate)-- @include_dict- def interval_to_dict(self):- return {"interval": self.interval}diff --git a/posthog/models/filters/mixins/property.py b/posthog/models/filters/mixins/property.pyindex bacfe1650251..e77dcc070a76 100644--- a/posthog/models/filters/mixins/property.py+++ b/posthog/models/filters/mixins/property.py@@ -1,13 +1,9 @@-import jsonfrom functools import cached_property-from rest_framework.exceptions import ValidationError-from posthog.constants import PROPERTIESfrom posthog.models.filters.mixins.base import BaseParamMixin-from posthog.models.filters.mixins.utils import include_dict, include_query_tags-from posthog.models.property import Property, PropertyGroup-from posthog.models.property.parse import parse_properties, parse_property_group_data+from posthog.models.property import PropertyGroup+from posthog.models.property.parse import parse_property_group_dataclass PropertyMixin(BaseParamMixin):@@ -17,43 +13,3 @@ class PropertyMixin(BaseParamMixin):def _parse_data(self, key: str) -> PropertyGroup:return parse_property_group_data(self._data.get(key))-- def old_properties(self, key: str) -> list[Property]:- _props = self._data.get(key)-- if isinstance(_props, str):- try:- loaded_props = json.loads(_props)- except json.decoder.JSONDecodeError:- raise ValidationError("Properties are unparsable!")- else:- loaded_props = _props-- # if grouped properties- if (isinstance(loaded_props, dict) and "type" in loaded_props and "values" in loaded_props) or isinstance(- loaded_props, PropertyGroup- ):- # property_groups is main function from now on- # TODO: this function will go away at end of migration- return []- else:- # old style dict properties or a list of properties- return parse_properties(loaded_props)-- @include_dict- def properties_to_dict(self):- return (- {PROPERTIES: self.property_groups.to_dict()} if self.property_groups and self.property_groups.values else {}- )-- @include_query_tags- def properties_query_tags(self):- filter_by_type = {prop.type for prop in self.property_groups.flat}- for entity in getattr(self, "entities", []):- filter_by_type |= {prop.type for prop in entity.property_groups.flat}-- return {"filter_by_type": list(filter_by_type)}-- @cached_property- def has_hogql_property(self):- return any(prop.type == "hogql" for prop in self.property_groups.flat)diff --git a/posthog/models/filters/mixins/test/test_interval.py b/posthog/models/filters/mixins/test/test_interval.pydeleted file mode 100644index 10405ba76528..000000000000--- a/posthog/models/filters/mixins/test/test_interval.py+++ /dev/null@@ -1,38 +0,0 @@-import pytest--from posthog.models.filters.properties_timeline_filter import PropertiesTimelineFilter--- "filter,expected_interval",- [- (PropertiesTimelineFilter(data={"interval": "hour"}), "hour"),- (PropertiesTimelineFilter(data={"interval": "day"}), "day"),- (PropertiesTimelineFilter(data={"interval": "week"}), "week"),- (PropertiesTimelineFilter(data={"interval": "month"}), "month"),- # Downcasing- (PropertiesTimelineFilter(data={"interval": "HoUR"}), "hour"),- # Blank filter- (PropertiesTimelineFilter(data={"events": []}), "day"),- # Legacy support - translate minutes to hours!- (PropertiesTimelineFilter(data={"interval": "minute"}), "hour"),- ],-)-def test_filter_interval_success(filter, expected_interval):- assert filter.interval == expected_interval- assert filter.interval_to_dict() == {"interval": expected_interval}--- "filter,expected_error_message",- [- (- PropertiesTimelineFilter(data={"interval": "foo"}),- "Interval foo does not belong to SUPPORTED_INTERVAL_TYPES!",- ),- (PropertiesTimelineFilter(data={"interval": 123}), "Interval must be a string!"),- ],-)-def test_filter_interval_errors(filter, expected_error_message):- with pytest.raises(ValueError, match=expected_error_message):- filter.interval # noqa: B018diff --git a/posthog/models/filters/mixins/test/test_property.py b/posthog/models/filters/mixins/test/test_property.pyindex 8c86b1d16f0f..e2df10ae631e 100644--- a/posthog/models/filters/mixins/test/test_property.py+++ b/posthog/models/filters/mixins/test/test_property.py@@ -1,4 +1,6 @@import json+from collections.abc import Callable+from typing import Anyimport pytestfrom unittest.mock import patch@@ -6,78 +8,88 @@ from unittest.mock import patchfrom posthoganalytics.contexts import get_capture_exception_code_variables_contextfrom rest_framework.exceptions import ValidationError-from posthog.models.filters.properties_timeline_filter import PropertiesTimelineFilter+from posthog.models.entity import Entityfrom posthog.models.property import Property, PropertyGroup, PropertyValidationError-def test_property_group_multi_level_parsing():- filter = PropertiesTimelineFilter(- data={- "properties": {- "type": "AND",- "values": [- {- "type": "AND",- "values": [- {"key": "attr", "value": "val_1"},- {"key": "attr_2", "value": "val_2"},- ],- },- {"type": "OR", "values": [{"key": "attr", "value": "val_2"}]},- ],- }+def _entity(data: dict[str, Any]) -> Entity:+ return Entity({"id": "$pageview", "type": "events", **data})++[email protected]("encode", [lambda data: data, json.dumps], ids=["dict", "json"])+def test_property_group_multi_level_parsing(encode: Callable[[dict[str, Any]], Any]):+ entity = _entity(+ {+ "properties": encode(+ {+ "type": "AND",+ "values": [+ {+ "type": "AND",+ "values": [+ {"key": "attr", "value": "val_1"},+ {"key": "attr_2", "value": "val_2"},+ ],+ },+ {"type": "OR", "values": [{"key": "attr", "value": "val_2"}]},+ ],+ }+ )})- assert filter.property_groups.type == "AND"- assert isinstance(filter.property_groups.values[0], PropertyGroup)- assert filter.property_groups.values[0].type == "AND"- assert isinstance(filter.property_groups.values[0].values[0], Property)- assert filter.property_groups.values[0].values[0].key == "attr"- assert filter.property_groups.values[0].values[0].value == "val_1"- assert isinstance(filter.property_groups.values[0].values[1], Property)- assert filter.property_groups.values[0].values[1].key == "attr_2"- assert filter.property_groups.values[0].values[1].value == "val_2"-- assert isinstance(filter.property_groups.values[1], PropertyGroup)- assert filter.property_groups.values[1].type == "OR"- assert isinstance(filter.property_groups.values[1].values[0], Property)- assert filter.property_groups.values[1].values[0].key == "attr"- assert filter.property_groups.values[1].values[0].value == "val_2"---def test_property_group_simple_parsing():- filter = PropertiesTimelineFilter(- data={- "properties": {- "type": "AND",- "values": [- {"key": "attr", "value": "val_1"},- {"key": "attr_2", "value": "val_2"},- ],- }+ assert entity.property_groups.type == "AND"+ assert isinstance(entity.property_groups.values[0], PropertyGroup)+ assert entity.property_groups.values[0].type == "AND"+ assert isinstance(entity.property_groups.values[0].values[0], Property)+ assert entity.property_groups.values[0].values[0].key == "attr"+ assert entity.property_groups.values[0].values[0].value == "val_1"+ assert isinstance(entity.property_groups.values[0].values[1], Property)+ assert entity.property_groups.values[0].values[1].key == "attr_2"+ assert entity.property_groups.values[0].values[1].value == "val_2"++ assert isinstance(entity.property_groups.values[1], PropertyGroup)+ assert entity.property_groups.values[1].type == "OR"+ assert isinstance(entity.property_groups.values[1].values[0], Property)+ assert entity.property_groups.values[1].values[0].key == "attr"+ assert entity.property_groups.values[1].values[0].value == "val_2"++[email protected]("encode", [lambda data: data, json.dumps], ids=["dict", "json"])+def test_property_group_simple_parsing(encode: Callable[[dict[str, Any]], Any]):+ entity = _entity(+ {+ "properties": encode(+ {+ "type": "AND",+ "values": [+ {"key": "attr", "value": "val_1"},+ {"key": "attr_2", "value": "val_2"},+ ],+ }+ )})- assert filter.property_groups.type == "AND"- assert isinstance(filter.property_groups.values[0], Property)- assert filter.property_groups.values[0].key == "attr"- assert filter.property_groups.values[0].value == "val_1"- assert isinstance(filter.property_groups.values[1], Property)- assert filter.property_groups.values[1].key == "attr_2"- assert filter.property_groups.values[1].value == "val_2"+ assert entity.property_groups.type == "AND"+ assert isinstance(entity.property_groups.values[0], Property)+ assert entity.property_groups.values[0].key == "attr"+ assert entity.property_groups.values[0].value == "val_1"+ assert isinstance(entity.property_groups.values[1], Property)+ assert entity.property_groups.values[1].key == "attr_2"+ assert entity.property_groups.values[1].value == "val_2"def test_property_group_empty_parsing():- filter = PropertiesTimelineFilter(data={"properties": {}})+ entity = _entity({"properties": {}})- assert filter.property_groups.type == "AND"- assert filter.property_groups.values == []+ assert entity.property_groups.type == "AND"+ assert entity.property_groups.values == []def test_property_group_invalid_parsing():- filter = PropertiesTimelineFilter(- data={+ entity = _entity(+ {"properties": {"type": "XaND","values": [@@ -89,12 +101,12 @@ def test_property_group_invalid_parsing():)with pytest.raises(ValidationError):- filter.property_groups # noqa: B018+ entity.property_groups # noqa: B018def test_property_group_includes_unhomogenous_groups():- filter = PropertiesTimelineFilter(- data={+ entity = _entity(+ {"properties": {"type": "AND","values": [@@ -108,12 +120,12 @@ def test_property_group_includes_unhomogenous_groups():)with pytest.raises(ValidationError):- filter.property_groups # noqa: B018+ entity.property_groups # noqa: B018def test_property_multi_level_to_dict():- filter = PropertiesTimelineFilter(- data={+ entity = _entity(+ {"properties": {"type": "AND","values": [@@ -130,7 +142,7 @@ def test_property_multi_level_to_dict():})- assert filter.property_groups.to_dict() == {+ assert entity.property_groups.to_dict() == {"type": "AND","values": [{@@ -149,8 +161,8 @@ def test_property_multi_level_to_dict():def test_property_group_simple_to_dict():- filter = PropertiesTimelineFilter(- data={+ entity = _entity(+ {"properties": {"type": "AND","values": [@@ -161,7 +173,7 @@ def test_property_group_simple_to_dict():})- assert filter.property_groups.to_dict() == {+ assert entity.property_groups.to_dict() == {"type": "AND","values": [{"key": "attr", "value": "val_1", "type": "event"},@@ -170,70 +182,6 @@ def test_property_group_simple_to_dict():}-def test_property_group_simple_json_parsing():- filter = PropertiesTimelineFilter(- data={- "properties": json.dumps(- {- "type": "AND",- "values": [- {"key": "attr", "value": "val_1"},- {"key": "attr_2", "value": "val_2"},- ],- }- )- }- )-- assert filter.property_groups.type == "AND"-- assert isinstance(filter.property_groups.values[0], Property)- assert filter.property_groups.values[0].key == "attr"- assert filter.property_groups.values[0].value == "val_1"- assert isinstance(filter.property_groups.values[1], Property)- assert filter.property_groups.values[1].key == "attr_2"- assert filter.property_groups.values[1].value == "val_2"---def test_property_group_multi_level_json_parsing():- filter = PropertiesTimelineFilter(- data={- "properties": json.dumps(- {- "type": "AND",- "values": [- {- "type": "AND",- "values": [- {"key": "attr", "value": "val_1"},- {"key": "attr_2", "value": "val_2"},- ],- },- {"type": "OR", "values": [{"key": "attr", "value": "val_2"}]},- ],- }- )- }- )-- assert filter.property_groups.type == "AND"- assert isinstance(filter.property_groups.values[0], PropertyGroup)- assert filter.property_groups.values[0].type == "AND"-- assert isinstance(filter.property_groups.values[0].values[0], Property)- assert filter.property_groups.values[0].values[0].key == "attr"- assert filter.property_groups.values[0].values[0].value == "val_1"- assert isinstance(filter.property_groups.values[0].values[1], Property)- assert filter.property_groups.values[0].values[1].key == "attr_2"- assert filter.property_groups.values[0].values[1].value == "val_2"-- assert isinstance(filter.property_groups.values[1], PropertyGroup)- assert filter.property_groups.values[1].type == "OR"- assert isinstance(filter.property_groups.values[1].values[0], Property)- assert filter.property_groups.values[1].values[0].key == "attr"- assert filter.property_groups.values[1].values[0].value == "val_2"--@pytest.mark.parametrize("invalid_property,expected_fields,expected_exception,expected_fingerprint",[@@ -299,8 +247,8 @@ def test_property_group_parsing_reports_and_skips_unparsable_property(# with no visibility at all. It must still be dropped (callers across the codebase# rely on best-effort parsing of legacy/malformed data), but the failure must now be# reported — regardless of which internal check inside Property.__init__ rejected it.- filter = PropertiesTimelineFilter(- data={+ entity = _entity(+ {"properties": {"type": "AND","values": [{"key": "attr", "value": "val_1"}, invalid_property],@@ -309,7 +257,7 @@ def test_property_group_parsing_reports_and_skips_unparsable_property()with patch("posthog.models.property.parse.capture_exception") as mock_capture_exception:- properties = filter.property_groups.values+ properties = entity.property_groups.valuesassert len(properties) == 1assert isinstance(properties[0], Property)@@ -330,10 +278,10 @@ def test_property_group_parsing_reports_non_mapping_property():# `Property(**prop_params)` unpacking with TypeError, before __init__ even runs. The# grouped-properties path can't reach this: a non-mapping element trips the "cannot# contain both PropertyGroup and Property objects" check first.- filter = PropertiesTimelineFilter(data={"properties": [{"key": "attr", "value": "val_1"}, "not-a-mapping"]})+ entity = _entity({"properties": [{"key": "attr", "value": "val_1"}, "not-a-mapping"]})with patch("posthog.models.property.parse.capture_exception") as mock_capture_exception:- properties = filter.property_groups.values+ properties = entity.property_groups.valuesassert len(properties) == 1assert isinstance(properties[0], Property)@@ -359,12 +307,12 @@ def test_property_group_parsing_disables_code_variable_capture_for_reported_excedef fake_capture_exception(error, additional_properties=None):observed_context_values.append(get_capture_exception_code_variables_context())- filter = PropertiesTimelineFilter(data={"properties": [{"key": "attr", "value": "val_1"}, "not-a-mapping"]})+ entity = _entity({"properties": [{"key": "attr", "value": "val_1"}, "not-a-mapping"]})with patch("posthog.models.property.parse.capture_exception", side_effect=fake_capture_exception) as mock_capture_exception:- _ = filter.property_groups.values+ _ = entity.property_groups.valuesmock_capture_exception.assert_called_once()assert observed_context_values == [False]diff --git a/posthog/models/filters/mixins/utils.py b/posthog/models/filters/mixins/utils.pydeleted file mode 100644index d205ec03b64d..000000000000--- a/posthog/models/filters/mixins/utils.py+++ /dev/null@@ -1,28 +0,0 @@-from typing import Optional, Union--from posthog.utils import str_to_bool---def include_dict(f):- f.include_dict = True- return f---def include_query_tags(f):- """- Decorates a method and adds the result of it to query tags stored in `log_comment`- in system.query_log when querying insights.-- To get access to these tags, you might need to modify `metrics_query_log` schema.- """- f.include_query_tags = True- return f---def process_bool(bool_to_test: Optional[Union[str, bool]]) -> bool:- if isinstance(bool_to_test, bool):- return bool_to_test- elif isinstance(bool_to_test, str):- return str_to_bool(bool_to_test)- else:- return Falsediff --git a/posthog/models/filters/properties_timeline_filter.py b/posthog/models/filters/properties_timeline_filter.pydeleted file mode 100644index 7ed042ca02b2..000000000000--- a/posthog/models/filters/properties_timeline_filter.py+++ /dev/null@@ -1,17 +0,0 @@-from .base_filter import BaseFilter-from .mixins.common import BreakdownMixin, DisplayDerivedMixin, EntitiesMixin-from .mixins.groups import GroupsAggregationMixin-from .mixins.interval import IntervalMixin-from .mixins.property import PropertyMixin---class PropertiesTimelineFilter(- IntervalMixin,- EntitiesMixin,- PropertyMixin,- GroupsAggregationMixin,- DisplayDerivedMixin,- BreakdownMixin,- BaseFilter,-):- passdiff --git a/posthog/settings/shell_plus.py b/posthog/settings/shell_plus.pyindex 67d7449ebbd5..28f90a033cdc 100644--- a/posthog/settings/shell_plus.py+++ b/posthog/settings/shell_plus.py@@ -14,7 +14,6 @@ SHELL_PLUS_POST_IMPORTS = [),("django.utils.timezone", ("now",)),("infi.clickhouse_orm.utils", ("import_submodules",)),- ("posthog.models.filters", ("Filter",)),("posthog.models.property", ("Property",)),("posthog.clickhouse.client", ("sync_execute",)),("posthog.hogql", ("ast")),diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex fbdc9a840cbf..274eaccda94a 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -132831,18 +132831,6 @@ export namespace Schemas {Json: 'json',} as const;- export type PersonsPropertiesTimelineRetrieveParams = {- format?: PersonsPropertiesTimelineRetrieveFormat;- };-- export type PersonsPropertiesTimelineRetrieveFormat = typeof PersonsPropertiesTimelineRetrieveFormat[keyof typeof PersonsPropertiesTimelineRetrieveFormat];--- export const PersonsPropertiesTimelineRetrieveFormat = {- Csv: 'csv',- Json: 'json',- } as const;-export type PersonsPropertiesTimelineCreateParams = {format?: PersonsPropertiesTimelineCreateFormat;};