-
Notifications
You must be signed in to change notification settings - Fork 51
Firestore Aggregate Count Implementation and Tests #659
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
215b366
AggregateQuery count implementation and tests
tom-andersen 4212b66
Implement AggregateQuery Count with tests
tom-andersen c2881cc
Add comments and prune imports
tom-andersen 4dd0afa
Merge remote-tracking branch 'origin/main' into tomandersen/count
tom-andersen bac6eab
Fix comments
tom-andersen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
|
|
||
|
|
||
| using Firebase.Firestore.Internal; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Firebase.Firestore { | ||
| /// <summary> | ||
| /// A query that calculates aggregations over an underlying query. | ||
| /// </summary> | ||
| public sealed class AggregateQuery | ||
| { | ||
| private readonly AggregateQueryProxy _proxy; | ||
| private readonly FirebaseFirestore _firestore; | ||
|
|
||
| internal AggregateQuery(AggregateQueryProxy proxy, FirebaseFirestore firestore) { | ||
| _proxy = Util.NotNull(proxy); | ||
| _firestore = Util.NotNull(firestore); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The query of aggregations that will be calculated. | ||
| /// </summary> | ||
| public Query Query => new Query(_proxy.query(), _firestore); | ||
|
|
||
| /// <summary> | ||
| /// Asynchronously executes the query. | ||
| /// </summary> | ||
| /// <param name="source">The source from which to acquire the aggregate results.</param> | ||
| /// <returns>The results of the query.</returns> | ||
| public Task<AggregateQuerySnapshot> GetSnapshotAsync(AggregateSource source) { | ||
| var sourceProxy = Enums.Convert(source); | ||
| return Util.MapResult(_proxy.GetAsync(sourceProxy), | ||
| taskResult => { return new AggregateQuerySnapshot(taskResult, _firestore); }); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override bool Equals(object obj) => Equals(obj as Query); | ||
dconeybe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// <summary> | ||
| /// Compares this aggregate query with another for equality. | ||
| /// </summary> | ||
| /// <param name="other">The aggregate query to compare this one with.</param> | ||
| /// <returns><c>true</c> if this aggregate query is equal to <paramref name="other"/>; | ||
| /// <c>false</c> otherwise.</returns> | ||
| public bool Equals(AggregateQuery other) => other != null && FirestoreCpp.AggregateQueryEquals(_proxy, other._proxy); | ||
|
|
||
| /// <inheritdoc /> | ||
| public override int GetHashCode() { | ||
| return FirestoreCpp.AggregateQueryHashCode(_proxy); | ||
| } | ||
| } | ||
| } | ||
dconeybe marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright 2017 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 | ||
| // | ||
| // https://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. | ||
|
|
||
| using Firebase.Firestore.Internal; | ||
|
|
||
| namespace Firebase.Firestore { | ||
| /// <summary> | ||
| /// The results of executing an <c>AggregateQuerySnapshot</c>. | ||
| /// </summary> | ||
| public sealed class AggregateQuerySnapshot { | ||
dconeybe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private readonly AggregateQuerySnapshotProxy _proxy; | ||
| private readonly FirebaseFirestore _firestore; | ||
|
|
||
| internal AggregateQuerySnapshot(AggregateQuerySnapshotProxy proxy, FirebaseFirestore firestore) { | ||
| _proxy = Util.NotNull(proxy); | ||
| _firestore = Util.NotNull(firestore); | ||
| } | ||
| /// <summary> | ||
| /// Returns the query that was executed to produce this result. | ||
| /// </summary> | ||
| public AggregateQuery Query { | ||
| get { | ||
| return new AggregateQuery(_proxy.query(), _firestore); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns the number of documents in the result set of the underlying query. | ||
| /// </summary> | ||
| public long Count { | ||
| get { | ||
| return _proxy.count(); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override bool Equals(object obj) => Equals(obj as AggregateQuerySnapshot); | ||
|
|
||
| /// <summary> | ||
| /// Compares this aggregate snapshot with another for equality. | ||
| /// </summary> | ||
| /// <param name="other">The aggregate snapshot to compare this one with.</param> | ||
| /// <returns><c>true</c> if this aggregate snapshot is equal to <paramref name="other"/>; | ||
| /// <c>false</c> otherwise.</returns> | ||
| public bool Equals(AggregateQuerySnapshot other) => | ||
| other != null && FirestoreCpp.AggregateQuerySnapshotEquals(_proxy, other._proxy); | ||
|
|
||
| /// <inheritdoc /> | ||
| public override int GetHashCode() { | ||
| return FirestoreCpp.AggregateQuerySnapshotHashCode(_proxy); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // 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 | ||
| // | ||
| // https://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. | ||
|
|
||
| namespace Firebase.Firestore { | ||
|
|
||
| /// <summary> | ||
| /// The sources from which an <see cref="AggregateQuery.GetSnapshotAsync"/> can retrieve its | ||
| /// results. | ||
| /// </summary> | ||
| public enum AggregateSource { | ||
| /// Perform the aggregation on the server and download the result. | ||
| /// The result received from the server is presented, unaltered, without | ||
| /// considering any local state. That is, documents in the local cache are not | ||
| /// taken into consideration, neither are local modifications not yet | ||
| /// synchronized with the server. Previously-downloaded results, if any, are | ||
| /// not used: every request using this source necessarily involves a round trip | ||
| /// to the server. | ||
| /// | ||
| /// The AggregateQuery will fail if the server cannot be reached, such as if | ||
| /// the client is offline. | ||
| Server, | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.