Skip to content

feat(search): add COLLECT reducer to FT.AGGREGATE - #3310

Merged
nkaradzhov merged 3 commits into
redis:masterfrom
nkaradzhov:collect-aggregate
Jul 6, 2026
Merged

nkaradzhov merged 3 commits into
redis:masterfrom
nkaradzhov:collect-aggregate

Conversation

@nkaradzhov

@nkaradzhov nkaradzhov commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Support the experimental COLLECT reducer (Redis Search 8.8), which fetches whole documents or projected fields within each GROUPBY group, with optional DISTINCT, in-group SORTBY, and LIMIT.

  • FIELDS '*' emits a bare wildcard token; an explicit list is count-prefixed
  • nargs is computed dynamically via pushVariadicWithLength (unlike the fixed-narg reducers), covering FIELDS/DISTINCT/SORTBY/LIMIT
  • reuses pushSortByProperty for the nested SORTBY clause
  • HYBRID picks up COLLECT automatically (shared parseGroupByReducer)

Description

Describe your pull request here


Checklist

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

Note

Low Risk
Additive API and command encoding for an optional reducer; existing reducers unchanged, with coverage focused on argument transformation and opt-in unstable server tests.

Overview
Adds client support for the experimental COLLECT GROUPBY reducer on FT.AGGREGATE, so callers can gather full documents or selected fields per group with optional DISTINCT, in-group SORTBY, LIMIT, and AS aliases.

parseGroupByReducer now serializes COLLECT with dynamic nargs via pushVariadicWithLength (wildcard FIELDS * vs count-prefixed field lists, plus optional clauses). HYBRID inherits COLLECT through the shared reducer parser. Tests add transform coverage and integration runs against OPEN_UNSTABLE (Redis 8.10+ with unstable search features).

Reviewed by Cursor Bugbot for commit 86098fa. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread packages/search/lib/commands/AGGREGATE.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 8a7ece9. Configure here.

Comment thread packages/search/lib/commands/AGGREGATE.ts
@PavelPashov
PavelPashov self-requested a review June 22, 2026 14:27
nkaradzhov and others added 2 commits July 6, 2026 14:41
Support the experimental COLLECT reducer (Redis Search 8.8), which fetches
whole documents or projected fields within each GROUPBY group, with optional
DISTINCT, in-group SORTBY, and LIMIT.

- FIELDS '*' emits a bare wildcard token; an explicit list is count-prefixed
- nargs is computed dynamically via pushVariadicWithLength (unlike the
  fixed-narg reducers), covering FIELDS/DISTINCT/SORTBY/LIMIT
- reuses pushSortByProperty for the nested SORTBY clause
- HYBRID picks up COLLECT automatically (shared parseGroupByReducer)

Tests: arg-serialization specs plus an integration test gated behind a new
OPEN_UNSTABLE server config (--search-enable-unstable-features yes), required
because COLLECT is rejected when unstable features are off.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
COLLECT reducer is only available on RediSearch >= 8.8 (behind
--search-enable-unstable-features). Older matrix servers (7.4/8.2/8.4)
reject it with "No such reducer: COLLECT". Gate the live test with
minimumDockerVersion so it skips on those and runs on 8.8.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nkaradzhov
nkaradzhov force-pushed the collect-aggregate branch from 25904dd to 276f051 Compare July 6, 2026 12:36
…8.10

DISTINCT is now merged in RediSearch and confirmed live in the 8.10 test
image. Add an integration test asserting DISTINCT collapses duplicate
projected fields within a group.

Both COLLECT integration tests are gated to server >= 8.10 (the version
verified to expose the reducer) and kept behind OPEN_UNSTABLE, since
COLLECT is still rejected on 8.10 when unstable features are off.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nkaradzhov
nkaradzhov force-pushed the collect-aggregate branch from 276f051 to 86098fa Compare July 6, 2026 12:44
@nkaradzhov
nkaradzhov merged commit 5b8cfa6 into redis:master Jul 6, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants