Skip to content

Conversation

@daniel-sanche
Copy link
Contributor

@daniel-sanche daniel-sanche commented Jan 7, 2026

WIP

TODO:

  • it sounds like some changes are coming to remove extra Exists statements. Blocked on revised sample code

@product-auto-label product-auto-label bot added the size: xl Pull request size is extra large. label Jan 7, 2026
@daniel-sanche daniel-sanche changed the base branch from main to pipeline-preview January 7, 2026 05:37
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Jan 7, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @daniel-sanche, 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 introduces a powerful new 'pipeline' feature to the Firestore client library, enabling complex data transformations and queries through a series of chained stages. It provides both synchronous and asynchronous APIs for building and executing these pipelines, integrating existing query and aggregation functionalities into this new framework. This significantly enhances the flexibility and expressiveness of data manipulation within Firestore.

Highlights

  • New Pipeline Feature: Introduced a comprehensive 'pipeline' feature for both synchronous and asynchronous Firestore clients, enabling complex data transformations and queries through a series of chained stages.
  • Pipeline Components: Added new classes for core pipeline logic (_BasePipeline, Pipeline, AsyncPipeline), pipeline sources (PipelineSource), various pipeline stages (pipeline_stages.py), and a rich set of pipeline expressions (pipeline_expressions.py) for defining operations like filtering, aggregation, and transformations.
  • Integration with Existing Queries: Existing Query and AggregationQuery objects can now be converted into pipeline instances, allowing for seamless integration of traditional query patterns with the new pipeline capabilities, including handling of filters, projections, orders, and cursors.
  • API Enhancements: Modified FirestoreClient and FirestoreAsyncClient to expose a pipeline() method, serving as the entry point for constructing pipelines. Also updated underlying gRPC and REST transports to support the new ExecutePipeline RPC.
  • Comprehensive Testing: Added extensive unit tests for all new pipeline components and their interactions, alongside new YAML-based system tests for end-to-end validation of pipeline functionality, covering various scenarios like aggregations, array operations, logical conditions, and vector searches.

🧠 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.

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.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: xl Pull request size is extra large. labels Jan 7, 2026
Copy link

@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 adds support for cursors and limit_to_last in pipeline from_query. The implementation looks promising, but I've identified a couple of critical correctness bugs in the logic. One is related to the incorrect ordering of pipeline stages, where a sort stage is added before a where stage for cursors. The other is in the cursor condition generation, which doesn't account for the sort direction. I've provided detailed comments and code suggestions to address these issues. Additionally, the unit tests for the new cursor functionality could be more specific to catch such bugs in the future. Overall, this is a great feature addition, and with these fixes, it should be solid.

Comment on lines 1191 to 1214
# If limit_to_last is set, we need to reverse the orderings to find the
# "last" N documents (which effectively become the "first" N in reverse order).
if self._limit_to_last:
actual_orderings = _reverse_orderings(orderings)
ppl = ppl.sort(*actual_orderings)
else:
ppl = ppl.sort(*orderings)

# Apply cursor conditions.
# Cursors are translated into filter conditions (e.g., field > value)
# based on the orderings.
if start_at_val:
ppl = ppl.where(
_where_conditions_from_cursor(
start_at_val, orderings, is_start_cursor=True
)
)

# Cursors, Limit and Offset
if self._start_at or self._end_at or self._limit_to_last:
raise NotImplementedError(
"Query to Pipeline conversion: cursors and limit_to_last is not supported yet."
)
else: # Limit & Offset without cursors
if self._offset:
ppl = ppl.offset(self._offset)
if self._limit:
if end_at_val:
ppl = ppl.where(
_where_conditions_from_cursor(
end_at_val, orderings, is_start_cursor=False
)
)

Choose a reason for hiding this comment

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

critical

The order of pipeline stages is incorrect. The sort stage is being added before the where stage for cursor conditions. To ensure correctness and for performance reasons, all filtering (where stages) should be applied before sorting. The block for applying cursor conditions should be moved before the block for sorting.

            # Apply cursor conditions.
            # Cursors are translated into filter conditions (e.g., field > value)
            # based on the orderings.
            if start_at_val:
                ppl = ppl.where(
                    _where_conditions_from_cursor(
                        start_at_val, orderings, is_start_cursor=True
                    )
                )

            if end_at_val:
                ppl = ppl.where(
                    _where_conditions_from_cursor(
                        end_at_val, orderings, is_start_cursor=False
                    )
                )

            # If limit_to_last is set, we need to reverse the orderings to find the
            # "last" N documents (which effectively become the "first" N in reverse order).
            if self._limit_to_last:
                actual_orderings = _reverse_orderings(orderings)
                ppl = ppl.sort(*actual_orderings)
            else:
                ppl = ppl.sort(*orderings)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is partially true. When limit_to_last is set, it needs to sort both before and after though. I made that change

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: firestore Issues related to the googleapis/python-firestore API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant