-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(firestore): support let stage #16030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -275,6 +275,31 @@ def find_nearest( | |||||
| stages.FindNearest(field, vector, distance_measure, options) | ||||||
| ) | ||||||
|
|
||||||
| def let(self, **variables: Expression) -> "_BasePipeline": | ||||||
| """ | ||||||
| Stage which declares a set of variables which can be accessed from the current scope | ||||||
| and below. | ||||||
|
|
||||||
| Variables are defined in a separate (global) scope, that does not interfere with | ||||||
| local field references. | ||||||
|
|
||||||
| Example: | ||||||
| >>> from google.cloud.firestore_v1.pipeline_expressions import Field, add | ||||||
| >>> pipeline = client.pipeline().collection("books") | ||||||
| >>> pipeline = pipeline.let( | ||||||
| ... rating_plus_one=add(Field.of("rating"), 1), | ||||||
| ... has_awards=Field.of("awards").exists() | ||||||
| ... ) | ||||||
| >>> # Later stages can use Variable.of("rating_plus_one") | ||||||
|
Contributor
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 mentions
Contributor
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 example in the docstring suggests using
Suggested change
|
||||||
|
|
||||||
| Args: | ||||||
| **variables: Keyword arguments where keys are the variable names (str) | ||||||
| and values are the `Expression` objects defining them. | ||||||
| Returns: | ||||||
| A new Pipeline object with this stage appended to the stage list | ||||||
| """ | ||||||
| return self._append(stages.Let(**variables)) | ||||||
|
|
||||||
| def replace_with( | ||||||
| self, | ||||||
| field: Selectable, | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -303,6 +303,23 @@ def _pb_options(self) -> dict[str, Value]: | |||||
| return options | ||||||
|
|
||||||
|
|
||||||
| class Let(Stage): | ||||||
| """Stage which declares a set of variables which can be accessed from the current | ||||||
| scope and below.""" | ||||||
|
|
||||||
| def __init__(self, **variables: Expression): | ||||||
| super().__init__("let") | ||||||
| self.variables = variables | ||||||
|
Contributor
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. To ensure deterministic output for
Suggested change
References
|
||||||
|
|
||||||
| def _pb_args(self): | ||||||
| map_val = {k: v._to_pb() for k, v in self.variables.items()} | ||||||
| return [Value(map_value={"fields": map_val})] | ||||||
|
|
||||||
| def __repr__(self): | ||||||
| vars_str = ", ".join(f"{k}={v!r}" for k, v in self.variables.items()) | ||||||
| return f"{self.__class__.__name__}({vars_str})" | ||||||
|
|
||||||
|
|
||||||
| class RawStage(Stage): | ||||||
| """Represents a generic, named stage with parameters.""" | ||||||
|
|
||||||
|
|
||||||
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.
Drive-by comment, we are using define instead of let for our SDKs(mobile/web/java/node). There is active discussions happening right now on the naming. You probably need to rename it depending on how the discussion goes.
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.
Thanks for the heads up! Will ping you