diff --git a/posthog/hogql/database/database.py b/posthog/hogql/database/database.py index ce714239d43d7..0927e8f7d5ac3 100644 --- a/posthog/hogql/database/database.py +++ b/posthog/hogql/database/database.py @@ -45,10 +45,6 @@ RawPersonDistinctIdsTable, ) from posthog.hogql.database.schema.persons import PersonsTable, RawPersonsTable, join_with_persons_table -from posthog.hogql.database.schema.person_overrides import ( - PersonOverridesTable, - RawPersonOverridesTable, -) from posthog.hogql.database.schema.session_replay_events import ( RawSessionReplayEventsTable, SessionReplayEventsTable, @@ -92,7 +88,6 @@ class Database(BaseModel): persons: PersonsTable = PersonsTable() person_distinct_ids: PersonDistinctIdsTable = PersonDistinctIdsTable() person_distinct_id_overrides: PersonDistinctIdOverridesTable = PersonDistinctIdOverridesTable() - person_overrides: PersonOverridesTable = PersonOverridesTable() session_replay_events: SessionReplayEventsTable = SessionReplayEventsTable() cohort_people: CohortPeople = CohortPeople() @@ -109,7 +104,6 @@ class Database(BaseModel): raw_groups: RawGroupsTable = RawGroupsTable() raw_cohort_people: RawCohortPeople = RawCohortPeople() raw_person_distinct_id_overrides: RawPersonDistinctIdOverridesTable = RawPersonDistinctIdOverridesTable() - raw_person_overrides: RawPersonOverridesTable = RawPersonOverridesTable() raw_sessions: RawSessionsTable = RawSessionsTable() # system tables @@ -121,7 +115,6 @@ class Database(BaseModel): "groups", "persons", "person_distinct_ids", - "person_overrides", "session_replay_events", "cohort_people", "static_cohort_people", diff --git a/posthog/hogql/database/schema/person_overrides.py b/posthog/hogql/database/schema/person_overrides.py deleted file mode 100644 index ee2854c91b05d..0000000000000 --- a/posthog/hogql/database/schema/person_overrides.py +++ /dev/null @@ -1,84 +0,0 @@ -from posthog.hogql.ast import SelectQuery -from posthog.hogql.context import HogQLContext - -from posthog.hogql.database.argmax import argmax_select -from posthog.hogql.database.models import ( - Table, - StringDatabaseField, - DateTimeDatabaseField, - IntegerDatabaseField, - FieldOrTable, - LazyTableToAdd, - LazyJoinToAdd, -) - -from posthog.hogql.errors import ResolutionError -from posthog.schema import HogQLQueryModifiers - -PERSON_OVERRIDES_FIELDS: dict[str, FieldOrTable] = { - "team_id": IntegerDatabaseField(name="team_id"), - "old_person_id": StringDatabaseField(name="old_person_id"), - "override_person_id": StringDatabaseField(name="override_person_id"), - "oldest_event": DateTimeDatabaseField(name="oldest_event"), - "merged_at": DateTimeDatabaseField(name="merged_at"), - "created_at": DateTimeDatabaseField(name="created_at"), -} - - -def select_from_person_overrides_table(requested_fields: dict[str, list[str | int]]): - return argmax_select( - table_name="raw_person_overrides", - select_fields=requested_fields, - group_fields=["old_person_id"], - argmax_field="version", - ) - - -def join_with_person_overrides_table( - join_to_add: LazyJoinToAdd, - context: HogQLContext, - node: SelectQuery, -): - from posthog.hogql import ast - - if not join_to_add.fields_accessed: - raise ResolutionError("No fields requested from person_distinct_ids") - - join_expr = ast.JoinExpr(table=select_from_person_overrides_table(join_to_add.fields_accessed)) - join_expr.join_type = "LEFT OUTER JOIN" - join_expr.alias = join_to_add.to_table - join_expr.constraint = ast.JoinConstraint( - expr=ast.CompareOperation( - op=ast.CompareOperationOp.Eq, - left=ast.Field(chain=[join_to_add.from_table, "event_person_id"]), - right=ast.Field(chain=[join_to_add.to_table, "old_person_id"]), - ), - constraint_type="ON", - ) - return join_expr - - -class RawPersonOverridesTable(Table): - fields: dict[str, FieldOrTable] = { - **PERSON_OVERRIDES_FIELDS, - "version": IntegerDatabaseField(name="version"), - } - - def to_printed_clickhouse(self, context): - return "person_overrides" - - def to_printed_hogql(self): - return "raw_person_overrides" - - -class PersonOverridesTable(Table): - fields: dict[str, FieldOrTable] = PERSON_OVERRIDES_FIELDS - - def lazy_select(self, table_to_add: LazyTableToAdd, modifiers: HogQLQueryModifiers): - return select_from_person_overrides_table(table_to_add.fields_accessed) - - def to_printed_clickhouse(self, context): - return "person_overrides" - - def to_printed_hogql(self): - return "person_overrides" diff --git a/posthog/hogql/database/test/__snapshots__/test_database.ambr b/posthog/hogql/database/test/__snapshots__/test_database.ambr index 43195bcc2d358..052df674a93b8 100644 --- a/posthog/hogql/database/test/__snapshots__/test_database.ambr +++ b/posthog/hogql/database/test/__snapshots__/test_database.ambr @@ -552,58 +552,6 @@ "name": "person_distinct_ids", "type": "posthog" }, - "person_overrides": { - "fields": { - "old_person_id": { - "chain": null, - "fields": null, - "hogql_value": "old_person_id", - "name": "old_person_id", - "schema_valid": true, - "table": null, - "type": "string" - }, - "override_person_id": { - "chain": null, - "fields": null, - "hogql_value": "override_person_id", - "name": "override_person_id", - "schema_valid": true, - "table": null, - "type": "string" - }, - "oldest_event": { - "chain": null, - "fields": null, - "hogql_value": "oldest_event", - "name": "oldest_event", - "schema_valid": true, - "table": null, - "type": "datetime" - }, - "merged_at": { - "chain": null, - "fields": null, - "hogql_value": "merged_at", - "name": "merged_at", - "schema_valid": true, - "table": null, - "type": "datetime" - }, - "created_at": { - "chain": null, - "fields": null, - "hogql_value": "created_at", - "name": "created_at", - "schema_valid": true, - "table": null, - "type": "datetime" - } - }, - "id": "person_overrides", - "name": "person_overrides", - "type": "posthog" - }, "session_replay_events": { "fields": { "session_id": { @@ -1912,58 +1860,6 @@ "name": "person_distinct_ids", "type": "posthog" }, - "person_overrides": { - "fields": { - "old_person_id": { - "chain": null, - "fields": null, - "hogql_value": "old_person_id", - "name": "old_person_id", - "schema_valid": true, - "table": null, - "type": "string" - }, - "override_person_id": { - "chain": null, - "fields": null, - "hogql_value": "override_person_id", - "name": "override_person_id", - "schema_valid": true, - "table": null, - "type": "string" - }, - "oldest_event": { - "chain": null, - "fields": null, - "hogql_value": "oldest_event", - "name": "oldest_event", - "schema_valid": true, - "table": null, - "type": "datetime" - }, - "merged_at": { - "chain": null, - "fields": null, - "hogql_value": "merged_at", - "name": "merged_at", - "schema_valid": true, - "table": null, - "type": "datetime" - }, - "created_at": { - "chain": null, - "fields": null, - "hogql_value": "created_at", - "name": "created_at", - "schema_valid": true, - "table": null, - "type": "datetime" - } - }, - "id": "person_overrides", - "name": "person_overrides", - "type": "posthog" - }, "session_replay_events": { "fields": { "session_id": {