This repository was archived by the owner on Mar 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
feat: literals pipeline stage #1170
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,6 +273,15 @@ def find_nearest( | |
| stages.FindNearest(field, vector, distance_measure, options) | ||
| ) | ||
|
|
||
| def literals( | ||
| self, | ||
| documents: Selectable, | ||
| ) -> "_BasePipeline": | ||
| """ | ||
| TODO: add docstring. | ||
| """ | ||
|
Comment on lines
+277
to
+338
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docstring for the """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.
""" |
||
| return self._append(stages.Literals(documents)) | ||
|
|
||
| def replace_with( | ||
| self, | ||
| field: Selectable, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -342,6 +342,17 @@ def _pb_args(self): | |
| return [Value(integer_value=self.limit)] | ||
|
|
||
|
|
||
| class Literals(Stage): | ||
| """TODO: add docstring.""" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| def __init__(self, documents: Selectable): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| super().__init__("literals") | ||
| self.documents = Field(documents) if isinstance(documents, str) else documents | ||
|
|
||
| def _pb_args(self): | ||
| return [self.documents._to_pb()] | ||
|
|
||
|
|
||
| class Offset(Stage): | ||
| """Skips a specified number of documents.""" | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type hint for
documentsisSelectable, but the implementation inLiterals.__init__also handlesstr. To be consistent with the implementation and other methods in this class (likeselect), the type hint should bestr | Selectable.