Skip to content

Commit 8f5c1e6

Browse files
Aggregation loadall (#1735)
Co-authored-by: Chayim <[email protected]>
1 parent 42101fc commit 8f5c1e6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

redis/commands/search/aggregation.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __init__(self, query="*"):
103103
self._query = query
104104
self._aggregateplan = []
105105
self._loadfields = []
106+
self._loadall = False
106107
self._limit = Limit()
107108
self._max = 0
108109
self._with_schema = False
@@ -116,9 +117,13 @@ def load(self, *fields):
116117
117118
### Parameters
118119
119-
- **fields**: One or more fields in the format of `@field`
120+
- **fields**: If fields not specified, all the fields will be loaded.
121+
Otherwise, fields should be given in the format of `@field`.
120122
"""
121-
self._loadfields.extend(fields)
123+
if fields:
124+
self._loadfields.extend(fields)
125+
else:
126+
self._loadall = True
122127
return self
123128

124129
def group_by(self, fields, *reducers):
@@ -308,7 +313,10 @@ def build_args(self):
308313
if self._cursor:
309314
ret += self._cursor
310315

311-
if self._loadfields:
316+
if self._loadall:
317+
ret.append("LOAD")
318+
ret.append("*")
319+
elif self._loadfields:
312320
ret.append("LOAD")
313321
ret.append(str(len(self._loadfields)))
314322
ret.extend(self._loadfields)

tests/test_search.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,11 @@ def test_aggregations_load(client):
10541054
res = client.ft().aggregate(req)
10551055
assert res.rows[0] == ["t2", "world"]
10561056

1057+
# load all
1058+
req = aggregations.AggregateRequest("*").load()
1059+
res = client.ft().aggregate(req)
1060+
assert res.rows[0] == ["t1", "hello", "t2", "world"]
1061+
10571062

10581063
@pytest.mark.redismod
10591064
def test_aggregations_apply(client):

0 commit comments

Comments
 (0)