Skip to content

Commit

Permalink
Merge branch 'master' into feat/delay-survey-popup
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarticus authored Jun 18, 2024
2 parents c127648 + d155529 commit cd7cc7f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 74 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"pmtiles": "^2.11.0",
"postcss": "^8.4.31",
"postcss-preset-env": "^9.3.0",
"posthog-js": "1.139.2",
"posthog-js": "1.139.3",
"posthog-js-lite": "3.0.0",
"prettier": "^2.8.8",
"prop-types": "^15.7.2",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions posthog/hogql_queries/insights/trends/aggregation_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from posthog.hogql_queries.utils.query_date_range import QueryDateRange
from posthog.models.team.team import Team
from posthog.schema import BaseMathType, ChartDisplayType, EventsNode, ActionsNode, DataWarehouseNode
from posthog.models.filters.mixins.utils import cached_property
from posthog.hogql_queries.insights.data_warehouse_mixin import DataWarehouseInsightQueryMixin


Expand Down Expand Up @@ -71,18 +70,11 @@ def __init__(
self.query_date_range = query_date_range
self.is_total_value = is_total_value

@cached_property
def _id_field(self) -> ast.Expr:
if isinstance(self.series, DataWarehouseNode):
return ast.Field(chain=["e", self.series.id_field])

return ast.Field(chain=["e", "uuid"])

def select_aggregation(self) -> ast.Expr:
if self.series.math == "hogql" and self.series.math_hogql is not None:
return parse_expr(self.series.math_hogql)
elif self.series.math == "total":
return parse_expr("count({id_field})", placeholders={"id_field": self._id_field})
return parse_expr("count()")
elif self.series.math == "dau":
actor = "e.distinct_id" if self.team.aggregate_users_by_distinct_id else "e.person_id"
return parse_expr(f"count(DISTINCT {actor})")
Expand Down Expand Up @@ -112,9 +104,7 @@ def select_aggregation(self) -> ast.Expr:
elif self.series.math == "p99":
return self._math_quantile(0.99, None)

return parse_expr(
"count({id_field})", placeholders={"id_field": self._id_field}
) # All "count per actor" get replaced during query orchestration
return parse_expr("count()") # All "count per actor" get replaced during query orchestration

def actor_id(self) -> ast.Expr:
if self.series.math == "unique_group" and self.series.math_group_type_index is not None:
Expand Down Expand Up @@ -367,23 +357,22 @@ def _events_query(
(
"""
SELECT
count({id_field}) AS total
count() AS total
FROM {table} AS e
WHERE {events_where_clause}
GROUP BY {person_field}
"""
if isinstance(self.series, DataWarehouseNode)
else """
SELECT
count({id_field}) AS total
count() AS total
FROM events AS e
SAMPLE {sample}
WHERE {events_where_clause}
GROUP BY {person_field}
"""
),
placeholders={
"id_field": self._id_field,
"table": self._table_expr,
"events_where_clause": where_clause_combined,
"sample": sample_value,
Expand Down
Loading

0 comments on commit cd7cc7f

Please sign in to comment.