Skip to content

Commit

Permalink
overrides kind of work
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Nov 23, 2023
1 parent 05cef3d commit cb47675
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
6 changes: 3 additions & 3 deletions posthog/hogql/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ def create_hogql_database(team_id: int, modifiers: Optional[HogQLQueryModifiers]
database.events.fields["person_id"] = StringDatabaseField(name="person_id")

elif modifiers.personsOnEventsMode == PersonsOnEventsMode.v2_enabled:
database.events.fields["old_person_id"] = StringDatabaseField(name="person_id")
database.events.fields["event_person_id"] = StringDatabaseField(name="person_id")
database.events.fields["override"] = LazyJoin(
from_field="old_person_id",
from_field="event_person_id",
join_table=PersonOverridesTable(),
join_function=join_with_person_overrides_table,
)
database.events.fields["person_id"] = ExpressionField(
name="person_id",
expr=parse_expr("ifNull(override_person_id, old_person_id)", start=None),
expr=parse_expr("ifNull(override.override_person_id, event_person_id)", start=None),
return_type=UUIDType(),
)
database.events.fields["person"] = FieldTraverser(chain=["poe"])
Expand Down
11 changes: 0 additions & 11 deletions posthog/hogql/database/schema/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
PersonDistinctIdsTable,
join_with_person_distinct_ids_table,
)
from posthog.hogql.database.schema.person_overrides import (
PersonOverridesTable,
join_with_person_overrides_table,
)


class EventsPersonSubTable(VirtualTable):
Expand Down Expand Up @@ -77,13 +73,6 @@ class EventsTable(Table):
join_table=PersonDistinctIdsTable(),
join_function=join_with_person_distinct_ids_table,
),
# Lazy table to fetch the overridden person_id
"override": LazyJoin(
from_field="person_id",
join_table=PersonOverridesTable(),
join_function=join_with_person_overrides_table,
),
"override_person_id": FieldTraverser(chain=["override", "override_person_id"]),
# Person and group fields on the event itself. Should not be used directly.
"poe": EventsPersonSubTable(),
"goe_0": EventsGroupSubTable(group_index=0),
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql/database/schema/person_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def join_with_person_overrides_table(
join_expr.constraint = ast.JoinConstraint(
expr=ast.CompareOperation(
op=ast.CompareOperationOp.Eq,
left=ast.Field(chain=[from_table, "person_id"]),
left=ast.Field(chain=[from_table, "event_person_id"]),
right=ast.Field(chain=[to_table, "old_person_id"]),
)
)
Expand Down
6 changes: 3 additions & 3 deletions posthog/hogql/functions/test/test_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _create_random_events(self) -> str:
flush_persons_and_events()
return random_uuid

@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=True)
@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=False)
def test_in_cohort_dynamic(self):
random_uuid = self._create_random_events()
cohort = Cohort.objects.create(
Expand All @@ -58,7 +58,7 @@ def test_in_cohort_dynamic(self):
self.assertEqual(len(response.results), 1)
self.assertEqual(response.results[0][0], random_uuid)

@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=True)
@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=False)
def test_in_cohort_static(self):
cohort = Cohort.objects.create(
team=self.team,
Expand All @@ -78,7 +78,7 @@ def test_in_cohort_static(self):
f"SELECT event FROM events WHERE in(person_id, (SELECT person_id FROM static_cohort_people WHERE equals(cohort_id, {cohort.pk}))) LIMIT 100",
)

@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=True)
@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=False)
def test_in_cohort_strings(self):
cohort = Cohort.objects.create(
team=self.team,
Expand Down
6 changes: 3 additions & 3 deletions posthog/hogql/transforms/test/test_in_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _create_random_events(self) -> str:
flush_persons_and_events()
return random_uuid

@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=True)
@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=False)
def test_in_cohort_dynamic(self):
random_uuid = self._create_random_events()
cohort = Cohort.objects.create(
Expand All @@ -58,7 +58,7 @@ def test_in_cohort_dynamic(self):
self.assertEqual(len(response.results), 1)
self.assertEqual(response.results[0][0], random_uuid)

@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=True)
@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=False)
def test_in_cohort_static(self):
cohort = Cohort.objects.create(
team=self.team,
Expand All @@ -78,7 +78,7 @@ def test_in_cohort_static(self):
f"SELECT event FROM events LEFT JOIN (SELECT person_id, 1 AS matched FROM static_cohort_people WHERE equals(cohort_id, {cohort.pk})) AS in_cohort__{cohort.pk} ON equals(in_cohort__{cohort.pk}.person_id, person_id) WHERE equals(in_cohort__{cohort.pk}.matched, 1) LIMIT 100",
)

@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=True)
@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=False)
def test_in_cohort_strings(self):
cohort = Cohort.objects.create(
team=self.team,
Expand Down

0 comments on commit cb47675

Please sign in to comment.