@@ -19,6 +19,7 @@ package google.firestore.v1;
19
19
import "google/api/annotations.proto" ;
20
20
import "google/api/client.proto" ;
21
21
import "google/api/field_behavior.proto" ;
22
+ import "google/firestore/v1/aggregation_result.proto" ;
22
23
import "google/firestore/v1/common.proto" ;
23
24
import "google/firestore/v1/document.proto" ;
24
25
import "google/firestore/v1/query.proto" ;
@@ -133,6 +134,29 @@ service Firestore {
133
134
};
134
135
}
135
136
137
+ // Runs an aggregation query.
138
+ //
139
+ // Rather than producing [Document][google.firestore.v1.Document] results like [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery],
140
+ // this API allows running an aggregation to produce a series of
141
+ // [AggregationResult][google.firestore.v1.AggregationResult] server-side.
142
+ //
143
+ // High-Level Example:
144
+ //
145
+ // ```
146
+ // -- Return the number of documents in table given a filter.
147
+ // SELECT COUNT(*) FROM ( SELECT * FROM k where a = true );
148
+ // ```
149
+ rpc RunAggregationQuery (RunAggregationQueryRequest ) returns (stream RunAggregationQueryResponse ) {
150
+ option (google.api.http ) = {
151
+ post : "/v1/{parent=projects/*/databases/*/documents}:runAggregationQuery"
152
+ body : "*"
153
+ additional_bindings {
154
+ post : "/v1/{parent=projects/*/databases/*/documents/*/**}:runAggregationQuery"
155
+ body : "*"
156
+ }
157
+ };
158
+ }
159
+
136
160
// Partitions a query by returning partition cursors that can be used to run
137
161
// the query in parallel. The returned partition cursors are split points that
138
162
// can be used by RunQuery as starting/end points for the query results.
@@ -522,6 +546,62 @@ message RunQueryResponse {
522
546
int32 skipped_results = 4 ;
523
547
}
524
548
549
+ // The request for [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery].
550
+ message RunAggregationQueryRequest {
551
+ // Required. The parent resource name. In the format:
552
+ // `projects/{project_id}/databases/{database_id}/documents` or
553
+ // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
554
+ // For example:
555
+ // `projects/my-project/databases/my-database/documents` or
556
+ // `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
557
+ string parent = 1 [(google.api.field_behavior ) = REQUIRED ];
558
+
559
+ // The query to run.
560
+ oneof query_type {
561
+ // An aggregation query.
562
+ StructuredAggregationQuery structured_aggregation_query = 2 ;
563
+ }
564
+
565
+ // The consistency mode for the query, defaults to strong consistency.
566
+ oneof consistency_selector {
567
+ // Run the aggregation within an already active transaction.
568
+ //
569
+ // The value here is the opaque transaction ID to execute the query in.
570
+ bytes transaction = 4 ;
571
+
572
+ // Starts a new transaction as part of the query, defaulting to read-only.
573
+ //
574
+ // The new transaction ID will be returned as the first response in the
575
+ // stream.
576
+ TransactionOptions new_transaction = 5 ;
577
+
578
+ // Executes the query at the given timestamp.
579
+ //
580
+ // Requires:
581
+ //
582
+ // * Cannot be more than 270 seconds in the past.
583
+ google.protobuf.Timestamp read_time = 6 ;
584
+ }
585
+ }
586
+
587
+ // The response for [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery].
588
+ message RunAggregationQueryResponse {
589
+ // A single aggregation result.
590
+ //
591
+ // Not present when reporting partial progress or when the query produced
592
+ // zero results.
593
+ AggregationResult result = 1 ;
594
+
595
+ // The transaction that was started as part of this request.
596
+ //
597
+ // Only present on the first response when the request requested to start
598
+ // a new transaction.
599
+ bytes transaction = 2 ;
600
+
601
+ // The time at which the aggregate value is valid for.
602
+ google.protobuf.Timestamp read_time = 3 ;
603
+ }
604
+
525
605
// The request for [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery].
526
606
message PartitionQueryRequest {
527
607
// Required. The parent resource name. In the format:
0 commit comments