Skip to content

Tomandersen/count api #1236

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 53 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
de5bc65
Firestore COUNT API (#1174)
tom-andersen Feb 10, 2023
fb86fa3
Merge branch 'main' into count
tom-andersen Feb 13, 2023
60ab28d
Fix linking
tom-andersen Jan 31, 2023
3a68030
Cleanup
tom-andersen Jan 31, 2023
558b317
Responding to PR comments.
tom-andersen Feb 9, 2023
0141434
Rename
tom-andersen Feb 10, 2023
ff40ac0
Rename
tom-andersen Feb 10, 2023
1a5b1c0
Fixup constructor/assignment parameter naming.
tom-andersen Feb 10, 2023
4e5a847
Add Test
tom-andersen Feb 10, 2023
c0f8f9d
Format
tom-andersen Feb 10, 2023
d704a5c
Add test
tom-andersen Feb 10, 2023
41f3e43
Add test
tom-andersen Feb 13, 2023
619e38c
Format
tom-andersen Feb 13, 2023
a8379ab
Recognize NaN filter probelm
tom-andersen Feb 17, 2023
c80337c
Add tests
tom-andersen Feb 24, 2023
0682275
Add tests
tom-andersen Feb 24, 2023
eceb451
Add tests
tom-andersen Feb 24, 2023
1af4623
Test is_valid()
tom-andersen Feb 24, 2023
9bceca3
Add constructor and assignment tests.
tom-andersen Mar 1, 2023
f0f6af1
Rename variable
tom-andersen Mar 2, 2023
833a2e8
Format
tom-andersen Mar 2, 2023
bbf2f4f
Remove extra semicolon
tom-andersen Mar 2, 2023
34ed02b
Firestore COUNT API
tom-andersen Dec 19, 2022
b54a046
[macOS sandbox mode] Application group name mangling for semaphores (…
DellaBitta Dec 21, 2022
2426266
Firestore COUNT implementation (WIP)
tom-andersen Jan 30, 2023
a493a8a
Firestore COUNT implementation (WIP)
tom-andersen Jan 30, 2023
07c1162
Fix linting
tom-andersen Jan 30, 2023
90a152e
Fix linting
tom-andersen Jan 30, 2023
f4ab7fa
Fix linking
tom-andersen Jan 31, 2023
cfebc8a
Disable getSessionId test on emulators. (#1193)
jonsimantov Jan 30, 2023
1c25668
Cleanup
tom-andersen Jan 31, 2023
ee7fbc0
Fix release notes
tom-andersen Jan 31, 2023
73b3276
Format
tom-andersen Jan 31, 2023
c3c8b4e
Fixes from review
tom-andersen Feb 8, 2023
7d878d2
Formatting
tom-andersen Feb 8, 2023
e1d1fe7
Responding to PR comments.
tom-andersen Feb 9, 2023
7c235c7
Add Hash
tom-andersen Feb 10, 2023
fd40bd2
Add Hash
tom-andersen Feb 10, 2023
bc60e1e
Fix copyright year
tom-andersen Feb 10, 2023
6f228f1
Rename
tom-andersen Feb 10, 2023
f239437
Format
tom-andersen Feb 10, 2023
8c35acf
Rename
tom-andersen Feb 10, 2023
5ab942a
Fixup constructor/assignment parameter naming.
tom-andersen Feb 10, 2023
6686fd7
Format
tom-andersen Feb 10, 2023
ddbb47a
Merge branch 'tomandersen/countTest' into tomandersen/countAPI
tom-andersen Mar 2, 2023
422de73
Stub Android Impl
tom-andersen Mar 3, 2023
d403ded
Tomandersen/count test (#1206)
tom-andersen Mar 6, 2023
1ddee51
JNI Count Implementation
tom-andersen Mar 9, 2023
3e5d9c1
Pretty
tom-andersen Mar 9, 2023
062c109
Merge remote-tracking branch 'origin/count' into tomandersen/countAPI
tom-andersen Mar 9, 2023
044da55
Merge branch 'count' into tomandersen/countAPI
tom-andersen Mar 13, 2023
db87160
Fix according PR comments
tom-andersen Mar 17, 2023
d2b34d4
Pretty
tom-andersen Mar 20, 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
6 changes: 6 additions & 0 deletions firestore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ binary_to_array("firestore_resources"

set(android_SRCS
${firestore_resources_source}
src/android/aggregate_query_android.cc
src/android/aggregate_query_android.h
src/android/aggregate_query_snapshot_android.cc
src/android/aggregate_query_snapshot_android.h
src/android/aggregate_source_android.cc
src/android/aggregate_source_android.h
src/android/blob_android.cc
src/android/blob_android.h
src/android/collection_reference_android.cc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
* limitations under the License.
*/

#include "firebase/firestore.h"
#include "firestore_integration_test.h"

#include "firebase/firestore.h"

#include "gtest/gtest.h"

#if defined(__ANDROID__)
#include "firestore/src/android/aggregate_query_android.h"
#include "firestore/src/android/aggregate_query_snapshot_android.h"
#include "firestore/src/android/converter_android.h"
#include "firestore/src/jni/object.h"
#else
#include "firestore/src/main/aggregate_query_snapshot_main.h"
#include "firestore/src/main/converter_main.h"
Expand All @@ -32,14 +36,27 @@ namespace firestore {
class AggregateQuerySnapshotTest : public FirestoreIntegrationTest {
protected:
static AggregateQuerySnapshot TestAggregateQuerySnapshot(
AggregateQuery aggregate_query, const int count) {
api::AggregateQuery aggregateQuery =
GetInternal(&aggregate_query)->aggregate_query_;
return MakePublic(
AggregateQuerySnapshotInternal(std::move(aggregateQuery), count));
}
AggregateQuery aggregate_query, const int count);
};

#if defined(__ANDROID__)
AggregateQuerySnapshot AggregateQuerySnapshotTest::TestAggregateQuerySnapshot(
firebase::firestore::AggregateQuery aggregate_query, const int count) {
AggregateQueryInternal* internal = GetInternal(&aggregate_query);
FirestoreInternal* firestoreInternal = internal->firestore_internal();
jni::Env env = firestoreInternal->GetEnv();
return AggregateQuerySnapshotInternal::Create(env, *internal, count);
}
#else
AggregateQuerySnapshot AggregateQuerySnapshotTest::TestAggregateQuerySnapshot(
firebase::firestore::AggregateQuery aggregate_query, const int count) {
api::AggregateQuery aggregateQuery =
GetInternal(&aggregate_query)->aggregate_query_;
return MakePublic(
AggregateQuerySnapshotInternal(std::move(aggregateQuery), count));
}
#endif // defined(__ANDROID__)

std::size_t AggregateQuerySnapshotHash(const AggregateQuerySnapshot& snapshot) {
return snapshot.Hash();
}
Expand Down Expand Up @@ -135,7 +152,7 @@ TEST_F(
EXPECT_EQ(snapshot_copy_dest.query(), AggregateQuery());
EXPECT_FALSE(snapshot_copy_dest.is_valid());

snapshot_copy_dest;
snapshot_copy_dest = snapshot;

EXPECT_EQ(snapshot_copy_dest.count(), 0);
EXPECT_EQ(snapshot_copy_dest.query(), AggregateQuery());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ TEST_F(
EXPECT_EQ(copied_aggregate_query.query(), Query());
EXPECT_FALSE(copied_aggregate_query.is_valid());

copied_aggregate_query;
copied_aggregate_query = aggregate_query;

EXPECT_EQ(aggregate_query.query(), Query());
EXPECT_FALSE(aggregate_query.is_valid());
Expand Down
75 changes: 75 additions & 0 deletions firestore/src/android/aggregate_query_android.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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/android/aggregate_query_android.h"

#include "firestore/src/android/aggregate_source_android.h"
#include "firestore/src/jni/compare.h"
#include "firestore/src/jni/env.h"
#include "firestore/src/jni/loader.h"
#include "firestore/src/jni/task.h"

namespace firebase {
namespace firestore {
namespace {

using jni::Env;
using jni::Local;
using jni::Method;
using jni::Object;
using jni::Task;

constexpr char kClassName[] =
PROGUARD_KEEP_CLASS "com/google/firebase/firestore/AggregateQuery";
Method<Task> kGet("get",
"(Lcom/google/firebase/firestore/AggregateSource;)"
"Lcom/google/android/gms/tasks/Task;");
Method<Object> kGetQuery("getQuery", "()Lcom/google/firebase/firestore/Query;");
Method<int32_t> kHashCode("hashCode", "()I");

} // namespace

void AggregateQueryInternal::Initialize(jni::Loader& loader) {
loader.LoadClass(kClassName, kGet, kGetQuery, kHashCode);
}

Query AggregateQueryInternal::query() const {
Env env = GetEnv();
Local<Object> query = env.Call(obj_, kGetQuery);
return firestore_->NewQuery(env, query);
}

Future<AggregateQuerySnapshot> AggregateQueryInternal::Get(
AggregateSource aggregate_source) {
Env env = GetEnv();
Local<Object> java_source =
AggregateSourceInternal::Create(env, aggregate_source);
Local<Task> task = env.Call(obj_, kGet, java_source);
return promises_.NewFuture<AggregateQuerySnapshot>(env, AsyncFn::kGet, task);
}

std::size_t AggregateQueryInternal::Hash() const {
Env env = GetEnv();
return env.Call(obj_, kHashCode);
}

bool operator==(const AggregateQueryInternal& lhs,
const AggregateQueryInternal& rhs) {
return jni::EqualityCompareJni(lhs, rhs);
}

} // namespace firestore
} // namespace firebase
78 changes: 78 additions & 0 deletions firestore/src/android/aggregate_query_android.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.
*/

#ifndef FIREBASE_FIRESTORE_SRC_ANDROID_AGGREGATE_QUERY_ANDROID_H_
#define FIREBASE_FIRESTORE_SRC_ANDROID_AGGREGATE_QUERY_ANDROID_H_

#include "firestore/src/android/promise_factory_android.h"
#include "firestore/src/android/query_android.h"
#include "firestore/src/android/wrapper.h"
#include "firestore/src/include/firebase/firestore/aggregate_source.h"

namespace firebase {
namespace firestore {

class AggregateQueryInternal : public Wrapper {
public:
// Each API of AggregateQuery that returns a Future needs to define an enum
// value here. For example, a Future-returning method Foo() relies on the enum
// value kFoo. The enum values are used to identify and manage Future in the
// Firestore Future manager.
enum class AsyncFn {
kGet = 0,
kCount, // Must be the last enum value.
};

static void Initialize(jni::Loader& loader);

AggregateQueryInternal(FirestoreInternal* firestore,
const jni::Object& object)
: Wrapper(firestore, object), promises_(firestore) {}

/**
* @brief Returns the query whose aggregations will be calculated by this
* object.
*/
Query query() const;

/**
* @brief Executes the aggregate query and returns the results as a
* AggregateQuerySnapshot.
*
* @param[in] aggregate_source A value to configure the get behavior.
*
* @return A Future that will be resolved with the results of the
* AggregateQuery.
*/
Future<AggregateQuerySnapshot> Get(AggregateSource aggregate_source);

size_t Hash() const;

private:
PromiseFactory<AsyncFn> promises_;
};

bool operator==(const AggregateQueryInternal& lhs,
const AggregateQueryInternal& rhs);
inline bool operator!=(const AggregateQueryInternal& lhs,
const AggregateQueryInternal& rhs) {
return !(lhs == rhs);
}

} // namespace firestore
} // namespace firebase

#endif // FIREBASE_FIRESTORE_SRC_ANDROID_AGGREGATE_QUERY_ANDROID_H_
79 changes: 79 additions & 0 deletions firestore/src/android/aggregate_query_snapshot_android.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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/android/aggregate_query_snapshot_android.h"

#include "firestore/src/android/aggregate_query_android.h"
#include "firestore/src/jni/compare.h"
#include "firestore/src/jni/env.h"
#include "firestore/src/jni/loader.h"

namespace firebase {
namespace firestore {
namespace {

using jni::Constructor;
using jni::Env;
using jni::Local;
using jni::Method;
using jni::Object;

constexpr char kClassName[] =
PROGUARD_KEEP_CLASS "com/google/firebase/firestore/AggregateQuerySnapshot";
Constructor<Object> kConstructor(
"(Lcom/google/firebase/firestore/AggregateQuery;J)V");
Method<int64_t> kGetCount("getCount", "()J");
Method<Object> kGetQuery("getQuery",
"()Lcom/google/firebase/firestore/AggregateQuery;");
Method<int32_t> kHashCode("hashCode", "()I");

} // namespace

void AggregateQuerySnapshotInternal::Initialize(jni::Loader& loader) {
loader.LoadClass(kClassName, kConstructor, kGetCount, kGetQuery, kHashCode);
}

AggregateQuerySnapshot AggregateQuerySnapshotInternal::Create(
Env& env, AggregateQueryInternal& aggregate_query_internal, int64_t count) {
const Object& arg = aggregate_query_internal.ToJava();
Local<Object> instance = env.New(kConstructor, arg, count);
return aggregate_query_internal.firestore_internal()
->NewAggregateQuerySnapshot(env, instance);
}

AggregateQuery AggregateQuerySnapshotInternal::query() const {
Env env = GetEnv();
Local<Object> query = env.Call(obj_, kGetQuery);
return firestore_->NewAggregateQuery(env, query);
}

int64_t AggregateQuerySnapshotInternal::count() const {
Env env = GetEnv();
return env.Call(obj_, kGetCount);
}

std::size_t AggregateQuerySnapshotInternal::Hash() const {
Env env = GetEnv();
return env.Call(obj_, kHashCode);
}

bool operator==(const AggregateQuerySnapshotInternal& lhs,
const AggregateQuerySnapshotInternal& rhs) {
return jni::EqualityCompareJni(lhs, rhs);
}

} // namespace firestore
} // namespace firebase
58 changes: 58 additions & 0 deletions firestore/src/android/aggregate_query_snapshot_android.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.
*/

#ifndef FIREBASE_FIRESTORE_SRC_ANDROID_AGGREGATE_QUERY_SNAPSHOT_ANDROID_H_
#define FIREBASE_FIRESTORE_SRC_ANDROID_AGGREGATE_QUERY_SNAPSHOT_ANDROID_H_

#include "firestore/src/android/wrapper.h"
#include "firestore/src/include/firebase/firestore/aggregate_query.h"
#include "firestore/src/include/firebase/firestore/aggregate_query_snapshot.h"

namespace firebase {
namespace firestore {

class AggregateQuery;

class AggregateQuerySnapshotInternal : public Wrapper {
public:
using Wrapper::Wrapper;

static void Initialize(jni::Loader& loader);

AggregateQuery query() const;
int64_t count() const;

std::size_t Hash() const;

private:
friend class AggregateQuerySnapshotTest;
static AggregateQuerySnapshot Create(
jni::Env& env,
AggregateQueryInternal& aggregate_query_internal,
int64_t count);
};

bool operator==(const AggregateQuerySnapshotInternal& lhs,
const AggregateQuerySnapshotInternal& rhs);
inline bool operator!=(const AggregateQuerySnapshotInternal& lhs,
const AggregateQuerySnapshotInternal& rhs) {
return !(lhs == rhs);
}

} // namespace firestore
} // namespace firebase

#endif // FIREBASE_FIRESTORE_SRC_ANDROID_AGGREGATE_QUERY_SNAPSHOT_ANDROID_H_
Loading