Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP #26947

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

WIP #26947

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions posthog/hogql/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from posthog.hogql.database.schema.person_distinct_ids import (
PersonDistinctIdsTable,
RawPersonDistinctIdsTable,
join_with_person_distinct_ids_table,
)
from posthog.hogql.database.schema.persons import (
PersonsTable,
Expand Down Expand Up @@ -457,6 +458,15 @@
),
)

if "events" in join.joining_table_name and join.configuration.get("experiments_optimized"):
source_table.fields["pdi"] = LazyJoin(

Check failure on line 462 in posthog/hogql/database/database.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Unexpected keyword argument "override_source_table_key" for "LazyJoin"
from_field=from_field,
join_table=PersonDistinctIdsTable(),
join_function=join_with_person_distinct_ids_table,
override_source_table_key=join.source_table_key,
)
source_table.fields["person"] = FieldTraverser(chain=["pdi", "person"])

if join.source_table_name == "persons":
person_field = database.events.fields["person"]
if isinstance(person_field, ast.FieldTraverser):
Expand Down
5 changes: 4 additions & 1 deletion posthog/hogql/database/schema/person_distinct_ids.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional
from posthog.hogql.ast import SelectQuery
from posthog.hogql.constants import HogQLQuerySettings
from posthog.hogql.context import HogQLContext
Expand Down Expand Up @@ -48,18 +49,20 @@ def join_with_person_distinct_ids_table(
join_to_add: LazyJoinToAdd,
context: HogQLContext,
node: SelectQuery,
override_source_table_key: Optional[str] = None,
):
from posthog.hogql import ast

if not join_to_add.fields_accessed:
raise ResolutionError("No fields requested from person_distinct_ids")
source_table_key = override_source_table_key or "distinct_id"
join_expr = ast.JoinExpr(table=select_from_person_distinct_ids_table(join_to_add.fields_accessed))
join_expr.join_type = "INNER 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, "distinct_id"]),
left=ast.Field(chain=[join_to_add.from_table, source_table_key]),
right=ast.Field(chain=[join_to_add.to_table, "distinct_id"]),
),
constraint_type="ON",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,6 @@ def create_data_warehouse_table_with_usage(self):
field_name="events",
configuration={"experiments_optimized": True, "experiments_timestamp_key": "ds"},
)

DataWarehouseJoin.objects.create(
team=self.team,
source_table_name=table_name,
source_table_key="userid",
joining_table_name="persons",
joining_table_key="properties.$user_id",
field_name="person",
)
return table_name

@freeze_time("2020-01-01T12:00:00Z")
Expand Down Expand Up @@ -869,8 +860,9 @@ def test_query_runner_with_data_warehouse_series_no_end_date_and_nested_id(self)

_create_person(
team=self.team,
distinct_ids=["internal_test_1"],
properties={"email": "internal_test_1@posthog.com", "$user_id": "internal_test_1"},
uuid="018f14b8-6cf3-7ffd-80bb-5ef1a9e4d328",
distinct_ids=["018f14b8-6cf3-7ffd-80bb-5ef1a9e4d328", "internal_test_1"],
properties={"email": "internal_test_1@posthog.com"},
)

_create_event(
Expand Down
Loading