public sealed class SpannerBatchWriteCommandReference documentation and code samples for the Google.Cloud.Spanner.Data class SpannerBatchWriteCommand.
Represents a batch of mutation groups to be executed against a Spanner database using the BatchWrite RPC. Each group is applied atomically and independently of other groups. Currently only Insert, Update, InsertOrUpdate, and Delete commands are supported in batch write mode.
You can create an instance of SpannerBatchWriteCommand with no initial commands. You can then add commands to a SpannerBatchWriteCommand using the Add(SpannerCommand, params SpannerCommand[]) or Add(IEnumerable<SpannerCommand>) methods.
Namespace
Google.Cloud.Spanner.DataAssembly
Google.Cloud.Spanner.Data.dll
Remarks
The BatchWrite RPC is intended for high-throughput write operations where atomicity is required within each group, but not across groups. This allows for partial success of the batch, where some groups may be committed while others fail.
Properties
CommandTimeout
public int CommandTimeout { get; set; }Gets or sets the wait time before terminating the attempt to execute a command and generating an error. Defaults to the timeout from the connection string.
| Property Value | |
|---|---|
| Type | Description |
int |
|
A value of '0' normally indicates that no timeout should be used (it waits an infinite amount of time). However, if you specify AllowImmediateTimeouts=true in the connection string, '0' will cause a timeout that expires immediately. This is normally used only for testing purposes.
Connection
public SpannerConnection Connection { get; }The connection to the data source. This is never null.
| Property Value | |
|---|---|
| Type | Description |
SpannerConnection |
|
Priority
public Priority Priority { get; set; }The RPC priority to use for this command. The default priority is Unspecified.
| Property Value | |
|---|---|
| Type | Description |
Priority |
|
Tag
public string Tag { get; set; }The statement tag to send to Cloud Spanner for this command.
| Property Value | |
|---|---|
| Type | Description |
string |
|
Methods
Add(SpannerCommand, params SpannerCommand[])
public void Add(SpannerCommand firstCommand, params SpannerCommand[] otherCommands)Adds one or more SpannerCommand instances as a single atomic command group.
| Parameters | |
|---|---|
| Name | Description |
firstCommand |
SpannerCommandThe first command to add to the group. Must not be null. |
otherCommands |
SpannerCommandAdditional commands to add to the same group. May be null. |
| Exceptions | |
|---|---|
| Type | Description |
InvalidOperationException |
One of the commands is not a supported write operation. |
Add(IEnumerable<SpannerCommand>)
public void Add(IEnumerable<SpannerCommand> commands)Adds a collection of SpannerCommand instances as a single atomic command group.
| Parameter | |
|---|---|
| Name | Description |
commands |
IEnumerableSpannerCommandThe collection of commands to add. Must not be null or empty. |
| Exceptions | |
|---|---|
| Type | Description |
ArgumentException |
|
InvalidOperationException |
One of the commands is not a supported write operation. |
ExecuteNonQueryAsync(CancellationToken)
public IAsyncEnumerable<SpannerBatchWriteCommand.BatchWriteResult> ExecuteNonQueryAsync(CancellationToken cancellationToken = default)Executes the batch of command groups asynchronously, returning a stream of responses.
| Parameter | |
|---|---|
| Name | Description |
cancellationToken |
CancellationTokenA cancellation token for the operation. |
| Returns | |
|---|---|
| Type | Description |
IAsyncEnumerableSpannerBatchWriteCommandBatchWriteResult |
An IAsyncEnumerable<T> representing the stream of results. |