Skip to content

Commit

Permalink
fix(trends): legacy considers '' breakdown as null (#21159)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra authored Mar 27, 2024
1 parent 0892e5b commit e027202
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 62 deletions.
36 changes: 18 additions & 18 deletions posthog/hogql_queries/insights/trends/breakdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,14 @@ def events_where_filter(self) -> ast.Expr | None:
left=transform_func, op=ast.CompareOperationOp.Eq, right=ast.Constant(value=value)
)
)
elif value == BREAKDOWN_NULL_STRING_LABEL:
compare_ops.append(
ast.CompareOperation(left=left, op=ast.CompareOperationOp.Eq, right=ast.Constant(value=None))
)
compare_ops.append(
ast.CompareOperation(left=left, op=ast.CompareOperationOp.Eq, right=ast.Constant(value=""))
)
else:
if value == BREAKDOWN_NULL_STRING_LABEL:
value = None

compare_ops.append(
ast.CompareOperation(left=left, op=ast.CompareOperationOp.Eq, right=ast.Constant(value=value))
)
Expand All @@ -172,21 +176,17 @@ def _get_breakdown_transform_func(self) -> ast.Call:
return self._get_breakdown_values_transform(ast.Field(chain=self._properties_chain))

def _get_breakdown_values_transform(self, node: ast.Expr) -> ast.Call:
breakdown_values = self._breakdown_values_ast
return ast.Call(
name="transform",
args=[
ast.Call(
name="ifNull",
args=[
hogql_to_string(node),
ast.Constant(value=BREAKDOWN_NULL_STRING_LABEL),
],
),
breakdown_values,
breakdown_values,
ast.Constant(value=BREAKDOWN_OTHER_STRING_LABEL),
],
return cast(
ast.Call,
parse_expr(
"transform(ifNull(nullIf(toString({node}), ''), {nil}), {values}, {values}, {other})",
placeholders={
"node": node,
"values": self._breakdown_values_ast,
"nil": ast.Constant(value=BREAKDOWN_NULL_STRING_LABEL),
"other": ast.Constant(value=BREAKDOWN_OTHER_STRING_LABEL),
},
),
)

@cached_property
Expand Down
Loading

0 comments on commit e027202

Please sign in to comment.