Skip to content

feat(firestore): add support for window functions in Pipelines - #14504

Open
MarkDuckworth wants to merge 10 commits into
mainfrom
markduckworth/window-functions
Open

MarkDuckworth wants to merge 10 commits into
mainfrom
markduckworth/window-functions

Conversation

@MarkDuckworth

@MarkDuckworth MarkDuckworth commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

BEGIN_COMMIT_OVERRIDE
feat(firestore): Added support for window functions in Pipelines, with the addWindowFields stage for computing aggregates such as running totals and moving averages over partitioned and sorted frames of documents, and over() for framing individual aggregates.
END_COMMIT_OVERRIDE

- Add AddWindowFields stage and Pipeline.addWindowFields overloads
- Add WindowSpec, WindowBound, WindowFunction, and AliasedWindowFunction
- Add AggregateFunction.over(WindowSpec) to evaluate aggregates over window frames
- Add serialization and proto tests in AddWindowFieldsProtoTest and PipelineProtoTest
- Add integration tests in ITPipelineTest with array_agg_distinct enabled against Nightly

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for window functions in the Firestore pipeline API, adding the addWindowFields stage along with supporting classes like WindowSpec, WindowFunction, WindowBound, and AliasedWindowFunction. It also includes extensive unit and integration tests to validate various windowing behaviors such as partitioning, sorting, and framing. A review comment suggests adding an explicit null check in WindowSpec.toBoundaryExpr to prevent potential serialization errors when a null boundary is provided.

- Replace the WindowBound enum with a final class exposing CURRENT/UNBOUNDED constants; remove the WindowSpec.CURRENT/UNBOUNDED aliases.
- Remove WindowSpec.partition(FieldPath...) and the getPartition()/getSort() getters.
- Document that CURRENT is peer-inclusive in range frames and positional in documents frames.
- Add integration tests for tied peers, string and multi-key range sorts, and double range offsets.
@MarkDuckworth
MarkDuckworth marked this pull request as ready for review October 23, 2026 21:46
@MarkDuckworth
MarkDuckworth requested review from a team as code owners October 23, 2026 21:46
@MarkDuckworth MarkDuckworth changed the title feat(firestore): implement pipeline window functions feat(firestore): pipeline window functions Oct 26, 2026
@MarkDuckworth MarkDuckworth changed the title feat(firestore): pipeline window functions feat(firestore): add support for window functions in Pipelines Oct 26, 2026
}

/**
* Creates a window function that assigns a unique rank to each row based on the sort order.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Creates a window function that assigns a unique rank to each row based on the sort order.
* Returns the rank of each document within its partition according to the window's sort order. Documents with equal sort values receive the same rank, and the following rank is skipped.

This branch has not been deployed

No deployments
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