Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Firestore/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ target_compile_definitions(
target_link_libraries(
firestore_util PUBLIC
absl::base
absl::flat_hash_map
absl::memory
absl::meta
absl::optional
Expand Down Expand Up @@ -250,7 +249,6 @@ target_link_libraries(
firestore_core PUBLIC
LevelDB::LevelDB
absl::base
absl::flat_hash_map
absl::memory
absl::meta
absl::optional
Expand Down
9 changes: 7 additions & 2 deletions Firestore/core/src/model/object_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>

#include "Firestore/Protos/nanopb/google/firestore/v1/document.nanopb.h"
#include "Firestore/core/src/model/value_util.h"
Expand Down Expand Up @@ -227,10 +228,12 @@ ObjectValue ObjectValue::FromFieldsEntry(
return ObjectValue{std::move(value)};
}

// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
// is upgraded to later than 20250127.0
ObjectValue ObjectValue::FromAggregateFieldsEntry(
google_firestore_v1_AggregationResult_AggregateFieldsEntry* fields_entry,
pb_size_t count,
const absl::flat_hash_map<std::string, std::string>& aliasMap) {
const std::unordered_map<std::string, std::string>& aliasMap) {
Message<google_firestore_v1_Value> value;
value->which_value_type = google_firestore_v1_Value_map_value_tag;

Expand All @@ -246,7 +249,9 @@ ObjectValue ObjectValue::FromAggregateFieldsEntry(
// using the client-side alias.
ByteString serverAlias(entry.key);
std::string serverAliasString = serverAlias.ToString();
HARD_ASSERT(aliasMap.contains(serverAliasString),
// TODO(b/443765747) Revert back to aliasMap.contains(serverAliasString)
// after the absl version is upgraded to later than 20250127.0
HARD_ASSERT(aliasMap.find(serverAliasString) != aliasMap.end(),
"%s not present in aliasMap", serverAlias.ToString());

ByteString clientAlias(aliasMap.find(serverAliasString)->second);
Expand Down
5 changes: 4 additions & 1 deletion Firestore/core/src/model/object_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <ostream>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>

#include "Firestore/Protos/nanopb/google/firestore/v1/document.nanopb.h"
Expand Down Expand Up @@ -78,10 +79,12 @@ class ObjectValue {
* @param count Count of fields in `fields_entry`.
* @return The created `ObjectValue`.
*/
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
// is upgraded to later than 20250127.0
static ObjectValue FromAggregateFieldsEntry(
google_firestore_v1_AggregationResult_AggregateFieldsEntry* fields_entry,
pb_size_t count,
const absl::flat_hash_map<std::string, std::string>& aliasMap);
const std::unordered_map<std::string, std::string>& aliasMap);

/** Recursively extracts the FieldPaths that are set in this ObjectValue. */
FieldMask ToFieldMask() const;
Expand Down
5 changes: 4 additions & 1 deletion Firestore/core/src/remote/datastore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "Firestore/core/src/remote/datastore.h"

#include <unordered_map>
#include <unordered_set>
#include <utility>

Expand Down Expand Up @@ -281,7 +282,9 @@ void Datastore::RunAggregateQueryWithCredentials(
const core::Query& query,
const std::vector<AggregateField>& aggregates,
api::AggregateQueryCallback&& callback) {
absl::flat_hash_map<std::string, std::string> aliasMap;
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
// is upgraded to later than 20250127.0
std::unordered_map<std::string, std::string> aliasMap;
grpc::ByteBuffer message =
MakeByteBuffer(datastore_serializer_.EncodeAggregateQueryRequest(
query, aggregates, aliasMap));
Expand Down
13 changes: 10 additions & 3 deletions Firestore/core/src/remote/remote_objc_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Firestore/core/src/remote/remote_objc_bridge.h"

#include <map>
#include <unordered_map>

#include "Firestore/core/src/core/database_info.h"
#include "Firestore/core/src/core/query.h"
Expand Down Expand Up @@ -272,11 +273,13 @@ DatastoreSerializer::MergeLookupResponses(
return result;
}

// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
// is upgraded to later than 20250127.0
Message<google_firestore_v1_RunAggregationQueryRequest>
DatastoreSerializer::EncodeAggregateQueryRequest(
const core::Query& query,
const std::vector<AggregateField>& aggregates,
absl::flat_hash_map<std::string, std::string>& aliasMap) const {
std::unordered_map<std::string, std::string>& aliasMap) const {
Message<google_firestore_v1_RunAggregationQueryRequest> result;
auto encodedTarget = serializer_.EncodeQueryTarget(query.ToAggregateTarget());
result->parent = encodedTarget.parent;
Expand All @@ -291,7 +294,9 @@ DatastoreSerializer::EncodeAggregateQueryRequest(
// De-duplicate aggregates based on the alias.
// Since aliases are auto-computed from the operation and path,
// equal aggregate will have the same alias.
absl::flat_hash_map<std::string, AggregateField> uniqueAggregates;
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
// is upgraded to later than 20250127.0
std::unordered_map<std::string, AggregateField> uniqueAggregates;
for (const AggregateField& aggregate : aggregates) {
auto pair = std::pair<std::string, AggregateField>(
aggregate.alias.StringValue(), aggregate);
Expand Down Expand Up @@ -365,9 +370,11 @@ DatastoreSerializer::EncodeAggregateQueryRequest(
return result;
}

// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
// is upgraded to later than 20250127.0
util::StatusOr<ObjectValue> DatastoreSerializer::DecodeAggregateQueryResponse(
const grpc::ByteBuffer& response,
const absl::flat_hash_map<std::string, std::string>& aliasMap) const {
const std::unordered_map<std::string, std::string>& aliasMap) const {
ByteBufferReader reader{response};
auto message =
Message<google_firestore_v1_RunAggregationQueryResponse>::TryParse(
Expand Down
9 changes: 7 additions & 2 deletions Firestore/core/src/remote/remote_objc_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -136,15 +137,19 @@ class DatastoreSerializer {
util::StatusOr<std::vector<model::Document>> MergeLookupResponses(
const std::vector<grpc::ByteBuffer>& responses) const;

// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
// is upgraded to later than 20250127.0
nanopb::Message<google_firestore_v1_RunAggregationQueryRequest>
EncodeAggregateQueryRequest(
const core::Query& query,
const std::vector<model::AggregateField>& aggregates,
absl::flat_hash_map<std::string, std::string>& aliasMap) const;
std::unordered_map<std::string, std::string>& aliasMap) const;

// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
// is upgraded to later than 20250127.0
util::StatusOr<model::ObjectValue> DecodeAggregateQueryResponse(
const grpc::ByteBuffer& response,
const absl::flat_hash_map<std::string, std::string>& aliasMap) const;
const std::unordered_map<std::string, std::string>& aliasMap) const;

const Serializer& serializer() const {
return serializer_;
Expand Down
4 changes: 3 additions & 1 deletion Firestore/core/test/unit/api/aggregate_query_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ TEST(AggregateQuery, GetCallsGetAggregateOk) {
aggregate_fields_entry[0].value.integer_value = 10;

// Test alias map
absl::flat_hash_map<std::string, std::string> alias_map;
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
// is upgraded to later than 20250127.0
std::unordered_map<std::string, std::string> alias_map;
alias_map["aggregate_0"] = "count";

// Test ObjectValue result
Expand Down
Loading