Skip to content

Commit

Permalink
feat(web-analytics): Support null as string in channel type (#21136)
Browse files Browse the repository at this point in the history
Support null as string in channel type
  • Loading branch information
robbie-c authored Mar 25, 2024
1 parent d226bd0 commit 652b75d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion posthog/hogql/database/schema/channel_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def create_channel_type_expr(
gad_source: ast.Expr,
) -> ast.Expr:
def wrap_with_null_if_empty(expr: ast.Expr) -> ast.Expr:
return ast.Call(name="nullIf", args=[expr, ast.Constant(value="")])
return ast.Call(
name="nullIf",
args=[ast.Call(name="nullIf", args=[expr, ast.Constant(value="")]), ast.Constant(value="null")],
)

return parse_expr(
"""
Expand Down
15 changes: 15 additions & 0 deletions posthog/hogql/database/schema/test/test_channel_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ def test_direct_empty_string(self):
),
)

def test_direct_null_string(self):
self.assertEqual(
"Direct",
self._get_initial_channel_type(
{
"$initial_referring_domain": "$direct",
"$initial_utm_source": "null",
"$initial_utm_medium": "null",
"$initial_utm_campaign": "null",
"$initial_gclid": "null",
"$initial_gad_source": "null",
}
),
)

def test_cross_network(self):
self.assertEqual(
"Cross Network",
Expand Down

0 comments on commit 652b75d

Please sign in to comment.