41
41
import com .google .firestore .v1 .FirestoreGrpc ;
42
42
import com .google .firestore .v1 .RunAggregationQueryRequest ;
43
43
import com .google .firestore .v1 .RunAggregationQueryResponse ;
44
- import com .google .firestore .v1 .RunQueryRequest ;
45
44
import com .google .firestore .v1 .StructuredAggregationQuery ;
46
45
import com .google .firestore .v1 .Value ;
47
-
48
46
import io .grpc .Status ;
49
47
import java .util .ArrayList ;
50
48
import java .util .Arrays ;
@@ -225,12 +223,15 @@ public void onClose(Status status) {
225
223
}
226
224
227
225
public Task <Long > runCountQuery (Target queryTarget ) {
228
- com .google .firestore .v1 .Target .QueryTarget encodedQueryTarget = serializer .encodeQueryTarget (queryTarget );
226
+ com .google .firestore .v1 .Target .QueryTarget encodedQueryTarget =
227
+ serializer .encodeQueryTarget (queryTarget );
229
228
230
- StructuredAggregationQuery .Builder structuredAggregationQuery = StructuredAggregationQuery .newBuilder ();
229
+ StructuredAggregationQuery .Builder structuredAggregationQuery =
230
+ StructuredAggregationQuery .newBuilder ();
231
231
structuredAggregationQuery .setStructuredQuery (encodedQueryTarget .getStructuredQuery ());
232
232
233
- StructuredAggregationQuery .Aggregation .Builder aggregation = StructuredAggregationQuery .Aggregation .newBuilder ();
233
+ StructuredAggregationQuery .Aggregation .Builder aggregation =
234
+ StructuredAggregationQuery .Aggregation .newBuilder ();
234
235
aggregation .setCount (StructuredAggregationQuery .Aggregation .Count .getDefaultInstance ());
235
236
aggregation .setAlias ("zzyzx_agg_alias_count" );
236
237
structuredAggregationQuery .addAggregations (aggregation );
@@ -239,13 +240,14 @@ public Task<Long> runCountQuery(Target queryTarget) {
239
240
request .setParent (encodedQueryTarget .getParent ());
240
241
request .setStructuredAggregationQuery (structuredAggregationQuery );
241
242
242
- return channel .runRpc (FirestoreGrpc .getRunAggregationQueryMethod (), request .build ())
243
+ return channel
244
+ .runRpc (FirestoreGrpc .getRunAggregationQueryMethod (), request .build ())
243
245
.continueWith (
244
246
workerQueue .getExecutor (),
245
247
task -> {
246
248
if (!task .isSuccessful ()) {
247
249
if (task .getException () instanceof FirebaseFirestoreException
248
- && ((FirebaseFirestoreException ) task .getException ()).getCode ()
250
+ && ((FirebaseFirestoreException ) task .getException ()).getCode ()
249
251
== FirebaseFirestoreException .Code .UNAUTHENTICATED ) {
250
252
channel .invalidateToken ();
251
253
}
@@ -255,10 +257,14 @@ public Task<Long> runCountQuery(Target queryTarget) {
255
257
256
258
AggregationResult aggregationResult = response .getResult ();
257
259
Map <String , Value > aggregateFieldsByAlias = aggregationResult .getAggregateFieldsMap ();
258
- hardAssert (aggregateFieldsByAlias .size () == 1 , "aggregateFieldsByAlias.size()==" + aggregateFieldsByAlias .size ());
260
+ hardAssert (
261
+ aggregateFieldsByAlias .size () == 1 ,
262
+ "aggregateFieldsByAlias.size()==" + aggregateFieldsByAlias .size ());
259
263
Value countValue = aggregateFieldsByAlias .get ("zzyzx_agg_alias_count" );
260
264
hardAssert (countValue != null , "countValue == null" );
261
- hardAssert (countValue .getValueTypeCase () == Value .ValueTypeCase .INTEGER_VALUE , "countValue.getValueTypeCase() == " + countValue .getValueTypeCase ());
265
+ hardAssert (
266
+ countValue .getValueTypeCase () == Value .ValueTypeCase .INTEGER_VALUE ,
267
+ "countValue.getValueTypeCase() == " + countValue .getValueTypeCase ());
262
268
return countValue .getIntegerValue ();
263
269
});
264
270
}
0 commit comments