-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(firestore): [PQ] introduce pipeline snapshots #13588
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
Merged
bhshkh
merged 9 commits into
googleapis:feature/fs-pipeline-queries
from
bhshkh:feat/fspq-pipeline-snapshot
Jan 13, 2026
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
71c456c
feat(firestore): [PQ] introduce pipeline snapshots
bhshkh 9379a7f
Update firestore/pipeline_snapshot.go
bhshkh 5156d81
Update firestore/pipeline_snapshot.go
bhshkh aef86e7
Update firestore/pipeline_snapshot.go
bhshkh 4ddcbf9
gofmt
bhshkh 98e7d00
add comments
bhshkh e469353
Update firestore/pipeline.go
bhshkh 4e31e46
Update firestore/pipeline_snapshot.go
bhshkh 5c65982
fix integration tests
bhshkh 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 |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package firestore | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| pb "cloud.google.com/go/firestore/apiv1/firestorepb" | ||
| "google.golang.org/api/iterator" | ||
| "google.golang.org/protobuf/types/known/anypb" | ||
| "google.golang.org/protobuf/types/known/wrapperspb" | ||
| ) | ||
|
|
||
| type PipelineSnapshot struct { | ||
| iter *PipelineResultIterator | ||
| } | ||
|
|
||
| func (ps *PipelineSnapshot) Results() *PipelineResultIterator { | ||
| return ps.iter | ||
| } | ||
|
|
||
| // ExplainStats returns stats from query explain. | ||
| // If [WithExplainMode] was set to [ExplainModeExplain] or left unset, then no stats will be available. | ||
| func (ps *PipelineSnapshot) ExplainStats() *ExplainStats { | ||
| if ps == nil { | ||
| return &ExplainStats{err: errors.New("firestore: PipelineSnapshot is nil")} | ||
| } | ||
| if ps.iter == nil { | ||
| return &ExplainStats{err: errors.New("firestore: PipelineResultIterator is nil")} | ||
| } | ||
| if ps.iter.err == nil || ps.iter.err != iterator.Done { | ||
| return &ExplainStats{err: errStatsBeforeEnd} | ||
| } | ||
| statsPb, statsErr := ps.iter.iter.getExplainStats() | ||
| return &ExplainStats{statsPb: statsPb, err: statsErr} | ||
| } | ||
|
|
||
| // ExplainStats is query explain stats. | ||
| // | ||
| // Contains all metadata related to pipeline planning and execution, specific | ||
| // contents depend on the supplied pipeline options. | ||
| type ExplainStats struct { | ||
| statsPb *pb.ExplainStats | ||
| err error | ||
| } | ||
|
|
||
| // RawData returns the explain stats in an encoded proto format, as returned from the Firestore backend. | ||
| // The caller is responsible for unpacking this proto message. | ||
| func (es *ExplainStats) RawData() (*anypb.Any, error) { | ||
| if es.err != nil { | ||
| return nil, es.err | ||
| } | ||
| if es.statsPb == nil { | ||
| return nil, nil | ||
| } | ||
|
|
||
| return es.statsPb.GetData(), nil | ||
| } | ||
|
|
||
| // Text returns the explain stats string verbatim as returned from the Firestore backend | ||
| // when explain stats were requested with `outputFormat = 'text'` | ||
| // If explain stats were requested with `outputFormat = 'json'`, this returns the explain stats | ||
| // as stringified JSON, which was returned from the Firestore backend. | ||
|
bhshkh marked this conversation as resolved.
Outdated
|
||
| func (es *ExplainStats) Text() (string, error) { | ||
| if es.err != nil { | ||
| return "", es.err | ||
| } | ||
| if es.statsPb == nil || es.statsPb.GetData() == nil { | ||
| return "", nil | ||
| } | ||
|
|
||
| var data wrapperspb.StringValue | ||
| if err := es.statsPb.GetData().UnmarshalTo(&data); err != nil { | ||
| return "", fmt.Errorf("firestore: failed to unmarshal Any to wrapperspb.StringValue: %w", err) | ||
| } | ||
|
|
||
| return data.GetValue(), nil | ||
| } | ||
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.