Repository navigation
feat(firestore): add RangeWindowFrame for pipeline windows #19119
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
Open
ohmayr
wants to merge
5
commits into
feat/firestore-window-2-document-frame
from
feat/firestore-window-3-range-frame
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
15229f7
feat(firestore): add RangeWindowFrame for pipeline windows
ohmayr 114ca63
Merge branch 'feat/firestore-window-2-document-frame' into feat/fires…
ohmayr 50f636c
chore(firestore): add RangeWindowFrame to top-level librarian post-pr…
ohmayr 31e9dd3
docs(firestore): include sort in RangeWindowFrame docstring example
ohmayr e62e6dc
refactor(firestore): use frame with RangeWindowFrame
ohmayr 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -386,13 +386,47 @@ def _to_dict(self) -> dict[str, Value]: | |
| return {"documents": self._to_pb()} | ||
|
|
||
|
|
||
| @dataclass | ||
| class RangeWindowFrame(_WindowFrame): | ||
| """Defines a value-based or time-range window frame relative to the current document's sort value. | ||
|
|
||
| Example: | ||
| >>> from google.cloud.firestore_v1.pipeline_expressions import Field | ||
| >>> from google.cloud.firestore_v1.pipeline_types import ( | ||
| ... RangeWindowFrame, | ||
| ... TimeUnit, | ||
| ... WindowBound, | ||
| ... WindowSpec, | ||
| ... ) | ||
| >>> window = WindowSpec( | ||
| ... sort=Field.of("time").ascending(), | ||
| ... frame=RangeWindowFrame(12, WindowBound.CURRENT, unit=TimeUnit.HOUR), | ||
| ... ) | ||
|
|
||
| Args: | ||
| preceding: The lower bound of the frame (a numeric offset, `WindowBound`, or `Expression`). | ||
| following: The upper bound of the frame (a numeric offset, `WindowBound`, or `Expression`). | ||
| unit: Optional duration unit for time-range frames (e.g., `TimeUnit.DAY`, `TimeGranularity.MONTH`, | ||
| `"day"`, or an `Expression`). | ||
| """ | ||
|
|
||
| preceding: WindowBound | str | int | float | pipeline_expressions.Expression | ||
| following: WindowBound | str | int | float | pipeline_expressions.Expression | ||
| unit: Optional[ | ||
| TimeUnit | TimeGranularity | str | pipeline_expressions.Expression | ||
| ] = None | ||
|
Comment on lines
+413
to
+417
Contributor
Author
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. Design Note — Separate
|
||
|
|
||
| def _to_dict(self) -> dict[str, Value]: | ||
| return {"range": self._to_pb()} | ||
|
|
||
|
|
||
| class WindowSpec: | ||
| """Configuration for a window in an `AddWindowFields` pipeline stage. | ||
|
|
||
| Args: | ||
| partition: Field paths or expressions used to partition documents into independent windows. | ||
| sort: Orderings specifying how documents are sorted within each partition. | ||
| frame: A `DocumentWindowFrame` defining a document-count window frame. | ||
| frame: A `DocumentWindowFrame` or `RangeWindowFrame` defining a sliding window frame. | ||
| """ | ||
|
|
||
| def __init__( | ||
|
|
@@ -404,7 +438,7 @@ def __init__( | |
| | str | ||
| ] = None, | ||
| sort: Optional[Sequence[Ordering] | Ordering] = None, | ||
| frame: Optional[DocumentWindowFrame] = None, | ||
| frame: Optional[DocumentWindowFrame | RangeWindowFrame] = None, | ||
| ): | ||
| if partition is None: | ||
| partition_list = [] | ||
|
|
@@ -422,7 +456,7 @@ def __init__( | |
| else: | ||
| self.sort = [sort] if isinstance(sort, Ordering) else list(sort) | ||
|
|
||
| self.frame: Optional[DocumentWindowFrame] = frame | ||
| self.frame: Optional[DocumentWindowFrame | RangeWindowFrame] = frame | ||
|
|
||
| def __eq__(self, other: object) -> bool: | ||
| if not isinstance(other, WindowSpec): | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.