async.Future<RunAggregationQueryResponse> runAggregationQuery(
RunAggregationQueryRequest request,
core.String parent, {
core.String? $fields,
}) async {
final _body = convert.json.encode(request);
final _queryParams = <core.String, core.List<core.String>>{
if ($fields != null) 'fields': [$fields],
};
final _url =
'v1/' + core.Uri.encodeFull('$parent') + ':runAggregationQuery';
final _response = await _requester.request(
_url,
'POST',
body: _body,
queryParams: _queryParams,
);
return RunAggregationQueryResponse.fromJson(
_response as core.Map<core.String, core.dynamic>);
}
I got an error here. So I printed out the _response, and it's a list, not a map. So as casting triggers the type error below.
Unhandled exception:
type 'List<dynamic>' is not a subtype of type 'Map<String, dynamic>' in type cast
#0 ProjectsDatabasesDocumentsResource.runAggregationQuery (package:firebaseapis/firestore/v1.dart:1455:19)
<asynchronous suspension>
#1 CRUDDocument.countDocuments (package:firestore_migration/src/crud_document.dart:46:9)
<asynchronous suspension>
#2 Migration_0_0_1.execute (package:firestore_migration/migrations/versions/0_0_1.dart:30:19)
<asynchronous suspension>
#3 main (file:///Users/kimsooyoung/Documents/flutter_packages/firestore_migration/bin/firestore_migration.dart:57:3)
<asynchronous suspension>
I guess it's because I handed over List<Aggregation> when I called the function. Many aggregations, and many responses, I think. Note that it's because of its type, List. I also got the list response when I handed over only one Aggregation.(in a list)
Future<int> countDocuments(StructuredQuery structuredQuery) async {
final request = RunAggregationQueryRequest(
structuredAggregationQuery: StructuredAggregationQuery(
// HERE
aggregations: [
Aggregation(
alias: 'result_1',
count: Count(),
),
Aggregation(
alias: 'result_2',
count: Count(),
),
],
structuredQuery: structuredQuery,
),
);
final result =
await firestoreApi.projects.databases.documents.runAggregationQuery(
request,
rootPath,
);
final count = int.parse(
(result.result?.aggregateFields?['result'])?.integerValue ?? '0');
return count;
}
So, I tried to make a fix pr, but it seems like a generated code, which is not suitable for a manual fix.
I found a bug with
runAggregationQuery
.I got an error here. So I printed out the
_response
, and it's a list, not a map. Soas
casting triggers the type error below.I guess it's because I handed over
List<Aggregation>
when I called the function. Many aggregations, and many responses, I think. Note that it's because of its type, List. I also got the list response when I handed over only one Aggregation.(in a list)So, I tried to make a fix pr, but it seems like a generated code, which is not suitable for a manual fix.
Also, I searched google API document. Below link is in Ruby, but it seems like it returns Enumerable. https://cloud.google.com/ruby/docs/reference/google-cloud-firestore-v1/latest/Google-Cloud-Firestore-V1-Firestore-Client#Google__Cloud__Firestore__V1__Firestore__Client_run_aggregation_query_instance_
Any answer on how to fix this would be appreciated!
References