Skip to content

feat(firestore): support array_agg(), array_agg_distinct(), first(), last()#16029

Merged
Linchin merged 5 commits intogoogleapis:mainfrom
Linchin:fs-funcs
Mar 10, 2026
Merged

feat(firestore): support array_agg(), array_agg_distinct(), first(), last()#16029
Linchin merged 5 commits intogoogleapis:mainfrom
Linchin:fs-funcs

Conversation

@Linchin
Copy link
Contributor

@Linchin Linchin commented Mar 5, 2026

TODO:

@Linchin Linchin requested review from a team as code owners March 5, 2026 00:47
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Firestore client library by introducing several new aggregation functions. These additions allow users to collect values into arrays, retrieve distinct values, and easily select the first or last elements within a dataset, thereby expanding the analytical capabilities of the query pipeline. The changes are thoroughly tested with both unit and system tests to ensure reliability.

Highlights

  • New Aggregation Functions: Added support for array_agg(), array_agg_distinct(), first(), and last() aggregation functions within the Firestore pipeline expressions, enabling more powerful data manipulation.
  • System Tests: Introduced comprehensive system-level end-to-end tests for the newly added aggregation functions to ensure their correct behavior in a real-world scenario.
  • Unit Tests: Implemented dedicated unit tests for each new aggregation method to verify their individual functionality and integration with the existing expression framework.
Changelog
  • packages/google-cloud-firestore/google/cloud/firestore_v1/pipeline_expressions.py
    • Added array_agg method to create an aggregation that collects values into an array.
    • Added array_agg_distinct method to create an aggregation that collects distinct values into an array.
    • Added first method to create an aggregation that selects the first value.
    • Added last method to create an aggregation that selects the last value.
  • packages/google-cloud-firestore/tests/system/pipeline_e2e/aggregates.yaml
    • Added a new system test testArrayAgg to verify the array_agg function.
    • Added a new system test testArrayAggDistinct to verify the array_agg_distinct function.
    • Added a new system test testFirst to verify the first function.
    • Added a new system test testLast to verify the last function.
  • packages/google-cloud-firestore/tests/unit/v1/test_pipeline_expressions.py
    • Added test_array_agg to validate the array_agg method's behavior.
    • Added test_array_agg_distinct to validate the array_agg_distinct method's behavior.
    • Added test_first to validate the first method's behavior.
    • Added test_last to validate the last method's behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 array_agg(), array_agg_distinct(), first(), and last() aggregation functions. The changes include updates to pipeline expressions and the addition of corresponding unit and system tests. My review found a couple of minor grammatical errors in the docstrings, for which I've provided suggestions. These comments do not conflict with any of the provided rules and are therefore kept as is.

Linchin and others added 3 commits March 4, 2026 17:01
…line_expressions.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…line_expressions.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link
Contributor

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

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

Looks mostly good to me, but consider improving that test

- "distinct_genres"
assert_results:
- distinct_genres:
- "Science Fiction"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a better test example that could be used? It looks like this is finding distinct values out of a fixed array with size 1

Could we make it read genres from the database, and return the distinct values or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a really good catch. I removed the filter.

@Linchin Linchin requested a review from daniel-sanche March 9, 2026 21:38
Copy link
Contributor

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

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

LGTM

@Linchin Linchin merged commit d04a241 into googleapis:main Mar 10, 2026
27 checks passed
parthea added a commit that referenced this pull request Mar 12, 2026
PR created by the Librarian CLI to initialize a release. Merging this PR
will auto trigger a release.

Librarian Version: v0.0.0-20260216162532-e323d455c92b
Language Image:
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:160860d189ff1c2f7515638478823712fa5b243e27ccc33a2728669fa1e2ed0c
<details><summary>google-ads-datamanager: v0.6.0</summary>

##
[v0.6.0](google-ads-datamanager-v0.5.0...google-ads-datamanager-v0.6.0)
(2026-03-12)

### Documentation

* update filter field documentation to clarify case requirements and
improve examples
([505bc97](505bc97))


### Features

* deprecate INVALID_COUNTRY_CODE and add MEMBERSHIP_DURATION_TOO_LONG to
the ErrorReason enum
([505bc97](505bc97))


### Bug Fixes

* feat: update advertiser_identifier_count in PairIdInfo to be optional
([505bc97](505bc97))
* update publisher_name in PairIdInfo to be required
([505bc97](505bc97))
* update match_rate_percentage in PairIdInfo to be required
([505bc97](505bc97))

</details>


<details><summary>google-auth: v2.49.1</summary>

##
[v2.49.1](google-auth-v2.49.0...google-auth-v2.49.1)
(2026-03-12)

### Bug Fixes

