feat(firestore): return native Go types from AggregationQuery.Get()#13651
feat(firestore): return native Go types from AggregationQuery.Get()#13651toshi38 wants to merge 1 commit intogoogleapis:mainfrom
Conversation
Summary of ChangesHello @toshi38, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Google Cloud Firestore client library for Go by standardizing the return types for aggregation queries. Previously, Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request modifies AggregationQuery.Get() to return native Go types (int64, float64, nil) instead of protobuf types, which resolves an inconsistency between the emulator and production environments. The changes are well-implemented, and the tests have been comprehensively updated to reflect the new behavior. I have one suggestion to improve the test helper function for comparing aggregation results, aiming for more concise code and better error reporting.
| switch val1 := v1.(type) { | ||
| case int64: | ||
| val2, ok := v2.(int64) | ||
| if !ok { | ||
| r.Errorf("aggResultsEquals: type mismatch for key %q: got %T, want int64", k, v2) | ||
| return false | ||
| } | ||
| if val1 != val2 { | ||
| r.Errorf("aggResultsEquals: value mismatch for key %q: got %v, want %v", k, val1, val2) | ||
| return false | ||
| } | ||
| case float64: | ||
| val2, ok := v2.(float64) | ||
| if !ok { | ||
| r.Errorf("aggResultsEquals: type mismatch for key %q: got %T, want float64", k, v2) | ||
| return false | ||
| } | ||
| if val1 != val2 { | ||
| r.Errorf("aggResultsEquals: value mismatch for key %q: got %v, want %v", k, val1, val2) | ||
| return false | ||
| } | ||
| case nil: | ||
| if v2 != nil { | ||
| r.Errorf("aggResultsEquals: value mismatch for key %q: got %v, want nil", k, v2) | ||
| return false | ||
| } | ||
| default: | ||
| r.Errorf("aggResultsEquals: unexpected type %T for key %q", v1, k) | ||
| return false | ||
| } |
There was a problem hiding this comment.
This type switch is quite verbose and can be simplified significantly by using testutil.Diff, which was used in the previous implementation. This would make the code more concise and maintainable. It would also provide richer diff output in case of a mismatch, which is an advantage over the current implementation.
// Compare native Go types (int64, float64, nil)
if diff := testutil.Diff(v1, v2); diff != "" {
r.Errorf("aggResultsEquals: mismatch for key %q (-want +got):\n%s", k, diff)
return false
}Fix AggregationQuery.Get() to return native Go types (int64, float64, nil) instead of *firestorepb.Value proto types. This resolves inconsistent behavior between the Firestore emulator and production, where users had to write type switches to handle both cases. Fixes googleapis#13646
ab1e2f0 to
4228fc5
Compare
|
This is a breaking change and cannot be accepted in its current format. While the function's signature—returning AggregationResult (which is a map[string]interface{})—remains the same, the underlying types of the values stored within that map are being altered In Go, users often interact with interface{} values by using type assertions. If a user's code previously relied on the results being of type *pb.Value, the change to native types (like int64 or float64) will cause those assertions to fail. Specifically:
|
Fix AggregationQuery.Get() to return native Go types (int64, float64, nil) instead of *firestorepb.Value proto types. This resolves inconsistent behavior between the Firestore emulator and production, where users had to write type switches to handle both cases.
Fixes #13646