Skip to content

feat(firestore): pipeline subequeries#16470

Open
daniel-sanche wants to merge 20 commits intomainfrom
firestore_pipelines_join
Open

feat(firestore): pipeline subequeries#16470
daniel-sanche wants to merge 20 commits intomainfrom
firestore_pipelines_join

Conversation

@daniel-sanche
Copy link
Copy Markdown
Contributor

@daniel-sanche daniel-sanche commented Mar 27, 2026

Add support for Pipeline subqueries, allowing users to perform complex data transformation by embedding a full pipeline inside another

New Stages:

  • define
  • subcollection

New Expressions:

  • current_document
  • variable
  • get_field

New classes:

  • SubPipeline, which represents a pipeline without an associated client, which can not be executed

Copy link
Copy Markdown
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 subqueries and variables within Firestore pipelines. Key additions include methods to convert pipelines into array or scalar expressions, a define stage for binding variables, and a subcollection source for relative path queries. New expression types like Variable and CurrentDocument were also implemented alongside corresponding system tests. Feedback was provided to add a type hint to the _PipelineValueExpression constructor to improve type safety and code clarity.

@daniel-sanche daniel-sanche marked this pull request as ready for review March 31, 2026 19:51
@daniel-sanche daniel-sanche requested review from a team as code owners March 31, 2026 19:51
@daniel-sanche daniel-sanche changed the title [DRAFT] feat(firestore): pipeline subequeries feat(firestore): pipeline subequeries Mar 31, 2026
return self._append(stages.Define(*aliased_expressions))


class SubPipeline(_BasePipeline):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this being named Subpipeline to avoid name collision ? Is there an existing Subcollection class ?

Java calls this stage Subcollection https://github.com/googleapis/java-firestore/blob/0c8188520dfbada0d3fef0719e4f95fc231306be/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java#L214-L238

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This isn't a stage, it's a pipeline subclass. I think this is probably Python-specific, because of the weird way we have to handle async/sync code

In Python, we have 3 classes:

  • Pipeline to handle sync clients
  • AsyncPipeline to handle async clients
  • _BasePipeline as a private class to handle common logic between the two.

Sub-pipelines presents a new use-case, where neither client is be attached, but it needs to be exposed to end-users

In Java and other implementations, it's much simpler, because there is a single pipeline class, and they just raise an exception if you try to use it to execute on a sub-pipeline.

"""
return self._create_pipeline(stages.Literals(*documents))

def subcollection(self, path: str) -> SubPipeline:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I'll fix that

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