Skip to content

Commit 7d4a66e

Browse files
committed
COUNT API added
1 parent 0fe063e commit 7d4a66e

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 final FirebaseFirestore db;
22+
23+
AggregateDemo(@NonNull FirebaseFirestore db) {
24+
this.db = db;
25+
}
26+
27+
void countBasicQuery() {
28+
AggregateQuery query = db.collection("users").count();
29+
AggregateQuerySnapshot snapshot = query.get(AggregateSource.SERVER_DIRECT).getResult();
30+
assertEqual(snapshot.getCount(), 50);
31+
}
32+
33+
void countLimitNumRowsScanned() {
34+
AggregateQuery query = db.collection("users").limit(11).count();
35+
AggregateQuerySnapshot snapshot = query.get(AggregateSource.SERVER_DIRECT).getResult();
36+
assertEqual(snapshot.getCount(), 11);
37+
}
38+
39+
private static void assertEqual(Object o1, Object o2) {}
40+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
import com.google.android.gms.tasks.Task;
19+
20+
public class AggregateQuery {
21+
22+
AggregateQuery() {}
23+
24+
@NonNull
25+
public Query getQuery() {
26+
throw new RuntimeException("not implemented");
27+
}
28+
29+
@NonNull
30+
public Task<AggregateQuerySnapshot> get(@NonNull AggregateSource source) {
31+
throw new RuntimeException("not implemented");
32+
}
33+
34+
@Override
35+
public int hashCode() {
36+
throw new RuntimeException("not implemented");
37+
}
38+
39+
@Override
40+
public boolean equals(Object obj) {
41+
throw new RuntimeException("not implemented");
42+
}
43+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.Nullable;
18+
import javax.annotation.Nonnull;
19+
20+
public class AggregateQuerySnapshot {
21+
22+
AggregateQuerySnapshot() {}
23+
24+
@Nonnull
25+
public AggregateQuery getQuery() {
26+
throw new RuntimeException("not implemented");
27+
}
28+
29+
@Nullable
30+
public Long getCount() {
31+
throw new RuntimeException("not implemented");
32+
}
33+
34+
@Override
35+
public boolean equals(@Nullable Object obj) {
36+
throw new RuntimeException("not implemented");
37+
}
38+
39+
@Override
40+
public int hashCode() {
41+
throw new RuntimeException("not implemented");
42+
}
43+
44+
@Override
45+
public String toString() {
46+
throw new RuntimeException("not implemented");
47+
}
48+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
public enum AggregateSource {
18+
SERVER_DIRECT,
19+
}

firebase-firestore/src/main/java/com/google/firebase/firestore/Query.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,11 @@ private void validateHasExplicitOrderByForLimitToLast() {
12231223
}
12241224
}
12251225

1226+
@NonNull
1227+
public AggregateQuery count() {
1228+
throw new RuntimeException("not implemented");
1229+
}
1230+
12261231
@Override
12271232
public boolean equals(Object o) {
12281233
if (this == o) {

0 commit comments

Comments
 (0)