* fix request session error (#16050)
([bfd9322](bfd93225))

* remove deprecated rsa dependency (#16020)
([e8927b9](e8927b9c))

</details>


<details><summary>google-cloud-ces: v0.2.0</summary>

##
[v0.2.0](google-cloud-ces-v0.1.0...google-cloud-ces-v0.2.0)
(2026-03-12)

### Documentation

* A comment for field `cert` in message
`.google.cloud.ces.v1beta.TlsConfig` is changed
([505bc97](505bc97))
* A comment for field `name` in message `.google.cloud.ces.v1beta.Tool`
is changed PiperOrigin-RevId: 878047537
([505bc97](505bc97))
* A comment for field `entry_agent` in message
`.google.cloud.ces.v1beta.SessionConfig` is changed
([505bc97](505bc97))


### Features

* update public libraries for CES v1beta
([505bc97](505bc97))


### Bug Fixes

* An existing field `app` is renamed to `name` in message
`.google.cloud.ces.v1beta.UploadEvaluationAudioRequest`
([505bc97](505bc97))
* An existing field `audio_transcript` is renamed to `transcript` in
message `.google.cloud.ces.v1beta.UploadEvaluationAudioResponse`
([505bc97](505bc97))
* An existing field `audio_duration` is renamed to `duration` in message
`.google.cloud.ces.v1beta.UploadEvaluationAudioResponse`
([505bc97](505bc97))
* An existing field `variables` is moved in to oneof in message
`.google.cloud.ces.v1beta.ExecuteToolRequest`
([505bc97](505bc97))
* An existing method_signature `app,audio_content` is removed from
method `UploadEvaluationAudio` in service `EvaluationService`
([505bc97](505bc97))
* An existing google.api.http annotation `http_uri` is changed for
method `UploadEvaluationAudio` in service `EvaluationService`
([505bc97](505bc97))

</details>


<details><summary>google-cloud-compute: v1.46.0</summary>

##
[1.46.0](google-cloud-compute-v1.45.0...google-cloud-compute-v1.46.0)
(2026-03-12)


### Features

* Update Compute Engine v1 API to revision 20260227
([7b22ea2](7b22ea2))

</details>


<details><summary>google-cloud-compute-v1beta: v0.9.0</summary>

##
[0.9.0](google-cloud-compute-v1beta-v0.8.0...google-cloud-compute-v1beta-v0.9.0)
(2026-03-12)


### Features

* Update Compute Engine v1beta API to revision 20260227
([bf43768](bf43768))

</details>


<details><summary>google-cloud-firestore: v2.25.0</summary>

##
[v2.25.0](google-cloud-firestore-v2.24.0...google-cloud-firestore-v2.25.0)
(2026-03-12)

### Features

* support array_agg(), array_agg_distinct(), first(), last() (#16029)
([d04a241](d04a241d))

</details>


<details><summary>google-cloud-gdchardwaremanagement: v0.4.0</summary>

##
[0.4.0](google-cloud-gdchardwaremanagement-v0.3.0...google-cloud-gdchardwaremanagement-v0.4.0)
(2026-03-12)


### Features

* Add `OFFLINE` state to Zone resources A new `OFFLINE` state has been
added to the `Zone.State` enum. This state indicates that the zone is
temporarily not operational, for example, while undergoing maintenance
or repair
([505bc97](505bc97))

</details>


<details><summary>google-cloud-geminidataanalytics: v0.11.0</summary>

##
[0.11.0](google-cloud-geminidataanalytics-v0.10.0...google-cloud-geminidataanalytics-v0.11.0)
(2026-03-12)


### Documentation

* update field comments for `generated_looker_query` in `DataMessage`
([505bc97](505bc97))


### Features

* add `ParameterizedSecureViewParameters` message and field for PSV
support
([505bc97](505bc97))
* add `ThinkingMode` enum and field to control agent thinking mode
([505bc97](505bc97))

</details>


<details><summary>google-cloud-gke-hub: v1.22.0</summary>

##
[1.22.0](google-cloud-gke-hub-v1.21.0...google-cloud-gke-hub-v1.22.0)
(2026-03-12)


### Features

* upgrade protobuf from v25.7 to v31.0
([505bc97](505bc97))
</details>


<details><summary>google-cloud-pubsub: v2.36.0</summary>

##
[2.36.0](google-cloud-pubsub-v2.35.0...google-cloud-pubsub-v2.36.0)
(2026-03-12)


### Features

* Add BigtableConfig type
([ec1a676](ec1a676))

</details>


<details><summary>google-maps-routing: v0.9.0</summary>

##
[0.9.0](google-maps-routing-v0.8.0...google-maps-routing-v0.9.0)
(2026-03-12)


### Documentation

* regenerated documentation for fields
([505bc97](505bc97))


### Features

* add a new Waypoint source to accept a token that identifies a
Navigation Point obtained from the `SearchDestinations` method of the
Geocoding API
([505bc97](505bc97))

</details>


<details><summary>google-resumable-media: v2.8.1</summary>

##
[v2.8.1](google-resumable-media-v2.8.0...google-resumable-media-v2.8.1)
(2026-03-12)

### Bug Fixes

* add max_length support to Gzip/Brotli decoders for urllib3 2.6&#43;
(#495)
([cb90060](cb900605))

</details>


<details><summary>google-shopping-type: v1.3.0</summary>

##
[1.3.0](google-shopping-type-v1.2.0...google-shopping-type-v1.3.0)
(2026-03-12)


### Documentation

* A comment for message `DestintionEnum` is changed
([505bc97](505bc97))


### Features

* add more values in DestintionEnum
([505bc97](505bc97))

</details>

---------

Co-authored-by: Anthonios Partheniou <partheniou@google.com>
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