Skip to content

Commit

Permalink
chore: removed custom trends session code (#18211)
Browse files Browse the repository at this point in the history
Removed custom trends session code
  • Loading branch information
Gilbert09 authored Oct 26, 2023
1 parent 578a602 commit 1fa2e0d
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 88 deletions.
8 changes: 0 additions & 8 deletions posthog/hogql_queries/insights/trends/breakdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from posthog.hogql import ast
from posthog.hogql.parser import parse_expr
from posthog.hogql.timings import HogQLTimings
from posthog.hogql_queries.insights.trends.breakdown_session import BreakdownSession
from posthog.hogql_queries.insights.trends.breakdown_values import BreakdownValues
from posthog.hogql_queries.insights.trends.utils import (
get_properties_chain,
Expand Down Expand Up @@ -173,15 +172,8 @@ def _get_breakdown_histogram_multi_if(self) -> ast.Expr:

@cached_property
def _properties_chain(self):
if self.is_session_type:
return self._breakdown_session.session_duration_property_chain()

return get_properties_chain(
breakdown_type=self.query.breakdown.breakdown_type,
breakdown_field=self.query.breakdown.breakdown,
group_type_index=self.query.breakdown.breakdown_group_type_index,
)

@cached_property
def _breakdown_session(self):
return BreakdownSession(self.query_date_range)
52 changes: 0 additions & 52 deletions posthog/hogql_queries/insights/trends/breakdown_session.py

This file was deleted.

11 changes: 0 additions & 11 deletions posthog/hogql_queries/insights/trends/breakdown_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
from posthog.hogql import ast
from posthog.hogql.parser import parse_expr, parse_select
from posthog.hogql.query import execute_hogql_query
from posthog.hogql_queries.insights.trends.breakdown_session import BreakdownSession
from posthog.hogql_queries.insights.trends.utils import get_properties_chain
from posthog.hogql_queries.utils.query_date_range import QueryDateRange
from posthog.models.filters.mixins.utils import cached_property
from posthog.models.team.team import Team


Expand Down Expand Up @@ -45,8 +43,6 @@ def get_breakdown_values(self) -> List[str]:
alias="value",
expr=parse_expr(self.breakdown_field),
)
elif self.breakdown_type == "session":
select_field = ast.Alias(alias="value", expr=self._breakdown_session.session_duration_field())
else:
select_field = ast.Alias(
alias="value",
Expand Down Expand Up @@ -92,9 +88,6 @@ def get_breakdown_values(self) -> List[str]:
if self.histogram_bin_count is not None:
query.select = [self._to_bucketing_expression()]

if self.breakdown_type == "session":
inner_events_query.select_from = self._breakdown_session.session_inner_join()

response = execute_hogql_query(
query_type="TrendsQueryBreakdownValues",
query=query,
Expand Down Expand Up @@ -145,7 +138,3 @@ def _to_bucketing_expression(self) -> ast.Expr:
qunatile_expression = f"quantiles({','.join([f'{quantile:.2f}' for quantile in quantiles])})(value)"

return parse_expr(f"arrayCompact(arrayMap(x -> floor(x, 2), {qunatile_expression}))")

@cached_property
def _breakdown_session(self):
return BreakdownSession(self.query_date_range)
17 changes: 0 additions & 17 deletions posthog/hogql_queries/insights/trends/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
AggregationOperations,
)
from posthog.hogql_queries.insights.trends.breakdown import Breakdown
from posthog.hogql_queries.insights.trends.breakdown_session import BreakdownSession
from posthog.hogql_queries.insights.trends.utils import series_event_name
from posthog.hogql_queries.utils.query_date_range import QueryDateRange
from posthog.models.filters.mixins.utils import cached_property
Expand Down Expand Up @@ -140,8 +139,6 @@ def _get_events_subquery(self) -> ast.SelectQuery:

orchestrator.events_query_builder.append_select(self._breakdown.column_expr())
orchestrator.events_query_builder.append_group_by(ast.Field(chain=["breakdown_value"]))
if self._breakdown.is_session_type:
orchestrator.events_query_builder.replace_select_from(self._breakdown_session.session_inner_join())

orchestrator.inner_select_query_builder.append_select(ast.Field(chain=["breakdown_value"]))
orchestrator.inner_select_query_builder.append_group_by(ast.Field(chain=["breakdown_value"]))
Expand All @@ -154,8 +151,6 @@ def _get_events_subquery(self) -> ast.SelectQuery:
default_query.select.append(self._breakdown.column_expr())
default_query.group_by.append(ast.Field(chain=["breakdown_value"]))

if self._breakdown.is_session_type:
default_query.select_from = self._breakdown_session.session_inner_join()
# Just complex series aggregation
elif self._aggregation_operation.requires_query_orchestration():
return self._aggregation_operation.get_query_orchestrator(
Expand Down Expand Up @@ -250,14 +245,6 @@ def _events_filter(self) -> ast.Expr:
# Breakdown
if self._breakdown.enabled and not self._breakdown.is_histogram_breakdown:
filters.append(self._breakdown.events_where_filter())
if self._breakdown.is_session_type:
filters.append(
ast.CompareOperation(
left=self._breakdown_session.session_duration_field(),
op=ast.CompareOperationOp.NotEq,
right=ast.Constant(value=None),
)
)

if len(filters) == 0:
return ast.Constant(value=True)
Expand All @@ -282,10 +269,6 @@ def _breakdown(self):
timings=self.timings,
)

@cached_property
def _breakdown_session(self):
return BreakdownSession(self.query_date_range)

@cached_property
def _aggregation_operation(self):
return AggregationOperations(self.series, self.query_date_range)
3 changes: 3 additions & 0 deletions posthog/hogql_queries/insights/trends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def get_properties_chain(
if breakdown_type == "person":
return ["person", "properties", breakdown_field]

if breakdown_type == "session":
return ["session", "session_duration"]

if breakdown_type == "group" and group_type_index is not None:
group_type_index_int = int(group_type_index)
return [f"group_{group_type_index_int}", "properties", breakdown_field]
Expand Down

0 comments on commit 1fa2e0d

Please sign in to comment.