feat(firestore): [PQ] add all the remaining private preview stages#13218
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request is a substantial contribution, adding the remaining private preview stages for Firestore pipelines. The changes include implementing numerous new pipeline stages, refactoring existing pipeline code for better structure and consistency, and adding comprehensive unit and integration tests. The refactoring of PipelineResult.Data() and DataTo() to align with DocumentSnapshot is a good consistency improvement.
I've found a couple of critical issues in the new integration tests that will cause compilation errors due to leftover code. I've also pointed out some minor issues, including leftover debug code and an inconsistently named function parameter. Once these are addressed, this will be a solid addition to the library.
| if err != nil { | ||
| t.Fatalf("Failed to get data: %v", err) | ||
| } |
There was a problem hiding this comment.
There was a problem hiding this comment.
err is defined in the scope but it was already checked in L3777. This comment still seems relevant though.
| if err != nil { | ||
| t.Fatalf("Failed to get data: %v", err) | ||
| } |
| func (p *Pipeline) Unnest(fieldpathsOrSelectables any) *Pipeline { | ||
| if p.err != nil { | ||
| return p | ||
| } | ||
| stage, err := newUnnestStageFromAny(fieldpathsOrSelectables) |
There was a problem hiding this comment.
The parameter name fieldpathsOrSelectables is plural, but the function accepts a single any argument, not a variadic one. This is inconsistent with other functions like Replace and can be confusing. For clarity and consistency, please consider renaming it to the singular fieldpathOrSelectable and updating its usage within the function.
| func (p *Pipeline) Unnest(fieldpathsOrSelectables any) *Pipeline { | |
| if p.err != nil { | |
| return p | |
| } | |
| stage, err := newUnnestStageFromAny(fieldpathsOrSelectables) | |
| func (p *Pipeline) Unnest(fieldpathOrSelectable any) *Pipeline { | |
| if p.err != nil { | |
| return p | |
| } | |
| stage, err := newUnnestStageFromAny(fieldpathOrSelectable) |
| // bytes, _ := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true, Multiline: true}.Marshal(req) | ||
| // fmt.Println(string(bytes)) |
| if err != nil { | ||
| t.Fatalf("Failed to get data: %v", err) | ||
| } |
There was a problem hiding this comment.
err is defined in the scope but it was already checked in L3777. This comment still seems relevant though.
|
|
||
| // Any error here is a bug in the client. | ||
| if err != nil { | ||
| panic(fmt.Sprintf("firestore: %v", err)) |
There was a problem hiding this comment.
panic here seems undesirable. Why was Data() changed to not return an error?
There was a problem hiding this comment.
To be inline with existing Data() method
google-cloud-go/firestore/document.go
Lines 78 to 88 in 9a4cb31
| // bytes, _ := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true, Multiline: true}.Marshal(req) | ||
| // fmt.Println(string(bytes)) |
daniel-sanche
left a comment
There was a problem hiding this comment.
Left some initial comments, I'll try to take another look soon
| PipelineType: &pb.ExecutePipelineRequest_StructuredPipeline{ | ||
| StructuredPipeline: &pb.StructuredPipeline{Pipeline: pipelinePb}, | ||
| }, | ||
| // TODO: Add consistencyselector |
There was a problem hiding this comment.
Is this todo still valid? If it's meant to be long term, maybe add some more context
There was a problem hiding this comment.
Yes, it is still valid. I'll resolve it in next PR.
| stageNameSelect = "select" | ||
| stageNameUnion = "union" | ||
| stageNameUnnest = "unnest" | ||
| stageNameWhere = "where" |
There was a problem hiding this comment.
I noticed inputStageCollection names are handled in a different way, with the name strings hard-coded in-line. Should those be added to this constant list for consistency?
| stageNameAddFields = "add_fields" | ||
| stageNameAggregate = "aggregate" | ||
| stageNameDistinct = "distinct" | ||
| stageNameDocuments = "documents" |
There was a problem hiding this comment.
Other sdks have a Generic stage (which seems to be renamed to RawStage after the latest updates?). Do you have anything like that here?
There was a problem hiding this comment.
Will add in next PR.
| }, nil | ||
| } | ||
|
|
||
| type inputStageDocuments struct { |
There was a problem hiding this comment.
Something I was meaning to look into that you might have an answer to:
For the CollectionGroup above this, you're taking in an ancestor and passing it in as the first argument. Is that still valid? The other implementations I've seen seem to just be passing an empty string as the first argument, but I haven't dug into that yet
There was a problem hiding this comment.
Removed the function to match other implementations.
176319f to
f045b7d
Compare
d46767e to
b96e23d
Compare
shollyman
left a comment
There was a problem hiding this comment.
I'm a little slow to review given the chaining builder pattern.
Things that throw me:
- the differing behavior for error for happy path. One embeds an error in the existing entity and ignores the current spec in the chain of pipeline directives. The other returns a copy/clone of the pipeline?
- Field namings. I'm having trouble tracking down the corresponding protos. I see this is being built in a feature branch, where can I see the source protos for pipelines?
| // WithGroups sets the grouping keys for the aggregation. | ||
| func (a *AggregateSpec) WithGroups(fieldsOrSelectables ...any) *AggregateSpec { | ||
| a.groups, a.err = fieldsOrSelectablesToSelectables(fieldsOrSelectables...) | ||
| func (a *AggregateSpec) WithGroups(fieldpathsOrSelectables ...any) *AggregateSpec { |
There was a problem hiding this comment.
How much of the naming is coming from a common spec here? I'd expect more of an option pattern due to the WithGroups naming, but this appears to just set the Groups field of the AggregateSpec. Should it just be Groups()?
Feel free to ignore, I'm still coming to terms with this particular builder pattern.
The protos are here: google-cloud-go/firestore/apiv1/firestorepb/pipeline.pb.go Lines 43 to 52 in a3ee1f1 google-cloud-go/firestore/apiv1/firestorepb/document.pb.go Lines 621 to 629 in a3ee1f1 google-cloud-go/firestore/apiv1/firestorepb/document.pb.go Lines 668 to 704 in a3ee1f1 |
shollyman
left a comment
There was a problem hiding this comment.
After offline discussion about this, approving this PR.
…3194) b/364927702 1. add all the remaining private preview aggregate functions. Merging this PR completes the implementation of all the **type: "Function" subType : "Accumulators (Aggregation)"** private preview features. See "Firestore Features (Pipeline)" sheet in [go/firestore-query-tracker](http://go/firestore-query-tracker) for the list of features. Java reference: - https://github.com/googleapis/java-firestore/blob/ccaf9d4fac5bd87a4da3d37493ca66fdc7681bc3/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregateFunction.java#L43-L71 - https://github.com/googleapis/java-firestore/blob/ccaf9d4fac5bd87a4da3d37493ca66fdc7681bc3/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/AggregateFunction.java#L93-L111 2. add all the remaining private preview timestamp functions. Merging this PR completes the implementation of all the **type: "Function" subType: "Date / Timestamp"** private preview features. (except timestamp_trunc function which is not yet inmplemented in any of the SDKs. Requires additonal approvals from Firestore team and will be added to separate PR). 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#L2262-L2517 3. Add integration tests for all functions. 4. Remove Rand function since it is not targeted for private preview. 5. Renamed numericExprOrField to numericExprOrFieldPath since field is a separate type/expression. https://github.com/googleapis/google-cloud-go/blob/a3ee1f19068c6d3fb77ad797e29884a90d6402a2/firestore/pipeline_field.go#L21-L41 Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218
d27101e
into
googleapis:feature/fs-pipeline-queries
) 1. add all the private preview 'array' functions. Merging this PR completes the implementation of all the **type: "Function" subType : "Array"** private preview features (except 'maximum' and 'minimum' which are not yet implemented in any of the SDKs. Requires additonal approvals from Firestore team and will be added to separate PR). See "Firestore Features (Pipeline)" sheet in [go/firestore-query-tracker](http://go/firestore-query-tracker) for the list of features. Java reference: - https://github.com/googleapis/java-firestore/blob/wuandy/JavaPplPP/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java 2. add all the private preview 'string' functions. (except 'string_split' which is not yet implemented in any of the SDKs. Requires additonal approvals from Firestore team and will be added to separate PR) 3. add all the private preview 'vector' functions. 4. add remaining types to ConstantOf to match Java's implementation. Java reference: - https://github.com/googleapis/java-firestore/blob/ccaf9d4fac5bd87a4da3d37493ca66fdc7681bc3/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/expressions/Expression.java#L70-L211 Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194
b/364927702 - toExprOrField was renamed to asFieldExpr in https://github.com/googleapis/google-cloud-go/pull/13194/files#diff-4a55211f7d38a1f0599e2f4cc92795073f138b2c56b846c933bda19e26bc3a7a . There were a few call locations were rename was missed while resolving merge conflicts which caused build failures. Fixing those failures in this PR. - the function signature of Data was changed in #13218. It no longer returns err as second argument. Fixing this in this PR. - remove duplicate asInt64Expr and asStringExpr - Move pipeline tests to their own file Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194 - #13245
b/364927702 - Combine FieldOf and FieldOfPath to avoid verbose name FieldOfPath Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194 - #13245 - #13270 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1. Move PipelineStages integration tests. 2. Remove IsNaN, IsNotNaN, IsNull, IsNotNull, Equivalent as they are no longer supported by backend 3. Remove examples as commented here #13245 (comment) Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194 - #13245 - #13270 - #13271
Add raw stage similar to Java https://github.com/googleapis/java-firestore/blob/742fab6583c9a6f9c47cf0496124c3c9b05fe0ee/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java#L997-L1021 The raw stage is an escape hatch to allow customers to consume new stages supported by the backend without having to update their SDK to a version that adds the stage. Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194 - #13245 - #13270 - #13271 - #13279
Add consistency selector similar to existing requests Existing code for reference: **client.go :** https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/client.go#L405-L412 https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/client.go#L308-L317 https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/client.go#L490-L504 **query.go :** https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/query.go#L1406-L1412 https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/query.go#L1551-L1561 **list_documents.go :** https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/list_documents.go#L48-L55 Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194 - #13245 - #13270 - #13271 - #13279 - #13280 - #13281
1. Move PipelineStages integration tests. 2. Remove IsNaN, IsNotNaN, IsNull, IsNotNull, Equivalent as they are no longer supported by backend 3. Remove examples as commented here #13245 (comment) Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194 - #13245 - #13270 - #13271
Add raw stage similar to Java https://github.com/googleapis/java-firestore/blob/742fab6583c9a6f9c47cf0496124c3c9b05fe0ee/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Pipeline.java#L997-L1021 The raw stage is an escape hatch to allow customers to consume new stages supported by the backend without having to update their SDK to a version that adds the stage. Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194 - #13245 - #13270 - #13271 - #13279
Add consistency selector similar to existing requests Existing code for reference: **client.go :** https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/client.go#L405-L412 https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/client.go#L308-L317 https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/client.go#L490-L504 **query.go :** https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/query.go#L1406-L1412 https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/query.go#L1551-L1561 **list_documents.go :** https://github.com/googleapis/google-cloud-go/blob/66cc9bb6e158416897af1d1dc4b9001118db3373/firestore/list_documents.go#L48-L55 Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194 - #13245 - #13270 - #13271 - #13279 - #13280 - #13281
#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
add collection and collectiongroup stage options similar to Java https://github.com/googleapis/java-firestore/blob/742fab6583c9a6f9c47cf0496124c3c9b05fe0ee/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/CollectionGroupOptions.java#L34-L36 https://github.com/googleapis/java-firestore/blob/742fab6583c9a6f9c47cf0496124c3c9b05fe0ee/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/CollectionOptions.java#L34-L36 https://github.com/googleapis/java-firestore/blob/742fab6583c9a6f9c47cf0496124c3c9b05fe0ee/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/CollectionHints.java#L34-L40 Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194 - #13245 - #13270 - #13271 - #13279 - #13280 - #13282 - googleapis/gapic-generator-go#1661
Add ExecuteOptions similar to query run options which was introduced in #10164. GetRawData and GetText implementation similar to Java https://github.com/googleapis/java-firestore/blob/742fab6583c9a6f9c47cf0496124c3c9b05fe0ee/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/PipelineExecuteOptions.java https://github.com/googleapis/java-firestore/blob/742fab6583c9a6f9c47cf0496124c3c9b05fe0ee/google-cloud-firestore/src/main/java/com/google/cloud/firestore/pipeline/stages/ExplainOptions.java https://github.com/googleapis/java-firestore/blob/742fab6583c9a6f9c47cf0496124c3c9b05fe0ee/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ExplainStats.java#L42-L71 https://github.com/googleapis/java-firestore/blob/742fab6583c9a6f9c47cf0496124c3c9b05fe0ee/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITPipelineTest.java#L2474-L2498 Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194 - #13245 - #13270 - #13271 - #13279 - #13280 - #13281 - #13282 - googleapis/gapic-generator-go#1661 - #13283
Add CreateFrom() and Pipeline() similar to Java. https://github.com/googleapis/java-firestore/blob/742fab6583c9a6f9c47cf0496124c3c9b05fe0ee/google-cloud-firestore/src/main/java/com/google/cloud/firestore/PipelineSource.java#L140-L164 Previous pull requests - #12217 - #12425 - #12538 - #13147 - #13199 - #13218 - #13194 - #13245 - #13270 - #13271 - #13279 - #13280 - #13281 - #13282 - googleapis/gapic-generator-go#1661 - #13283 - #13274 - #13338
b/364927702
See "Firestore Features (Pipeline)" sheet in go/firestore-query-tracker
google-cloud-go/firestore/document.go
Lines 64 to 127 in 9a4cb31
Previous pull requests