Skip to content

Comments

feat(firestore): Add array expressions#9492

Open
milaGGL wants to merge 10 commits intomainfrom
mila/expressions-array
Open

feat(firestore): Add array expressions#9492
milaGGL wants to merge 10 commits intomainfrom
mila/expressions-array

Conversation

@milaGGL
Copy link
Contributor

@milaGGL milaGGL commented Feb 11, 2026

Add new array expressions arrayFirst, arrayFirstN,arrayLast,arrayLastN,arrayMinimum,arrayMinimumN,arrayMaximum,arrayMaximumN,arrayIndexOf, arrayLastIndexOf,arrayIndexOfAll.

@changeset-bot
Copy link

changeset-bot bot commented Feb 11, 2026

🦋 Changeset detected

Latest commit: 84ae093

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
firebase Patch
@firebase/firestore Patch
@firebase/firestore-compat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @milaGGL, 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 expands the array processing capabilities within the Firestore SDK by adding eight new expressions. These functions provide developers with enhanced tools to extract specific elements (first, last, or a specified number of elements) and calculate statistical values (minimum, maximum, or a specified number of min/max elements) directly from arrays within their data pipelines, streamlining array-based data transformations.

Highlights

  • New Array Expressions: Eight new array manipulation functions have been introduced: arrayFirst, arrayFirstN, arrayLast, arrayLastN, arrayMaximum, arrayMaximumN, arrayMinimum, and arrayMinimumN.
  • API and Documentation Updates: The API definitions and documentation for both firestore-lite and full Firestore pipelines have been updated to include these new expressions.
  • Comprehensive Testing: Integration and lite-mode tests have been added to ensure the correct functionality of all new array expressions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • common/api-review/firestore-lite-pipelines.api.md
    • Added API definitions for arrayFirst, arrayFirstN, arrayLast, arrayLastN, arrayMaximum, arrayMaximumN, arrayMinimum, and arrayMinimumN.
  • common/api-review/firestore-pipelines.api.md
    • Added API definitions for arrayFirst, arrayFirstN, arrayLast, arrayLastN, arrayMaximum, arrayMaximumN, arrayMinimum, and arrayMinimumN.
  • docs-devsite/firestore_lite_pipelines.expression.md
    • Documented the new arrayFirst, arrayFirstN, arrayLast, arrayLastN, arrayMaximum, arrayMaximumN, arrayMinimum, and arrayMinimumN expressions with signatures and examples.
  • docs-devsite/firestore_pipelines.expression.md
    • Documented the new arrayFirst, arrayFirstN, arrayLast, arrayLastN, arrayMaximum, arrayMaximumN, arrayMinimum, and arrayMinimumN expressions with signatures and examples.
  • packages/firestore/lite/pipelines/pipelines.ts
    • Exported the newly implemented array functions.
  • packages/firestore/src/api_pipelines.ts
    • Exported the newly implemented array functions from the lite-api expressions.
  • packages/firestore/src/lite-api/expressions.ts
    • Implemented the arrayFirst, arrayFirstN, arrayLast, arrayLastN, arrayMaximum, arrayMaximumN, arrayMinimum, and arrayMinimumN methods on the Expression class and as standalone functions.
  • packages/firestore/test/integration/api/pipeline.test.ts
    • Added integration tests to verify the functionality of arrayFirst, arrayFirstN, arrayLast, arrayLastN, arrayMaximum, arrayMaximumN, arrayMinimum, and arrayMinimumN.
  • packages/firestore/test/lite/pipeline.test.ts
    • Added lite-mode tests to verify the functionality of arrayFirst, arrayFirstN, arrayLast, arrayLastN, arrayMaximum, arrayMaximumN, arrayMinimum, and arrayMinimumN.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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 eight new array expression functions to Firestore pipelines, enhancing the query capabilities for array fields. The new functions are arrayFirst, arrayFirstN, arrayLast, arrayLastN, arrayMaximum, arrayMaximumN, arrayMinimum, and arrayMinimumN. The changes are well-implemented and include corresponding API definitions, documentation, and comprehensive tests. I have identified a few areas for improvement, primarily concerning API documentation consistency and formatting in the generated documentation files.

@milaGGL milaGGL changed the title add 8 new expressions feat(firestore): Add array expressions Feb 12, 2026
@milaGGL milaGGL marked this pull request as ready for review February 13, 2026 15:21
@milaGGL milaGGL requested review from a team as code owners February 13, 2026 15:21
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 PR introduces a comprehensive set of new array expressions for Firestore pipelines, including functions for filtering, slicing, and finding elements within arrays. The implementation is well-tested with extensive integration tests. My feedback is primarily focused on improving the accuracy and consistency of the documentation for these new features to ensure clarity for developers. I've pointed out a few places where examples are missing or descriptions of return values could be more precise based on the test cases.

@milaGGL
Copy link
Contributor Author

milaGGL commented Feb 13, 2026

/gemini review

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 a comprehensive set of new array expressions to Firestore pipelines, which is a great feature enhancement. The implementation and tests are thorough. My feedback is mainly focused on improving code organization, documentation clarity, and minor code simplification for better maintainability. I've pointed out some redundant function calls, suggested reordering of exports and methods for consistency, and highlighted some areas in the documentation that could be confusing for users due to duplicated entries and incorrect links.

@milaGGL milaGGL requested a review from a team as a code owner February 18, 2026 21:16
@milaGGL
Copy link
Contributor Author

milaGGL commented Feb 18, 2026

/gemini review

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 a comprehensive set of new array expressions for Firestore pipelines, which is a great addition. The implementation is mostly straightforward, with new methods on the Expression class and corresponding top-level functions. The test coverage for these new features appears to be thorough.

I have two main points of feedback. First, the generated documentation for the new overloaded functions contains a lot of duplication, which impacts readability. Second, the behavior of the arraySlice function's end parameter is inclusive, which is inconsistent with the standard slice behavior in many languages and could be a source of confusion for developers.

@milaGGL
Copy link
Contributor Author

milaGGL commented Feb 24, 2026

/gemini review

@milaGGL milaGGL requested a review from dlarocque February 24, 2026 21:06
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 a suite of new array expressions for Firestore pipelines, enhancing query capabilities. The implementation looks solid, and the accompanying tests are comprehensive.

I've identified a couple of areas for improvement:

  • In packages/firestore/src/lite-api/expressions.ts, there are some magic strings ('first', 'last') that should be extracted into constants for better readability and maintainability.
  • The auto-generated documentation in docs-devsite/ has duplicate headers for overloaded functions. This should be addressed to improve documentation quality and avoid potential issues with HTML rendering and navigation.

Overall, this is a great feature addition. Addressing these minor points will make the code and documentation even better.

Comment on lines +530 to +596
## Expression.arrayFirstN()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>

Returns the first `n` elements of the array.

<b>Signature:</b>

```typescript
arrayFirstN(n: number): FunctionExpression;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| n | number | The number of elements to return. |

<b>Returns:</b>

[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)

A new `Expression` representing the first `n` elements.

### Example


```typescript
// Get the first 3 elements of the 'myArray' field.
field("myArray").arrayFirstN(3);

```

## Expression.arrayFirstN()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>

Returns the first `n` elements of the array.

<b>Signature:</b>

```typescript
arrayFirstN(n: Expression): FunctionExpression;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| n | [Expression](./firestore_lite_pipelines.expression.md#expression_class) | An expression evaluating to the number of elements to return. |

<b>Returns:</b>

[FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class)

A new `Expression` representing the first `n` elements.

### Example


```typescript
// Get the first n elements of the 'myArray' field.
field("myArray").arrayFirstN(field("count"));

```
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The documentation for overloaded methods like arrayFirstN is generating duplicate markdown headers. This can lead to issues with page navigation, broken links, and creates invalid HTML. It's better to document all overloads under a single, unique header.

For example, you could structure it like this:

## Expression.arrayFirstN()

... description ...

**Signature 1:**
```typescript
arrayFirstN(n: number): FunctionExpression;

... params, returns, example for signature 1 ...

Signature 2:

arrayFirstN(n: Expression): FunctionExpression;

... params, returns, example for signature 2 ...


This same issue applies to `arrayIndexOf`, `arrayIndexOfAll`, `arrayLastIndexOf`, `arrayMaximumN`, and `arrayMinimumN` in this file.

Comment on lines +530 to +596
## Expression.arrayFirstN()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>

Returns the first `n` elements of the array.

<b>Signature:</b>

```typescript
arrayFirstN(n: number): FunctionExpression;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| n | number | The number of elements to return. |

<b>Returns:</b>

[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)

A new `Expression` representing the first `n` elements.

### Example


```typescript
// Get the first 3 elements of the 'myArray' field.
field("myArray").arrayFirstN(3);

```

## Expression.arrayFirstN()

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>

Returns the first `n` elements of the array.

<b>Signature:</b>

```typescript
arrayFirstN(n: Expression): FunctionExpression;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| n | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression evaluating to the number of elements to return. |

<b>Returns:</b>

[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)

A new `Expression` representing the first `n` elements.

### Example


```typescript
// Get the first n elements of the 'myArray' field.
field("myArray").arrayFirstN(field("count"));

```
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The documentation for overloaded methods like arrayFirstN is generating duplicate markdown headers. This can lead to issues with page navigation, broken links, and creates invalid HTML. It's better to document all overloads under a single, unique header.

For example, you could structure it like this:

## Expression.arrayFirstN()

... description ...

**Signature 1:**
```typescript
arrayFirstN(n: number): FunctionExpression;

... params, returns, example for signature 1 ...

Signature 2:

arrayFirstN(n: Expression): FunctionExpression;

... params, returns, example for signature 2 ...


This same issue applies to `arrayIndexOf`, `arrayIndexOfAll`, `arrayLastIndexOf`, `arrayMaximumN`, and `arrayMinimumN` in this file.

arrayIndexOf(search: unknown | Expression): FunctionExpression {
return new FunctionExpression(
'array_index_of',
[this, valueToDefaultExpr(search), valueToDefaultExpr('first')],
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The string literal 'first' is a magic string. It would be better to define it as a constant to improve readability and maintainability. The same applies to 'last' on line 1566.

Consider creating a small set of constants for these values, for example:

const ARRAY_INDEX_OF_FIRST = 'first';
const ARRAY_INDEX_OF_LAST = 'last';

This would make the code easier to understand and less prone to typos.

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.

3 participants