Skip to content

Firestore COUNT API #1174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f58cad4
Firestore COUNT API
tom-andersen Dec 19, 2022
8eec324
Exempt from go/allstar check (#1173)
chkuang-g Dec 19, 2022
3c704e0
Token-changed listeners for iOS AppCheck (#1172)
AlmostMatt Dec 20, 2022
2cb8eb2
[macOS sandbox mode] Application group name mangling for semaphores (…
DellaBitta Dec 21, 2022
b59f275
Setup Desktop test workflow that detects C++ SDK breakage caused by i…
sunmou99 Dec 27, 2022
33c1831
[Bugfx] Fix Nightly Test Report template (#1181)
sunmou99 Jan 3, 2023
40e7025
Reduce number of RewardedAd loads on iOS in CI (#1180)
DellaBitta Jan 3, 2023
2810bef
Firestore COUNT implementation (WIP)
tom-andersen Jan 30, 2023
371b820
Firestore COUNT implementation (WIP)
tom-andersen Jan 30, 2023
e19f512
Merge remote-tracking branch 'origin/main' into tomandersen/countAPI
tom-andersen Jan 30, 2023
00570d7
Fix linting
tom-andersen Jan 30, 2023
1f3f40d
Fix linting
tom-andersen Jan 30, 2023
bed0cea
Fix linking
tom-andersen Jan 31, 2023
eb61c87
Merge remote-tracking branch 'origin/main' into tomandersen/countAPI
tom-andersen Jan 31, 2023
e6bb4df
Cleanup
tom-andersen Jan 31, 2023
088560d
Fix release notes
tom-andersen Jan 31, 2023
d928ae8
Format
tom-andersen Jan 31, 2023
c08a1ba
Fixes from review
tom-andersen Feb 8, 2023
dfa4248
Formatting
tom-andersen Feb 8, 2023
94fcdef
Responding to PR comments.
tom-andersen Feb 9, 2023
e9502a3
Add Hash
tom-andersen Feb 10, 2023
a4d88eb
Add Hash
tom-andersen Feb 10, 2023
d2d6d36
Fix copyright year
tom-andersen Feb 10, 2023
cedc0e2
Rename
tom-andersen Feb 10, 2023
04eca2e
Format
tom-andersen Feb 10, 2023
dc6e00c
Rename
tom-andersen Feb 10, 2023
281d2b5
Fixup constructor/assignment parameter naming.
tom-andersen Feb 10, 2023
398a262
Format
tom-andersen Feb 10, 2023
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
3 changes: 3 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ if (IOS)
${FIREBASE_SOURCE_DIR}/dynamic_links/src/include/firebase/dynamic_links/components.h)
set(firestore_HDRS
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/aggregate_query.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/aggregate_query_snapshot.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/aggregate_source.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/collection_reference.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/document_change.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/document_reference.h
Expand Down
6 changes: 6 additions & 0 deletions firestore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ else()
endif()

set(common_SRCS
src/common/aggregate_query.cc
src/common/aggregate_query_snapshot.cc
src/common/cleanup.h
src/common/collection_reference.cc
src/common/compiler_info.cc
Expand Down Expand Up @@ -185,6 +187,10 @@ set(android_SRCS

# Sources that apply to all non-Android platforms.
set(main_SRCS
src/main/aggregate_query_main.cc
src/main/aggregate_query_main.h
src/main/aggregate_query_snapshot_main.cc
src/main/aggregate_query_snapshot_main.h
src/main/collection_reference_main.cc
src/main/collection_reference_main.h
src/main/converter_main.h
Expand Down
2 changes: 1 addition & 1 deletion firestore/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ a Python3 installation.

# Architecture

It is easier to work this Firestore CPP SDK by keeping a high level archetecture in mind:
It is easier to work this Firestore CPP SDK by keeping a high level architecture in mind:

![architecture.png](architecture.png)

Expand Down
108 changes: 108 additions & 0 deletions firestore/src/common/aggregate_query.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "firestore/src/include/firebase/firestore/aggregate_query.h"
#include "firestore/src/common/cleanup.h"
#include "firestore/src/common/futures.h"
#include "firestore/src/common/util.h"
#include "firestore/src/include/firebase/firestore/aggregate_query_snapshot.h"

#if defined(__ANDROID__)
// TODO(tomandersen) #include "firestore/src/android/aggregate_query_android.h"
#else
#include "firestore/src/main/aggregate_query_main.h"
#endif // defined(__ANDROID__)

namespace firebase {
namespace firestore {

using CleanupFnQuery = CleanupFn<AggregateQuery>;

AggregateQuery::AggregateQuery() {}

AggregateQuery::AggregateQuery(const AggregateQuery& aggregate_query) {
if (aggregate_query.internal_) {
internal_ = new AggregateQueryInternal(*aggregate_query.internal_);
}
CleanupFnQuery::Register(this, internal_);
}

AggregateQuery::AggregateQuery(AggregateQuery&& aggregate_query) {
CleanupFnQuery::Unregister(&aggregate_query, aggregate_query.internal_);
std::swap(internal_, aggregate_query.internal_);
CleanupFnQuery::Register(this, internal_);
}

AggregateQuery::AggregateQuery(AggregateQueryInternal* internal)
: internal_(internal) {
SIMPLE_HARD_ASSERT(internal != nullptr);
CleanupFnQuery::Register(this, internal_);
}

AggregateQuery::~AggregateQuery() {
CleanupFnQuery::Unregister(this, internal_);
delete internal_;
internal_ = nullptr;
}

AggregateQuery& AggregateQuery::operator=(
const AggregateQuery& aggregate_query) {
if (this == &aggregate_query) {
return *this;
}

CleanupFnQuery::Unregister(this, internal_);
delete internal_;
if (aggregate_query.internal_) {
internal_ = new AggregateQueryInternal(*aggregate_query.internal_);
} else {
internal_ = nullptr;
}
CleanupFnQuery::Register(this, internal_);
return *this;
}

AggregateQuery& AggregateQuery::operator=(AggregateQuery&& aggregate_query) {
if (this == &aggregate_query) {
return *this;
}

CleanupFnQuery::Unregister(&aggregate_query, aggregate_query.internal_);
CleanupFnQuery::Unregister(this, internal_);
delete internal_;
internal_ = aggregate_query.internal_;
aggregate_query.internal_ = nullptr;
CleanupFnQuery::Register(this, internal_);
return *this;
}

Query AggregateQuery::query() const {
if (!internal_) return {};
return internal_->query();
}

Future<AggregateQuerySnapshot> AggregateQuery::Get(
AggregateSource aggregate_source) const {
if (!internal_) return FailedFuture<AggregateQuerySnapshot>();
return internal_->Get(aggregate_source);
}

bool operator==(const AggregateQuery& lhs, const AggregateQuery& rhs) {
return EqualityCompare(lhs.internal_, rhs.internal_);
}

} // namespace firestore
} // namespace firebase
118 changes: 118 additions & 0 deletions firestore/src/common/aggregate_query_snapshot.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "firestore/src/include/firebase/firestore/aggregate_query_snapshot.h"

#include "firestore/src/common/cleanup.h"
#include "firestore/src/common/util.h"
#include "firestore/src/include/firebase/firestore/aggregate_query.h"

#if defined(__ANDROID__)
// TODO(tomandersen) #include
// "firestore/src/android/aggregate_query_snapshot_android.h"
#else
#include "firestore/src/main/aggregate_query_snapshot_main.h"
#endif // defined(__ANDROID__)

namespace firebase {
namespace firestore {

using CleanupFnAggregateQuerySnapshot = CleanupFn<AggregateQuerySnapshot>;

AggregateQuerySnapshot::AggregateQuerySnapshot() {}

AggregateQuerySnapshot::AggregateQuerySnapshot(
const AggregateQuerySnapshot& snapshot) {
if (snapshot.internal_) {
internal_ = new AggregateQuerySnapshotInternal(*snapshot.internal_);
}
CleanupFnAggregateQuerySnapshot::Register(this, internal_);
}

AggregateQuerySnapshot::AggregateQuerySnapshot(
AggregateQuerySnapshot&& snapshot) {
CleanupFnAggregateQuerySnapshot::Unregister(&snapshot, snapshot.internal_);
std::swap(internal_, snapshot.internal_);
CleanupFnAggregateQuerySnapshot::Register(this, internal_);
}

AggregateQuerySnapshot::AggregateQuerySnapshot(
AggregateQuerySnapshotInternal* internal)
: internal_(internal) {
SIMPLE_HARD_ASSERT(internal != nullptr);
CleanupFnAggregateQuerySnapshot::Register(this, internal_);
}

AggregateQuerySnapshot::~AggregateQuerySnapshot() {
CleanupFnAggregateQuerySnapshot::Unregister(this, internal_);
delete internal_;
internal_ = nullptr;
}

AggregateQuerySnapshot& AggregateQuerySnapshot::operator=(
const AggregateQuerySnapshot& snapshot) {
if (this == &snapshot) {
return *this;
}

CleanupFnAggregateQuerySnapshot::Unregister(this, internal_);
delete internal_;
if (snapshot.internal_) {
internal_ = new AggregateQuerySnapshotInternal(*snapshot.internal_);
} else {
internal_ = nullptr;
}
CleanupFnAggregateQuerySnapshot::Register(this, internal_);
return *this;
}

AggregateQuerySnapshot& AggregateQuerySnapshot::operator=(
AggregateQuerySnapshot&& snapshot) {
if (this == &snapshot) {
return *this;
}

CleanupFnAggregateQuerySnapshot::Unregister(&snapshot, snapshot.internal_);
CleanupFnAggregateQuerySnapshot::Unregister(this, internal_);
delete internal_;
internal_ = snapshot.internal_;
snapshot.internal_ = nullptr;
CleanupFnAggregateQuerySnapshot::Register(this, internal_);
return *this;
}

AggregateQuery AggregateQuerySnapshot::query() const {
if (!internal_) return {};
return internal_->query();
}

int64_t AggregateQuerySnapshot::count() const {
if (!internal_) return 0;
return internal_->count();
}

bool operator==(const AggregateQuerySnapshot& lhs,
const AggregateQuerySnapshot& rhs) {
return EqualityCompare(lhs.internal_, rhs.internal_);
}

size_t AggregateQuerySnapshot::Hash() const {
if (!internal_) return {};
return internal_->Hash();
}

} // namespace firestore
} // namespace firebase
6 changes: 6 additions & 0 deletions firestore/src/common/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "firestore/src/common/futures.h"
#include "firestore/src/common/hard_assert_common.h"
#include "firestore/src/common/util.h"
#include "firestore/src/include/firebase/firestore/aggregate_query.h"
#include "firestore/src/include/firebase/firestore/document_snapshot.h"
#include "firestore/src/include/firebase/firestore/field_path.h"
#include "firestore/src/include/firebase/firestore/field_value.h"
Expand Down Expand Up @@ -106,6 +107,11 @@ Firestore* Query::firestore() {
return internal_->firestore();
}

AggregateQuery Query::Count() const {
if (!internal_) return {};
return internal_->Count();
}

Query Query::WhereEqualTo(const std::string& field,
const FieldValue& value) const {
return WhereEqualTo(FieldPath::FromDotSeparatedString(field), value);
Expand Down
12 changes: 12 additions & 0 deletions firestore/src/common/type_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
namespace firebase {
namespace firestore {

class AggregateQuery;
class AggregateQueryInternal;
class AggregateQuerySnapshot;
class AggregateQuerySnapshotInternal;
class CollectionReference;
class CollectionReferenceInternal;
class DocumentChange;
Expand Down Expand Up @@ -54,6 +58,14 @@ class WriteBatchInternal;
template <typename T>
struct InternalTypeMap {};

template <>
struct InternalTypeMap<AggregateQuery> {
using type = AggregateQueryInternal;
};
template <>
struct InternalTypeMap<AggregateQuerySnapshot> {
using type = AggregateQuerySnapshotInternal;
};
template <>
struct InternalTypeMap<CollectionReference> {
using type = CollectionReferenceInternal;
Expand Down
3 changes: 3 additions & 0 deletions firestore/src/include/firebase/firestore.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "firebase/log.h"
// Include *all* the public headers to make sure including just "firestore.h" is
// sufficient for users.
#include "firebase/firestore/aggregate_query.h"
#include "firebase/firestore/aggregate_query_snapshot.h"
#include "firebase/firestore/aggregate_source.h"
#include "firebase/firestore/collection_reference.h"
#include "firebase/firestore/document_change.h"
#include "firebase/firestore/document_reference.h"
Expand Down
Loading