Skip to content

feat: literals pipeline stage#1170

Open
Linchin wants to merge 2 commits intogoogleapis:mainfrom
Linchin:literals
Open

feat: literals pipeline stage#1170
Linchin wants to merge 2 commits intogoogleapis:mainfrom
Linchin:literals

Conversation

@Linchin
Copy link
Contributor

@Linchin Linchin commented Feb 13, 2026

TODO:

  • add docstring
  • verify pb format
  • verify system test

@Linchin Linchin requested review from a team as code owners February 13, 2026 22:40
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: firestore Issues related to the googleapis/python-firestore API. labels Feb 13, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @Linchin, 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 new Literals pipeline stage to the Firestore client library. This feature enables users to define and inject literal documents directly into a pipeline, providing a flexible way to start or augment data processing flows with predefined data. The changes include the implementation of the new stage, its integration into the base pipeline, and corresponding unit and system tests.

Highlights

  • New Literals Pipeline Stage: A new Literals stage has been introduced in pipeline_stages.py to allow direct injection of documents into a pipeline, enhancing data flow flexibility.
  • _BasePipeline Integration: A literals method was added to _BasePipeline in base_pipeline.py, providing a convenient way to append the new Literals stage to a pipeline.
  • Comprehensive Testing: Unit tests for the Literals stage and its integration, along with a system-level end-to-end test, have been added to ensure correctness and functionality.
Changelog
  • google/cloud/firestore_v1/base_pipeline.py
    • Added the literals method to _BasePipeline to append a Literals stage.
  • google/cloud/firestore_v1/pipeline_stages.py
    • Implemented the Literals class, inheriting from Stage, to represent a pipeline stage that takes Selectable documents.
    • Defined __init__ and _pb_args methods for the Literals stage.
  • tests/system/pipeline_e2e/general.yaml
    • Added a new system test case named "literals" to verify the functionality of the Literals pipeline stage with constant documents.
  • tests/unit/v1/test_pipeline.py
    • Added a test case to test_pipeline_execute_stream_equivalence to ensure the literals method correctly maps to the stages.Literals class.
  • tests/unit/v1/test_pipeline_stages.py
    • Created TestLiterals class with unit tests for the Literals stage's constructor, repr method, and _to_pb conversion.
Activity
  • The author has indicated pending tasks: adding a docstring for the literals method, verifying the protocol buffer format, and verifying the system test.
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

@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 new literals pipeline stage, which allows injecting a fixed set of documents into a pipeline. No security vulnerabilities were identified. However, there are a couple of areas for improvement: the docstrings for the new functionality are currently placeholders and should be filled out, and a minor inconsistency in type hints for the new method should be corrected for clarity and consistency.

Comment on lines +280 to +282
"""
TODO: add docstring.
"""

Choose a reason for hiding this comment

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

high

The docstring for the literals method is a TODO placeholder. Please add a complete docstring explaining what the method does, its parameters, and providing examples of its usage. This is important for maintainability and for other developers to understand how to use this new pipeline stage.

        """Starts a pipeline with a fixed set of documents.

        This stage replaces the current set of documents in the pipeline with a
        new set of literal documents. This is useful for testing or for pipelines
        that operate on a predefined set of data.

        The documents can be provided directly as a `Constant` expression or
        indirectly via a field reference from the input documents.

        Example (with a `Constant`):
            >>> from google.cloud.firestore_v1.pipeline_expressions import Constant
            >>>
            >>> documents = [
            ...     {"name": "Alice", "score": 95},
            ...     {"name": "Bob", "score": 87},
            ... ]
            >>> pipeline = client.pipeline().literals(Constant.of(documents))

        Example (with a field reference):
            >>> # Assumes input documents have a field 'document_list' containing an array of documents.
            >>> pipeline = client.pipeline().collection("sources").literals("document_list")

        Args:
            documents: A `str` or `Selectable` expression. If a `str`, it's
                       treated as a field path to an array of documents.
                       If a `Selectable`, it's usually a `Constant`
                       containing an array of documents (as dictionaries).

        Returns:
            A new Pipeline object with this stage appended to the stage list.
        """



class Literals(Stage):
"""TODO: add docstring."""

Choose a reason for hiding this comment

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

high

The docstring for the Literals class is a TODO placeholder. Please add a docstring explaining what the stage does.

Suggested change
"""TODO: add docstring."""
"""Starts a pipeline with a fixed set of documents."""


def literals(
self,
documents: Selectable,

Choose a reason for hiding this comment

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

medium

The type hint for documents is Selectable, but the implementation in Literals.__init__ also handles str. To be consistent with the implementation and other methods in this class (like select), the type hint should be str | Selectable.

Suggested change
documents: Selectable,
documents: str | Selectable,

class Literals(Stage):
"""TODO: add docstring."""

def __init__(self, documents: Selectable):

Choose a reason for hiding this comment

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

medium

The type hint for documents is Selectable, but the implementation in __init__ also handles str. To be consistent with the implementation, the type hint should be str | Selectable.

Suggested change
def __init__(self, documents: Selectable):
def __init__(self, documents: str | Selectable):

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: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants