Method DeleteRangeAsync
DeleteRangeAsync(String, Object, DeleteRangeOptions, CancellationToken)
Declaration
public Task<DeleteRangeResult> DeleteRangeAsync(string tableName, object partialPrimaryKey, DeleteRangeOptions options = null, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
String | tableName | The name of the table. |
Object | partialPrimaryKey | Partial primary key. Currently must be provided as MapValue representing names and values of the partial primary key fields. |
DeleteRangeOptions | options | (Optional) Options for the DeleteRange
operation. If not specified or null , appropriate defaults
will be used. See DeleteRangeOptions. |
CancellationToken | cancellationToken | (Optional) Cancellation token. |
Returns
Type | Description |
---|---|
Task<DeleteRangeResult> | Task returning DeleteRangeResult. |
Remarks
This operation deletes multiple rows from a table residing on the same shard in an atomic operation. A range of rows is specified using a partial primary key plus a field range based on the portion of the key that is not provided.The partial primary key must contain all of the fields that are in the shard key. For example if a table's primary key is <id, timestamp> and its shard key is the id, it is possible to delete a range of timestamp values for a specific id by providing a key with an id value but no timestamp value and providing a range of timestamp values as FieldRange. If the field range is not provided, the operation will delete all rows matching the partial primary key.
Because this operation can exceed the maximum amount of data
modified in a single operation as specified by
MaxWriteKB or the system limit,
it is possible that it will delete only part of the range of rows
and a continuation key (provided as
ContinuationKey) can be used to
continue the operation. In this case, call
DeleteRangeAsync(String, Object, DeleteRangeOptions, CancellationToken)
in a loop until
ContinuationKey is null
as
shown in the example below.
Alternatively, you can call
GetDeleteRangeAsyncEnumerable(String, Object, DeleteRangeOptions, CancellationToken)
and iterate over resulting IAsyncEnumerable<T>.
Note that when the DeleteRange operation requires multiple calls with the continuation key or iteration with GetDeleteRangeAsyncEnumerable(String, Object, DeleteRangeOptions, CancellationToken), the operation is no longer atomic as a whole, although each call to DeleteRangeAsync(String, Object, DeleteRangeOptions, CancellationToken) and each iteration of the loop over GetDeleteRangeAsyncEnumerable(String, Object, DeleteRangeOptions, CancellationToken) is still atomic.
Examples
Executing DeleteRange operation on table with schema myTable( storeId LONG, itemId LONG, itemName STRING, PRIMARY KEY( SHARD(storeId), itemId)). This operation will delete all items for a given store because we do not provide the field range. This operation is performed in a loop using the continuation key to allow deleting large quantity of the table rows. var partialPrimaryKey = new MapValue
{
["storeId"] = 50
};
var options = new DeleteRangeOptions();
do
{
var result = await client.DeleteRangeAsync("myTable",
partialPrimaryKey, options);
Console.WriteLine($"Deleted {result.DeletedCount} row(s)");
options.ContinuationKey = result.ContinuationKey;
}
while(options.ContinuationKey != null);
Exceptions
Type | Condition |
---|---|
ArgumentException | If
tableName is null or invalid or
partialPrimaryKey is null or invalid or
options contains invalid values. |
TimeoutException | Operation has timed out. |
InvalidOperationException | The table or the service is not in a valid state to perform this operation. |
NoSQLException | NoSQLException or one of its subclasses is thrown if operation cannot be performed for any other reason. See documentation for corresponding subclass of NoSQLException. |
See Also
DeleteRangeAsync(String, Object, FieldRange, CancellationToken)
Declaration
public Task<DeleteRangeResult> DeleteRangeAsync(string tableName, object partialPrimaryKey, FieldRange fieldRange, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
String | tableName | The name of the table. |
Object | partialPrimaryKey | Partial primary key. Currently must be provided as MapValue representing names and values of the partial primary key fields. |
FieldRange | fieldRange | Field range for the DeleteRange operation, see FieldRange. |
CancellationToken | cancellationToken | (Optional) Cancellation token. |
Returns
Type | Description |
---|---|
Task<DeleteRangeResult> | Task returning DeleteRangeResult. |
Remarks
fieldRange
instead of the options
and can be used when no other options are required.
Examples
Executing DeleteRange operation on table with schema myTable( storeId LONG, itemId LONG, itemName STRING, PRIMARY KEY( SHARD(storeId), itemId)). This operation will delete a range of items in a given store which should not be large. var result = await client.DeleteRangeAsync(
"myTable",
new MapValue // partial primary key
{
["storeId"] = 50
},
new FieldRange("itemId")
{
StartsWith = 1000,
EndsBefore = 1010
});
Console.WriteLine($"Deleted {result.DeletedCount} row(s)");
Exceptions
Type | Condition |
---|---|
ArgumentException | If
tableName is null or invalid or
partialPrimaryKey is null or invalid or
fieldRange is invalid.
|
TimeoutException | Operation has timed out. |
InvalidOperationException | The table or the service is not in a valid state to perform this operation. |
NoSQLException | NoSQLException or one of its subclasses is thrown if operation cannot be performed for any other reason. See documentation for corresponding subclass of NoSQLException. |
See Also
DeleteRangeAsync(String, Object, CancellationToken)
Declaration
public Task<DeleteRangeResult> DeleteRangeAsync(string tableName, object partialPrimaryKey, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
String | tableName | The name of the table. |
Object | partialPrimaryKey | Partial primary key. Currently must be provided as MapValue representing names and values of the partial primary key fields. |
CancellationToken | cancellationToken | Cancellation token. |
Returns
Type | Description |
---|---|
Task<DeleteRangeResult> | Task returning DeleteRangeResult. |
Remarks
Exceptions
Type | Condition |
---|---|
ArgumentException | If
tableName is null or invalid or
partialPrimaryKey is null or invalid.
|
TimeoutException | Operation has timed out. |
InvalidOperationException | The table or the service is not in a valid state to perform this operation. |
NoSQLException | NoSQLException or one of its subclasses is thrown if operation cannot be performed for any other reason. See documentation for corresponding subclass of NoSQLException. |