Skip to content

feat(firestore): [PQ] add consistency selector#13282

Merged
bhshkh merged 5 commits intogoogleapis:feature/fs-pipeline-queriesfrom
bhshkh:feature/fspq-consistency-selctor
Nov 3, 2025
Merged

feat(firestore): [PQ] add consistency selector#13282
bhshkh merged 5 commits intogoogleapis:feature/fs-pipeline-queriesfrom
bhshkh:feature/fspq-consistency-selctor

Conversation

@bhshkh
Copy link
Copy Markdown
Contributor

@bhshkh bhshkh commented Oct 31, 2025

Add consistency selector similar to existing requests

Existing code for reference:

client.go :

// WithReadOptions specifies constraints for accessing documents from the database,
// e.g. at what time snapshot to read the documents.
func (c *Client) WithReadOptions(opts ...ReadOption) *Client {
for _, ro := range opts {
ro.apply(c.readSettings)
}
return c
}

// Note that transaction ID and other consistency selectors are mutually exclusive.
// We respect the transaction first, any read options passed by the caller second,
// and any read options stored in the client third.
if rt, hasOpts := parseReadTime(c, rs); hasOpts {
req.ConsistencySelector = &pb.BatchGetDocumentsRequest_ReadTime{ReadTime: rt}
}
if tid != nil {
req.ConsistencySelector = &pb.BatchGetDocumentsRequest_Transaction{Transaction: tid}
}

// ReadTime specifies a time-specific snapshot of the database to read.
func ReadTime(t time.Time) ReadOption {
return readTime(t)
}
type readTime time.Time
func (rt readTime) apply(rs *readSettings) {
rs.readTime = time.Time(rt)
}
// ReadOption interface allows for abstraction of computing read time settings.
type ReadOption interface {
apply(*readSettings)
}

query.go :

// Respect transactions first and read options (read time) second
if rt, hasOpts := parseReadTime(client, it.readSettings); hasOpts {
req.ConsistencySelector = &pb.RunQueryRequest_ReadTime{ReadTime: rt}
}
if it.tid != nil {
req.ConsistencySelector = &pb.RunQueryRequest_Transaction{Transaction: it.tid}
}

// WithReadOptions specifies constraints for accessing documents from the database,
// e.g. at what time snapshot to read the documents.
func (q *Query) WithReadOptions(opts ...ReadOption) *Query {
if q.readSettings == nil {
q.readSettings = &readSettings{}
}
for _, ro := range opts {
ro.apply(q.readSettings)
}
return q
}

list_documents.go :

// Transactions and ReadTime are mutually exclusive; Transactions should be
// respected before read time.
if rt, hasOpts := parseReadTime(client, rs); hasOpts {
req.ConsistencySelector = &pb.ListDocumentsRequest_ReadTime{ReadTime: rt}
}
if tid != nil {
req.ConsistencySelector = &pb.ListDocumentsRequest_Transaction{Transaction: tid}
}

Previous pull requests

@product-auto-label product-auto-label Bot added the api: firestore Issues related to the Firestore API. label Oct 31, 2025
@bhshkh
Copy link
Copy Markdown
Contributor Author

bhshkh commented Oct 31, 2025

/gemini review

@bhshkh bhshkh marked this pull request as ready for review October 31, 2025 23:16
@bhshkh bhshkh requested review from a team October 31, 2025 23:16
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 adds support for consistency selectors to Firestore pipelines, including WithReadOptions and execution within transactions. The changes are logical and include necessary integration tests. I have a couple of suggestions for firestore/pipeline.go to improve code clarity and remove a redundant check.

Comment thread firestore/pipeline.go Outdated
Comment thread firestore/pipeline.go Outdated
@bhshkh bhshkh merged commit 4cd1053 into googleapis:feature/fs-pipeline-queries Nov 3, 2025
181 of 182 checks passed
@bhshkh bhshkh deleted the feature/fspq-consistency-selctor branch November 3, 2025 18:39
bhshkh added a commit that referenced this pull request Nov 10, 2025
#13283)

Changes in this PR:

1. firestore_client.go : Updated generated client as per
googleapis/gapic-generator-go#1661 . Removed
retries from tests since the headers have now been fixed.
2. Remove Equivalent since it was removed from backend.
3. Add/update comments
4. Add timestamp truncate (pending from
#13194) and string
split (pending from
#13245) functions.
5. add all the private preview general, key, logical (except iferror),
type and object functions.
See "Firestore Features (Pipeline)" sheet in
[go/firestore-query-tracker](http://go/firestore-query-tracker) for the
list of functions.
    Java reference:
-
https://github.com/googleapis/java-firestore/blob/ccaf9d4fac5bd87a4da3d37493ca66fdc7681bc3/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java



Previous pull requests

- #12217
- #12425
- #12538
- #13147
- #13199
- #13218
- #13194
- #13245
- #13270
- #13271
- #13279
- #13280
- #13281
- #13282
- googleapis/gapic-generator-go#1661
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: firestore Issues related to the Firestore API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants