Skip to content

Commit d46de63

Browse files
authored
Temporarily replace absl::flat_hash_map (#15300)
1 parent 1cce11c commit d46de63

File tree

7 files changed

+35
-12
lines changed

7 files changed

+35
-12
lines changed

Firestore/core/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ target_compile_definitions(
137137
target_link_libraries(
138138
firestore_util PUBLIC
139139
absl::base
140-
absl::flat_hash_map
141140
absl::memory
142141
absl::meta
143142
absl::optional
@@ -250,7 +249,6 @@ target_link_libraries(
250249
firestore_core PUBLIC
251250
LevelDB::LevelDB
252251
absl::base
253-
absl::flat_hash_map
254252
absl::memory
255253
absl::meta
256254
absl::optional

Firestore/core/src/model/object_value.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <algorithm>
2020
#include <map>
2121
#include <set>
22+
#include <unordered_map>
2223

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

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

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

252257
ByteString clientAlias(aliasMap.find(serverAliasString)->second);

Firestore/core/src/model/object_value.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <ostream>
2222
#include <set>
2323
#include <string>
24+
#include <unordered_map>
2425
#include <utility>
2526

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

8689
/** Recursively extracts the FieldPaths that are set in this ObjectValue. */
8790
FieldMask ToFieldMask() const;

Firestore/core/src/remote/datastore.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

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

19+
#include <unordered_map>
1920
#include <unordered_set>
2021
#include <utility>
2122

@@ -281,7 +282,9 @@ void Datastore::RunAggregateQueryWithCredentials(
281282
const core::Query& query,
282283
const std::vector<AggregateField>& aggregates,
283284
api::AggregateQueryCallback&& callback) {
284-
absl::flat_hash_map<std::string, std::string> aliasMap;
285+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
286+
// is upgraded to later than 20250127.0
287+
std::unordered_map<std::string, std::string> aliasMap;
285288
grpc::ByteBuffer message =
286289
MakeByteBuffer(datastore_serializer_.EncodeAggregateQueryRequest(
287290
query, aggregates, aliasMap));

Firestore/core/src/remote/remote_objc_bridge.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "Firestore/core/src/remote/remote_objc_bridge.h"
1818

1919
#include <map>
20+
#include <unordered_map>
2021

2122
#include "Firestore/core/src/core/database_info.h"
2223
#include "Firestore/core/src/core/query.h"
@@ -272,11 +273,13 @@ DatastoreSerializer::MergeLookupResponses(
272273
return result;
273274
}
274275

276+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
277+
// is upgraded to later than 20250127.0
275278
Message<google_firestore_v1_RunAggregationQueryRequest>
276279
DatastoreSerializer::EncodeAggregateQueryRequest(
277280
const core::Query& query,
278281
const std::vector<AggregateField>& aggregates,
279-
absl::flat_hash_map<std::string, std::string>& aliasMap) const {
282+
std::unordered_map<std::string, std::string>& aliasMap) const {
280283
Message<google_firestore_v1_RunAggregationQueryRequest> result;
281284
auto encodedTarget = serializer_.EncodeQueryTarget(query.ToAggregateTarget());
282285
result->parent = encodedTarget.parent;
@@ -291,7 +294,9 @@ DatastoreSerializer::EncodeAggregateQueryRequest(
291294
// De-duplicate aggregates based on the alias.
292295
// Since aliases are auto-computed from the operation and path,
293296
// equal aggregate will have the same alias.
294-
absl::flat_hash_map<std::string, AggregateField> uniqueAggregates;
297+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
298+
// is upgraded to later than 20250127.0
299+
std::unordered_map<std::string, AggregateField> uniqueAggregates;
295300
for (const AggregateField& aggregate : aggregates) {
296301
auto pair = std::pair<std::string, AggregateField>(
297302
aggregate.alias.StringValue(), aggregate);
@@ -365,9 +370,11 @@ DatastoreSerializer::EncodeAggregateQueryRequest(
365370
return result;
366371
}
367372

373+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
374+
// is upgraded to later than 20250127.0
368375
util::StatusOr<ObjectValue> DatastoreSerializer::DecodeAggregateQueryResponse(
369376
const grpc::ByteBuffer& response,
370-
const absl::flat_hash_map<std::string, std::string>& aliasMap) const {
377+
const std::unordered_map<std::string, std::string>& aliasMap) const {
371378
ByteBufferReader reader{response};
372379
auto message =
373380
Message<google_firestore_v1_RunAggregationQueryResponse>::TryParse(

Firestore/core/src/remote/remote_objc_bridge.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <memory>
2121
#include <string>
22+
#include <unordered_map>
2223
#include <utility>
2324
#include <vector>
2425

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

140+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
141+
// is upgraded to later than 20250127.0
139142
nanopb::Message<google_firestore_v1_RunAggregationQueryRequest>
140143
EncodeAggregateQueryRequest(
141144
const core::Query& query,
142145
const std::vector<model::AggregateField>& aggregates,
143-
absl::flat_hash_map<std::string, std::string>& aliasMap) const;
146+
std::unordered_map<std::string, std::string>& aliasMap) const;
144147

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

149154
const Serializer& serializer() const {
150155
return serializer_;

Firestore/core/test/unit/api/aggregate_query_test.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ TEST(AggregateQuery, GetCallsGetAggregateOk) {
110110
aggregate_fields_entry[0].value.integer_value = 10;
111111

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

116118
// Test ObjectValue result

0 commit comments

Comments
 (0)