|
| 1 | +// Copyright 2022 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package com.google.firebase.firestore; |
| 16 | + |
| 17 | +import androidx.annotation.NonNull; |
| 18 | + |
| 19 | +final class AggregateDemo { |
| 20 | + |
| 21 | + private AggregateDemo() { |
| 22 | + } |
| 23 | + |
| 24 | + public void Demo0_NormalQuery(FirebaseFirestore db) { |
| 25 | + CollectionReference query = db.collection("games/halo/players"); |
| 26 | + QuerySnapshot snapshot = query.get().getResult(); |
| 27 | + assertEqual(snapshot.size(), 5_000_000); |
| 28 | + } |
| 29 | + |
| 30 | + public void Demo1_CountOfDocumentsInACollection(FirebaseFirestore db) { |
| 31 | + AggregateQuery countQuery = db.collection("games/halo/players").count(); |
| 32 | + AggregateQuerySnapshot snapshot = countQuery.get(AggregateSource.SERVER_DIRECT).getResult(); |
| 33 | + assertEqual(snapshot.getCount(), 5_000_000); |
| 34 | + } |
| 35 | + |
| 36 | + public void Demo2_CountOfDocumentsInACollectionWithFilter(FirebaseFirestore db) { |
| 37 | + Query query = db.collection("games/halo/players").where(Filter.equalTo("online", true)); |
| 38 | + AggregateQuery countQuery = query.count(); |
| 39 | + AggregateQuerySnapshot snapshot = countQuery.get(AggregateSource.SERVER_DIRECT).getResult(); |
| 40 | + assertEqual(snapshot.getCount(), 2000); |
| 41 | + } |
| 42 | + |
| 43 | + public void Demo2_CountOfDocumentsInACollectionWithLimit(FirebaseFirestore db) { |
| 44 | + Query query = db.collection("games/halo/players").limit(9000); |
| 45 | + AggregateQuery countQuery = query.count(); |
| 46 | + AggregateQuerySnapshot snapshot = countQuery.get(AggregateSource.SERVER_DIRECT).getResult(); |
| 47 | + assertEqual(snapshot.getCount(), 9000); |
| 48 | + } |
| 49 | + |
| 50 | + private static void assertEqual(Object o1, Object o2) {} |
| 51 | +} |
0 commit comments