Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(trends): legacy considers '' breakdown as null #21159

Merged
merged 10 commits into from
Mar 27, 2024
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
Loading