Skip to content

Commit

Permalink
WIP: start adding old trends tests against new query runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilbert09 committed Nov 10, 2023
1 parent d79002a commit 4b33ada
Show file tree
Hide file tree
Showing 6 changed files with 8,646 additions and 10 deletions.
8 changes: 6 additions & 2 deletions posthog/hogql_queries/insights/trends/breakdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ def column_expr(self) -> ast.Expr:
expr=parse_expr(self.query.breakdown.breakdown),
)
elif self.query.breakdown.breakdown_type == "cohort":
cohort_breakdown = 0 if self.query.breakdown.breakdown == "all" else int(self.query.breakdown.breakdown)
return ast.Alias(
alias="breakdown_value",
expr=ast.Constant(value=int(self.query.breakdown.breakdown)),
expr=ast.Constant(value=cohort_breakdown),
)

if self.query.breakdown.breakdown_type == "hogql":
Expand All @@ -76,8 +77,11 @@ def column_expr(self) -> ast.Expr:
expr=ast.Field(chain=self._properties_chain),
)

def events_where_filter(self) -> ast.Expr:
def events_where_filter(self) -> ast.Expr | None:
if self.query.breakdown.breakdown_type == "cohort":
if self.query.breakdown.breakdown == "all":
return None

return ast.CompareOperation(
left=ast.Field(chain=["person_id"]),
op=ast.CompareOperationOp.InCohort,
Expand Down
3 changes: 3 additions & 0 deletions posthog/hogql_queries/insights/trends/breakdown_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def __init__(

def get_breakdown_values(self) -> List[str | int]:
if self.breakdown_type == "cohort":
if self.breakdown_field == "all":
return [0]

return [int(self.breakdown_field)]

if self.breakdown_type == "hogql":
Expand Down
6 changes: 1 addition & 5 deletions posthog/hogql_queries/insights/trends/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ def should_wrap_inner_query(self) -> bool:
return self.display_type == ChartDisplayType.ActionsLineGraphCumulative

def modify_outer_query(self, outer_query: ast.SelectQuery, inner_query: ast.SelectQuery) -> ast.SelectQuery:
if (
self.display_type == ChartDisplayType.BoldNumber
or self.display_type == ChartDisplayType.ActionsPie
or self.display_type == ChartDisplayType.WorldMap
):
if self.should_aggregate_values():
return ast.SelectQuery(
select=[
ast.Alias(
Expand Down
4 changes: 3 additions & 1 deletion posthog/hogql_queries/insights/trends/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ 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())
breakdown_filter = self._breakdown.events_where_filter()
if breakdown_filter is not None:
filters.append(breakdown_filter)

if len(filters) == 0:
return ast.Constant(value=True)
Expand Down
Loading

0 comments on commit 4b33ada

Please sign in to comment.