Skip to content

Commit

Permalink
chore: remove event properties from subquery (#24558)
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin authored Aug 27, 2024
1 parent 26e3e0e commit 547d9f5
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import re
from typing import Any, NamedTuple, cast, Optional, Union
from datetime import datetime, timedelta

Expand All @@ -21,10 +20,6 @@
logger = structlog.get_logger(__name__)


def is_event_property(p: Property) -> bool:
return p.type == "event" or (p.type == "hogql" and bool(re.search(r"(?<!person\.)properties\.", p.key)))


def is_person_property(p: Property) -> bool:
return p.type == "person" or (p.type == "hogql" and "person.properties" in p.key)

Expand Down Expand Up @@ -239,9 +234,7 @@ def _having_predicates(self) -> ast.Expr:
return property_to_expr(self._filter.having_predicates, team=self._team, scope="replay")

def _strip_person_and_event_properties(self, property_group: PropertyGroup) -> PropertyGroup | None:
property_groups_to_keep = [
g for g in property_group.flat if not is_event_property(g) and not is_person_property(g)
]
property_groups_to_keep = [g for g in property_group.flat if not is_person_property(g)]

return (
PropertyGroup(
Expand Down Expand Up @@ -427,7 +420,7 @@ def _select_from_events(self, select_expr: ast.Expr) -> ast.SelectQuery:

def get_query_for_session_id_matching(self) -> ast.SelectQuery | ast.SelectUnionQuery | None:
use_poe = poe_is_active(self._team) and self.person_properties
if self._filter.entities or self.event_properties or use_poe:
if self._filter.entities or use_poe:
return self._select_from_events(ast.Alias(alias="session_id", expr=ast.Field(chain=["$session_id"])))
else:
return None
Expand Down Expand Up @@ -497,9 +490,6 @@ def _where_predicates(self) -> ast.Expr:
if event_where_exprs:
exprs.append(self._filter.events_operand(exprs=event_where_exprs))

if self.event_properties:
exprs.append(property_to_expr(self.event_properties, team=self._team, scope="replay"))

if self._team.person_on_events_mode and self.person_properties:
exprs.append(property_to_expr(self.person_properties, team=self._team, scope="event"))

Expand Down Expand Up @@ -529,10 +519,6 @@ def _having_predicates(self) -> ast.Expr:

return ast.Constant(value=True)

@cached_property
def event_properties(self):
return [g for g in self._filter.property_groups.flat if is_event_property(g)]

@cached_property
def person_properties(self) -> PropertyGroup | None:
person_property_groups = [g for g in self._filter.property_groups.flat if is_person_property(g)]
Expand Down
Loading

0 comments on commit 547d9f5

Please sign in to comment.