Skip to content

Commit

Permalink
tet
Browse files Browse the repository at this point in the history
  • Loading branch information
aspicer committed Dec 5, 2024
1 parent f04d14c commit 1320bac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions frontend/src/scenes/trends/persons-modal/personsModalLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export const personsModalLogic = kea<personsModalLogicType>([
() => [(_, p) => p.additionalSelect],
(additionalSelect: PersonModalLogicProps['additionalSelect']): string[] => {
const extra = Object.values(additionalSelect || {})
return ['actor', 'created_at', ...extra]
return ['actor', ...extra]
},
],
actorsQuery: [
Expand All @@ -344,7 +344,7 @@ export const personsModalLogic = kea<personsModalLogicType>([
kind: NodeKind.ActorsQuery,
source: query,
select: selectFields,
orderBy: orderBy || ['created_at DESC'],
orderBy: orderBy || [],
search: searchTerm,
}
},
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/actor_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_actors(self, actor_ids, order_by: str = "") -> dict[str, dict]:
return person_uuid_to_person

def input_columns(self) -> list[str]:
return ["person", "id", "created_at", "person.$delete"]
return ["person", "id", "person.$delete"]

def filter_conditions(self) -> list[ast.Expr]:
where_exprs: list[ast.Expr] = []
Expand Down
18 changes: 17 additions & 1 deletion posthog/hogql_queries/actors_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ def to_query(self) -> ast.SelectQuery:
columns = []
group_by = []
aggregations = []
joinless_fields = ("actor", self.strategy.field, self.strategy.origin_id)
requires_join = False
for expr in self.input_columns():
column: ast.Expr = parse_expr(expr)

Expand All @@ -202,6 +204,10 @@ def to_query(self) -> ast.SelectQuery:
# like `groupUniqArray(100)(tuple(timestamp, uuid, `$session_id`, `$window_id`)) AS matching_events`
# we look up valid session ids and match them against the session ids in matching events
column = ast.Field(chain=["matching_events"])
else:
# Make this more specific ( don't require join for count for example )
if expr not in joinless_fields:
requires_join = True

columns.append(column)
if has_aggregation(column):
Expand All @@ -212,6 +218,8 @@ def to_query(self) -> ast.SelectQuery:

with self.timings.measure("filters"):
filter_conditions = self.strategy.filter_conditions()
if filter_conditions:
requires_join = True
where_list = [expr for expr in filter_conditions if not has_aggregation(expr)]
if len(where_list) == 0:
where = None
Expand All @@ -233,8 +241,11 @@ def to_query(self) -> ast.SelectQuery:
if self.query.orderBy is not None:
strategy_order_by = self.strategy.order_by()
if strategy_order_by is not None:
requires_join = True
order_by = strategy_order_by
else:
if any(col not in joinless_fields for col in self.query.orderBy):
requires_join = True
order_by = [parse_order_expr(col, timings=self.timings) for col in self.query.orderBy]
elif "count()" in self.input_columns():
order_by = [ast.OrderExpr(expr=parse_expr("count()"), order="DESC")]
Expand All @@ -253,8 +264,13 @@ def to_query(self) -> ast.SelectQuery:
else:
assert self.source_query_runner is not None # For type checking
source_query = self.source_query_runner.to_actors_query()

source_id_chain = self.source_id_column(source_query)

if isinstance(source_query, ast.SelectQuery) and not requires_join:
source_query.select.append(ast.Alias(alias="id", expr=ast.Field(chain=source_id_chain)))

Check failure on line 270 in posthog/hogql_queries/actors_query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Argument "chain" to "Field" has incompatible type "list[str]"; expected "list[str | int]"

Check failure on line 270 in posthog/hogql_queries/actors_query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

"List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance

Check failure on line 270 in posthog/hogql_queries/actors_query_runner.py

View workflow job for this annotation

GitHub Actions / Python code quality checks

Consider using "Sequence" instead, which is covariant
source_query.order_by = order_by
return source_query

source_alias = "source"

origin = self.strategy.origin
Expand Down

0 comments on commit 1320bac

Please sign in to comment.