Skip to content

feat(firestore): return native Go types from AggregationQuery.Get()#13651

Open
toshi38 wants to merge 1 commit intogoogleapis:mainfrom
toshi38:toshi38/emulator-types
Open

feat(firestore): return native Go types from AggregationQuery.Get()#13651
toshi38 wants to merge 1 commit intogoogleapis:mainfrom
toshi38:toshi38/emulator-types

Conversation

@toshi38
Copy link
Copy Markdown

@toshi38 toshi38 commented Jan 21, 2026

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

@toshi38 toshi38 requested review from a team January 21, 2026 14:10
@toshi38 toshi38 requested a review from a team as a code owner January 21, 2026 14:10
@product-auto-label product-auto-label Bot added the api: firestore Issues related to the Firestore API. label Jan 21, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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, AggregationQuery.Get() could return different types depending on whether it was interacting with the Firestore emulator or production, leading to developer friction. The update ensures that aggregation results consistently return native Go types such as int64, float64, and nil, thereby improving API predictability and simplifying client-side type handling.

Highlights

  • Type Consistency: The AggregationQuery.Get() method now consistently returns native Go types (int64, float64, nil) instead of *firestorepb.Value proto types.
  • Emulator/Production Alignment: This change resolves inconsistencies in behavior between the Firestore emulator and production environments regarding aggregation result types.
  • Simplified Client Code: Users no longer need to implement type switches to handle varying return types, leading to cleaner and more predictable client-side code.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 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.

Comment thread firestore/integration_test.go Outdated
Comment on lines 2917 to 2946
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
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
		}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduced

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
@toshi38 toshi38 force-pushed the toshi38/emulator-types branch from ab1e2f0 to 4228fc5 Compare January 21, 2026 14:16
@shollyman shollyman requested a review from bhshkh January 21, 2026 22:40
@bhshkh
Copy link
Copy Markdown
Contributor

bhshkh commented Jan 26, 2026

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:

  • Runtime Panics: A direct assertion like res["count"].(*pb.Value) will now trigger a panic at runtime because the value is no longer a pointer to a proto message .
  • Logic Errors: Safe assertions (e.g., v, ok := res["count"].(*pb.Value)) will now return ok == false, likely breaking the application's logic .

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.

firestore: AggregationQuery.Get() returns different types for emulator vs production (*firestorepb.Value vs int64)

2 participants