Skip to content

Aggregation loadall #1735

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

Merged
merged 25 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions redis/commands/search/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def __init__(self, query="*"):
self._query = query
self._aggregateplan = []
self._loadfields = []
self._loadall = False
self._limit = Limit()
self._max = 0
self._with_schema = False
Expand All @@ -116,9 +117,13 @@ def load(self, *fields):

### Parameters

- **fields**: One or more fields in the format of `@field`
- **fields**: If fields not specified, all the fields will be loaded.
Otherwise, fields should be given in the format of `@field`.
"""
self._loadfields.extend(fields)
if fields:
self._loadfields.extend(fields)
else:
self._loadall = True
return self

def group_by(self, fields, *reducers):
Expand Down Expand Up @@ -308,7 +313,10 @@ def build_args(self):
if self._cursor:
ret += self._cursor

if self._loadfields:
if self._loadall:
ret.append("LOAD")
ret.append("*")
elif self._loadfields:
ret.append("LOAD")
ret.append(str(len(self._loadfields)))
ret.extend(self._loadfields)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,11 @@ def test_aggregations_load(client):
res = client.ft().aggregate(req)
assert res.rows[0] == ["t2", "world"]

# load all
req = aggregations.AggregateRequest("*").load()
res = client.ft().aggregate(req)
assert res.rows[0] == ["t1", "hello", "t2", "world"]


@pytest.mark.redismod
def test_aggregations_apply(client):
Expand Down