Skip to content

Commit

Permalink
fix: Unsupported constant type (#25413)
Browse files Browse the repository at this point in the history
  • Loading branch information
timgl authored Oct 5, 2024
1 parent afdca61 commit c80a904
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions posthog/hogql/functions/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def compare_types(arg_types: list[ConstantType], sig_arg_types: tuple[ConstantTy
"parseDateTime": HogQLFunctionMeta("parseDateTimeOrNull", 2, 3, tz_aware=True),
"parseDateTimeBestEffort": HogQLFunctionMeta("parseDateTime64BestEffortOrNull", 1, 2, tz_aware=True),
"toTypeName": HogQLFunctionMeta("toTypeName", 1, 1),
"cityHash64": HogQLFunctionMeta("cityHash64", 1, 1),
# dates and times
"toTimeZone": HogQLFunctionMeta("toTimeZone", 2, 2),
"timeZoneOf": HogQLFunctionMeta("timeZoneOf", 1, 1),
Expand Down
20 changes: 9 additions & 11 deletions posthog/hogql_queries/events_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,15 @@ def to_query(self) -> ast.SelectQuery:
Person.objects.filter(team=self.team), self.query.personId
).first()
where_exprs.append(
parse_expr(
"cityHash64(distinct_id) in {list}", # Because the events table is partitioned by cityHash64(distinct_ids), using cityhash for the comparison is much quicker,
{
"list": ast.Constant(
value=[
ast.Call(name="cityHash64", args=[ast.Constant(value=id)])
for id in get_distinct_ids_for_subquery(person, self.team)
]
)
},
timings=self.timings,
ast.CompareOperation(
left=ast.Call(name="cityHash64", args=[ast.Field(chain=["distinct_id"])]),
right=ast.Tuple(
exprs=[
ast.Call(name="cityHash64", args=[ast.Constant(value=id)])
for id in get_distinct_ids_for_subquery(person, self.team)
]
),
op=ast.CompareOperationOp.In,
)
)
if self.query.filterTestAccounts:
Expand Down
8 changes: 4 additions & 4 deletions posthog/hogql_queries/test/test_events_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ def test_person_id_expands_to_distinct_ids(self):
# matching team
query_ast = EventsQueryRunner(query=query, team=self.team).to_query()
where_expr = cast(ast.CompareOperation, cast(ast.And, query_ast.where).exprs[0])
right_expr = cast(ast.Constant, where_expr.right)
self.assertEqual([x.args[0].value for x in right_expr.value], ["id1", "id2"])
right_expr = cast(ast.Tuple, where_expr.right)
self.assertEqual([x.args[0].value for x in right_expr.exprs], ["id1", "id2"])

Check failure on line 134 in posthog/hogql_queries/test/test_events_query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

"Expr" has no attribute "args"

# another team
another_team = Team.objects.create(organization=Organization.objects.create())
query_ast = EventsQueryRunner(query=query, team=another_team).to_query()
where_expr = cast(ast.CompareOperation, cast(ast.And, query_ast.where).exprs[0])
right_expr = cast(ast.Constant, where_expr.right)
self.assertEqual(right_expr.value, [])
right_expr = cast(ast.Tuple, where_expr.right)
self.assertEqual(right_expr.exprs, [])

def test_test_account_filters(self):
self.team.test_account_filters = [
Expand Down

0 comments on commit c80a904

Please sign in to comment.