Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Dec 15, 2023
1 parent 6838e36 commit d2fbce4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 10 additions & 3 deletions posthog/queries/trends/breakdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
SESSION_DURATION_BREAKDOWN_INNER_SQL,
VOLUME_PER_ACTOR_BREAKDOWN_AGGREGATE_SQL,
VOLUME_PER_ACTOR_BREAKDOWN_INNER_SQL,
BREAKDOWN_PROP_JOIN_WITH_OTHER_SQL,
)
from posthog.queries.trends.util import (
COUNT_PER_ACTOR_MATH_FUNCTIONS,
Expand Down Expand Up @@ -460,20 +461,26 @@ def _breakdown_prop_params(self, aggregate_operation: str, math_params: Dict):
elif self.filter.breakdown_type == "session" and self.filter.breakdown == "$session_duration":
# Not adding "Other" for the custom session duration filter.
pass
elif not self.filter.breakdown_hide_other_aggregation:
else:
all_values_are_numeric = all(isinstance(value, int) or isinstance(value, float) for value in values_arr)
all_values_are_string = all(isinstance(value, str) for value in values_arr)

if all_values_are_numeric:
breakdown_other_value = BREAKDOWN_OTHER_NUMERIC_LABEL
elif not all_values_are_string:
breakdown_value = f"toString({breakdown_value})"

breakdown_value = f"transform({breakdown_value}, (%(values)s), (%(values)s), %(other_value)s)"

if self.filter.using_histogram:
sql_query = BREAKDOWN_HISTOGRAM_PROP_JOIN_SQL
elif self.filter.breakdown_hide_other_aggregation:
sql_query = BREAKDOWN_PROP_JOIN_SQL
else:
sql_query = BREAKDOWN_PROP_JOIN_WITH_OTHER_SQL

return (
{"values": values_arr, "other_value": breakdown_other_value},
BREAKDOWN_PROP_JOIN_SQL if not self.filter.using_histogram else BREAKDOWN_HISTOGRAM_PROP_JOIN_SQL,
sql_query,
{
"breakdown_value_expr": breakdown_value,
"numeric_property_filter": numeric_property_filter,
Expand Down
6 changes: 6 additions & 0 deletions posthog/queries/trends/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,14 @@
WHERE e.team_id = %(team_id)s {event_filter} {filters} {parsed_date_from_prev_range} {parsed_date_to} {actions_query} {null_person_filter}
"""

BREAKDOWN_PROP_JOIN_WITH_OTHER_SQL = """
WHERE e.team_id = %(team_id)s {event_filter} {filters} {parsed_date_from} {parsed_date_to} {null_person_filter}
{actions_query}
"""

BREAKDOWN_PROP_JOIN_SQL = """
WHERE e.team_id = %(team_id)s {event_filter} {filters} {parsed_date_from} {parsed_date_to} {null_person_filter}
AND {breakdown_value_expr} in (%(values)s)
{actions_query}
"""

Expand Down

0 comments on commit d2fbce4

Please sign in to comment.