firestore: add BatchWrite

PiperOrigin-RevId: 314471006
pull/600/head
Google APIs 5 years ago committed by Copybara-Service
parent 8be3770465
commit d5fe42c39c
  1. 145
      google/firestore/v1/firestore.proto
  2. 68
      google/firestore/v1/query.proto

@ -132,6 +132,20 @@ service Firestore {
};
}
// Partitions a query by returning partition cursors that can be used to run
// the query in parallel. The returned partition cursors are split points that
// can be used by RunQuery as starting/end points for the query results.
rpc PartitionQuery(PartitionQueryRequest) returns (PartitionQueryResponse) {
option (google.api.http) = {
post: "/v1/{parent=projects/*/databases/*/documents}:partitionQuery"
body: "*"
additional_bindings {
post: "/v1/{parent=projects/*/databases/*/documents/*/**}:partitionQuery"
body: "*"
}
};
}
// Streams batches of document updates and deletes, in order.
rpc Write(stream WriteRequest) returns (stream WriteResponse) {
option (google.api.http) = {
@ -161,6 +175,22 @@ service Firestore {
option (google.api.method_signature) = "parent";
}
// Applies a batch of write operations.
//
// The BatchWrite method does not apply the write operations atomically
// and can apply them out of order. Method does not allow more than one write
// per document. Each write succeeds or fails independently. See the
// [BatchWriteResponse][google.firestore.v1.BatchWriteResponse] for the success status of each write.
//
// If you require an atomically applied set of writes, use
// [Commit][google.firestore.v1.Firestore.Commit] instead.
rpc BatchWrite(BatchWriteRequest) returns (BatchWriteResponse) {
option (google.api.http) = {
post: "/v1/{database=projects/*/databases/*}/documents:batchWrite"
body: "*"
};
}
// Creates a new document.
rpc CreateDocument(CreateDocumentRequest) returns (Document) {
option (google.api.http) = {
@ -189,7 +219,7 @@ message GetDocumentRequest {
bytes transaction = 3;
// Reads the version of the document at the given time.
// This may not be older than 60 seconds.
// This may not be older than 270 seconds.
google.protobuf.Timestamp read_time = 5;
}
}
@ -230,7 +260,7 @@ message ListDocumentsRequest {
bytes transaction = 8;
// Reads documents as they were at the given time.
// This may not be older than 60 seconds.
// This may not be older than 270 seconds.
google.protobuf.Timestamp read_time = 10;
}
@ -346,7 +376,7 @@ message BatchGetDocumentsRequest {
TransactionOptions new_transaction = 5;
// Reads documents as they were at the given time.
// This may not be older than 60 seconds.
// This may not be older than 270 seconds.
google.protobuf.Timestamp read_time = 7;
}
}
@ -460,7 +490,7 @@ message RunQueryRequest {
TransactionOptions new_transaction = 6;
// Reads documents as they were at the given time.
// This may not be older than 60 seconds.
// This may not be older than 270 seconds.
google.protobuf.Timestamp read_time = 7;
}
}
@ -491,6 +521,81 @@ message RunQueryResponse {
int32 skipped_results = 4;
}
// The request for [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery].
message PartitionQueryRequest {
// Required. The parent resource name. In the format:
// `projects/{project_id}/databases/{database_id}/documents`.
// Document resource names are not supported; only database resource names
// can be specified.
string parent = 1 [(google.api.field_behavior) = REQUIRED];
// The query to partition.
oneof query_type {
// A structured query.
// Filters, order bys, limits, offsets, and start/end cursors are not
// supported.
StructuredQuery structured_query = 2;
}
// The desired maximum number of partition points.
// The partitions may be returned across multiple pages of results.
// The number must be strictly positive. The actual number of partitions
// returned may be fewer.
//
// For example, this may be set to one fewer than the number of parallel
// queries to be run, or in running a data pipeline job, one fewer than the
// number of workers or compute instances available.
int64 partition_count = 3;
// The `next_page_token` value returned from a previous call to
// PartitionQuery that may be used to get an additional set of results.
// There are no ordering guarantees between sets of results. Thus, using
// multiple sets of results will require merging the different result sets.
//
// For example, two subsequent calls using a page_token may return:
//
// * cursor B, cursor M, cursor Q
// * cursor A, cursor U, cursor W
//
// To obtain a complete result set ordered with respect to the results of the
// query supplied to PartitionQuery, the results sets should be merged:
// cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W
string page_token = 4;
// The maximum number of partitions to return in this call, subject to
// `partition_count`.
//
// For example, if `partition_count` = 10 and `page_size` = 8, the first call
// to PartitionQuery will return up to 8 partitions and a `next_page_token`
// if more results exist. A second call to PartitionQuery will return up to
// 2 partitions, to complete the total of 10 specified in `partition_count`.
int32 page_size = 5;
}
// The response for [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery].
message PartitionQueryResponse {
// Partition results.
// Each partition is a split point that can be used by RunQuery as a starting
// or end point for the query results. The RunQuery requests must be made with
// the same query supplied to this PartitionQuery request. The partition
// cursors will be ordered according to same ordering as the results of the
// query supplied to PartitionQuery.
//
// For example, if a PartitionQuery request returns partition cursors A and B,
// running the following three queries will return the entire result set of
// the original query:
//
// * query, end_at A
// * query, start_at A, end_at B
// * query, start_at B
repeated Cursor partitions = 1;
// A page token that may be used to request an additional set of results, up
// to the number specified by `partition_count` in the PartitionQuery request.
// If blank, there are no more results.
string next_page_token = 2;
}
// The request for [Firestore.Write][google.firestore.v1.Firestore.Write].
//
// The first request creates a stream, or resumes an existing one from a token.
@ -756,3 +861,35 @@ message ListCollectionIdsResponse {
// A page token that may be used to continue the list.
string next_page_token = 2;
}
// The request for [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite].
message BatchWriteRequest {
// Required. The database name. In the format:
// `projects/{project_id}/databases/{database_id}`.
string database = 1 [(google.api.field_behavior) = REQUIRED];
// The writes to apply.
//
// Method does not apply writes atomically and does not guarantee ordering.
// Each write succeeds or fails independently. You cannot write to the same
// document more than once per request.
repeated Write writes = 2;
// Labels associated with this batch write.
map<string, string> labels = 3;
}
// The response from [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite].
message BatchWriteResponse {
// The result of applying the writes.
//
// This i-th write result corresponds to the i-th write in the
// request.
repeated WriteResult write_results = 1;
// The status of applying the writes.
//
// This i-th write status corresponds to the i-th write in the
// request.
repeated google.rpc.Status status = 2;
}

@ -83,31 +83,55 @@ message StructuredQuery {
// Unspecified. This value must not be used.
OPERATOR_UNSPECIFIED = 0;
// Less than. Requires that the field come first in `order_by`.
// The given `field` is less than the given `value`.
//
// Requires:
//
// * That `field` come first in `order_by`.
LESS_THAN = 1;
// Less than or equal. Requires that the field come first in `order_by`.
// The given `field` is less than or equal to the given `value`.
//
// Requires:
//
// * That `field` come first in `order_by`.
LESS_THAN_OR_EQUAL = 2;
// Greater than. Requires that the field come first in `order_by`.
// The given `field` is greater than the given `value`.
//
// Requires:
//
// * That `field` come first in `order_by`.
GREATER_THAN = 3;
// Greater than or equal. Requires that the field come first in
// `order_by`.
// The given `field` is greater than or equal to the given `value`.
//
// Requires:
//
// * That `field` come first in `order_by`.
GREATER_THAN_OR_EQUAL = 4;
// Equal.
// The given `field` is equal to the given `value`.
EQUAL = 5;
// Contains. Requires that the field is an array.
// The given `field` is an array that contains the given `value`.
ARRAY_CONTAINS = 7;
// In. Requires that `value` is a non-empty ArrayValue with at most 10
// values.
// The given `field` is equal to at least one value in the given array.
//
// Requires:
//
// * That `value` is a non-empty `ArrayValue` with at most 10 values.
// * No other `IN`, `ARRAY_CONTAINS_ANY`, or `NOT_IN`.
IN = 8;
// Contains any. Requires that the field is an array and
// `value` is a non-empty ArrayValue with at most 10 values.
// The given `field` is an array that contains any of the values in the
// given array.
//
// Requires:
//
// * That `value` is a non-empty `ArrayValue` with at most 10 values.
// * No other `IN`, `ARRAY_CONTAINS_ANY`, or `NOT_IN`.
ARRAY_CONTAINS_ANY = 9;
}
@ -121,15 +145,6 @@ message StructuredQuery {
Value value = 3;
}
// The projection of document's fields to return.
message Projection {
// The fields to return.
//
// If empty, all fields are returned. To only return the name
// of the document, use `['__name__']`.
repeated FieldReference fields = 2;
}
// A filter with a single operand.
message UnaryFilter {
// A unary operator.
@ -137,10 +152,10 @@ message StructuredQuery {
// Unspecified. This value must not be used.
OPERATOR_UNSPECIFIED = 0;
// Test if a field is equal to NaN.
// The given `field` is equal to `NaN`.
IS_NAN = 2;
// Test if an expression evaluates to Null.
// The given `field` is equal to `NULL`.
IS_NULL = 3;
}
@ -168,6 +183,15 @@ message StructuredQuery {
Direction direction = 2;
}
// The projection of document's fields to return.
message Projection {
// The fields to return.
//
// If empty, all fields are returned. To only return the name
// of the document, use `['__name__']`.
repeated FieldReference fields = 2;
}
// A sort direction.
enum Direction {
// Unspecified.

Loading…
Cancel
Save