You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FR] Add SUM Functionality to AggregateQuerySnapshot #1703
Hello,
The Firestore C++ SDK currently supports only the count() method in the firebase::firestore::AggregateQuerySnapshot class but lacks a sum() method (and avg()), which is essential for aggregating numeric fields across documents.
Current State
The public functions of AggregateQuerySnapshot are:
This enhancement would also benefit the Flutter SDK, which relies on the Firestore C++ SDK for Windows platform support. For example, in the FlutterFire plugin, unsupported aggregation types like sum currently result in:
...
caseAggregateType::sum:
std::cout <<"Sum is not supported on C++"<< std::endl;
break;
...
Adding sum() to the C++ SDK would also benefit Flutter developers using Firestore on Windows.
Benefits
Implementing a sum() method would:
Provide access to Firestore's aggregation capabilities in the C++ SDK.
Support more use cases for C++ and Flutter developers.
Looking forward to hearing thoughts and feedback!
Thanks,
Heads up for anyone picking this up: on desktop the core already does the work.
The Firestore core the SDK vendors (firebase-ios-sdk, pinned in cmake/external/firestore.cmake) carries aggregations end to end. From the
built libfirestore_core.a:
and model::AggregateField is enum class OpKind { Sum, Avg, Count }.
Nothing calls it. QueryInternal::Count() reaches for query_.Count(), and query_.Aggregate() has no caller anywhere in the repo. So for the desktop
path this is exposing an API over machinery that already works, not
implementing aggregation.
Results come back in the ObjectValue keyed by the alias you asked for. Worth
knowing: a sum of integers arrives as integer_value and a sum of doubles as double_value, so reading only the double gives 0 for the integer case.
I've got this working locally against the Firestore emulator (sum, average,
filtered aggregations, sparse fields) as a patch we carry downstream. It's
desktop-only and its API shape doesn't match where this issue is heading, so
I'm not proposing it as-is — just flagging that the desktop half is smaller
than it looks.
Also: AVERAGE has no issue or PR of its own, only SUM.
Activity
google-oss-bot commentedon Mar 31, 2025
I found a few problems with this issue:
cherylEnkidu commentedon Mar 31, 2025
Hi @KKimj , thank you for filling out the ticket. This has been added to the feature request list.
jwinarske commentedon Sep 2, 2026
Heads up for anyone picking this up: on desktop the core already does the work.
The Firestore core the SDK vendors (firebase-ios-sdk, pinned in
cmake/external/firestore.cmake) carries aggregations end to end. From thebuilt
libfirestore_core.a:and
model::AggregateFieldisenum class OpKind { Sum, Avg, Count }.Nothing calls it.
QueryInternal::Count()reaches forquery_.Count(), andquery_.Aggregate()has no caller anywhere in the repo. So for the desktoppath this is exposing an API over machinery that already works, not
implementing aggregation.
Results come back in the
ObjectValuekeyed by the alias you asked for. Worthknowing: a sum of integers arrives as
integer_valueand a sum of doubles asdouble_value, so reading only the double gives 0 for the integer case.I've got this working locally against the Firestore emulator (sum, average,
filtered aggregations, sparse fields) as a patch we carry downstream. It's
desktop-only and its API shape doesn't match where this issue is heading, so
I'm not proposing it as-is — just flagging that the desktop half is smaller
than it looks.
Also: AVERAGE has no issue or PR of its own, only SUM.