-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hogql): Add basic support for PoE v3 (distinct ID overrides) (#2…
- Loading branch information
Showing
10 changed files
with
246 additions
and
2 deletions.
There are no files selected for viewing
Binary file modified
BIN
+55 Bytes
(100%)
...nd/__snapshots__/scenes-app-insights--funnel-top-to-bottom-breakdown--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
posthog/hogql/database/schema/person_distinct_id_overrides.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from typing import Dict, List | ||
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, | ||
IntegerDatabaseField, | ||
StringDatabaseField, | ||
BooleanDatabaseField, | ||
LazyJoin, | ||
LazyTable, | ||
FieldOrTable, | ||
) | ||
from posthog.hogql.database.schema.persons import join_with_persons_table | ||
from posthog.hogql.errors import HogQLException | ||
from posthog.schema import HogQLQueryModifiers | ||
|
||
PERSON_DISTINCT_ID_OVERRIDES_FIELDS = { | ||
"team_id": IntegerDatabaseField(name="team_id"), | ||
"distinct_id": StringDatabaseField(name="distinct_id"), | ||
"person_id": StringDatabaseField(name="person_id"), | ||
"person": LazyJoin( | ||
from_field=["person_id"], | ||
join_table="persons", | ||
join_function=join_with_persons_table, | ||
), | ||
} | ||
|
||
|
||
def select_from_person_distinct_id_overrides_table(requested_fields: Dict[str, List[str | int]]): | ||
# Always include "person_id", as it's the key we use to make further joins, and it'd be great if it's available | ||
if "person_id" not in requested_fields: | ||
requested_fields = {**requested_fields, "person_id": ["person_id"]} | ||
return argmax_select( | ||
table_name="raw_person_distinct_id_overrides", | ||
select_fields=requested_fields, | ||
group_fields=["distinct_id"], | ||
argmax_field="version", | ||
deleted_field="is_deleted", | ||
) | ||
|
||
|
||
def join_with_person_distinct_id_overrides_table( | ||
from_table: str, | ||
to_table: str, | ||
requested_fields: Dict[str, List[str]], | ||
context: HogQLContext, | ||
node: SelectQuery, | ||
): | ||
from posthog.hogql import ast | ||
|
||
if not requested_fields: | ||
raise HogQLException("No fields requested from person_distinct_id_overrides") | ||
join_expr = ast.JoinExpr(table=select_from_person_distinct_id_overrides_table(requested_fields)) | ||
join_expr.join_type = "LEFT OUTER JOIN" | ||
join_expr.alias = to_table | ||
join_expr.constraint = ast.JoinConstraint( | ||
expr=ast.CompareOperation( | ||
op=ast.CompareOperationOp.Eq, | ||
left=ast.Field(chain=[from_table, "distinct_id"]), | ||
right=ast.Field(chain=[to_table, "distinct_id"]), | ||
) | ||
) | ||
return join_expr | ||
|
||
|
||
class RawPersonDistinctIdOverridesTable(Table): | ||
fields: Dict[str, FieldOrTable] = { | ||
**PERSON_DISTINCT_ID_OVERRIDES_FIELDS, | ||
"is_deleted": BooleanDatabaseField(name="is_deleted"), | ||
"version": IntegerDatabaseField(name="version"), | ||
} | ||
|
||
def to_printed_clickhouse(self, context): | ||
return "person_distinct_id_overrides" | ||
|
||
def to_printed_hogql(self): | ||
return "raw_person_distinct_id_overrides" | ||
|
||
|
||
class PersonDistinctIdOverridesTable(LazyTable): | ||
fields: Dict[str, FieldOrTable] = PERSON_DISTINCT_ID_OVERRIDES_FIELDS | ||
|
||
def lazy_select(self, requested_fields: Dict[str, List[str | int]], modifiers: HogQLQueryModifiers): | ||
Check failure on line 85 in posthog/hogql/database/schema/person_distinct_id_overrides.py GitHub Actions / Python code quality checks
Check failure on line 85 in posthog/hogql/database/schema/person_distinct_id_overrides.py GitHub Actions / Python code quality checks
Check failure on line 85 in posthog/hogql/database/schema/person_distinct_id_overrides.py GitHub Actions / Python code quality checks
Check failure on line 85 in posthog/hogql/database/schema/person_distinct_id_overrides.py GitHub Actions / Python code quality checks
|
||
return select_from_person_distinct_id_overrides_table(requested_fields) | ||
|
||
def to_printed_clickhouse(self, context): | ||
return "person_distinct_id_overrides" | ||
|
||
def to_printed_hogql(self): | ||
return "person_distinct_id_overrides" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters