Skip to content

Commit

Permalink
[core][fix] Apply limit to aggregate result not query (#2017)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Apr 8, 2024
1 parent 68ee19c commit 7d8accf
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions fixcore/fixcore/db/arango_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ def to_query(
query = query_model.query
start = from_collection or f"`{db.graph_vertex_name()}`"
cursor, query_str = query_string(db, query, query_model, start, with_edges, ctx, id_column=id_column)
last_limit = (
f" LIMIT {ll.offset}, {ll.length}" if ((ll := query.current_part.limit) and not query.is_aggregate()) else ""
)
last_limit = f" LIMIT {ll.offset}, {ll.length}" if (ll := query.current_part.limit) else ""
return f"""{query_str} FOR result in {cursor}{last_limit} RETURN UNSET(result, {unset_props})""", ctx.bind_vars


Expand Down Expand Up @@ -709,8 +707,8 @@ def navigation(in_crsr: str, nav: Navigation) -> str:

# Skip the limit in case of
# - with clause: the limit is applied in the with clause
# - last part of a non aggregation query: the limit is applied in the outermost for loop
filter_limit = p.limit if (p.with_clause is None and (not last_part or query.is_aggregate())) else None
# - last part: the limit is applied in the outermost for loop
filter_limit = p.limit if (p.with_clause is None and not last_part) else None
cursor = in_cursor
part_term = p.term
if isinstance(p.term, MergeTerm):
Expand All @@ -728,7 +726,7 @@ def navigation(in_crsr: str, nav: Navigation) -> str:
cursor = filter_statement(cursor, part_term, filter_limit)

# See filter_limit documentation above
with_clause_limit = p.limit if (not last_part or query.is_aggregate()) else None
with_clause_limit = p.limit if not last_part else None
cursor = with_clause(cursor, p.with_clause, with_clause_limit) if p.with_clause else cursor
cursor = navigation(cursor, p.navigation) if p.navigation else cursor
return p, cursor, filtered_out, query_part
Expand Down

0 comments on commit 7d8accf

Please sign in to comment.