Retrieves the attributes for multiple items from multiple tables using their primary keys.
The maximum number of item attributes that can be retrieved for a single operation is 100. Also, the number of items retrieved is constrained by a 1 MB the size limit. If the response size limit is exceeded or a partial result is returned due to an internal processing failure, Amazon DynamoDB returns an UnprocessedKeys value so you can retry the operation starting with the next item to get.
Amazon DynamoDB automatically adjusts the number of items returned per page to enforce this limit. For example, even if you ask to retrieve 100 items, but each individual item is 50k in size, the system returns 20 items and an appropriate UnprocessedKeys value so you can get the next page of results. If necessary, your application needs its own logic to assemble the pages of results into one set.
C# |
public class BatchGetItemRequest : AmazonWebServiceRequest
All Members | Constructors | Methods | Properties | ||
Icon | Member | Description |
---|---|---|
BatchGetItemRequest()()()() | Initializes a new instance of the BatchGetItemRequest class | |
Equals(Object) | (Inherited from Object.) | |
GetHashCode()()()() | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType()()()() | Gets the type of the current instance. (Inherited from Object.) | |
RequestItems |
A map of the table name and corresponding items to get by primary key. While requesting items, each table name can be invoked only once per
operation.
Constraints: | |
ToString()()()() | Returns a string that represents the current object. (Inherited from Object.) | |
WithRequestItems(array<KeyValuePair<(Of <<'(String, KeysAndAttributes>)>>)>[]()[][]) | Obsolete.
Adds the KeyValuePairs to the RequestItems dictionary.
|
The following examples show how to batch get item from two tables.
This example will construct the collection of keys for the items to retrieve from the first table.
// Construct get-request for first table KeysAndAttributes sampleTableItems = new KeysAndAttributes(); sampleTableItems.WithAttributesToGet("Author", "Title", "Year"); sampleTableItems.WithKeys( new Key() .WithHashKeyElement(new AttributeValue().WithS("Mark Twain")) .WithRangeKeyElement(new AttributeValue().WithS("The Adventures of Tom Sawyer")), new Key() .WithHashKeyElement(new AttributeValue().WithS("Mark Twain")) .WithRangeKeyElement(new AttributeValue().WithS("Adventures of Huckleberry Finn")) );
This example will construct the collection of keys for the items to retrieve from the second table.
// Construct get-request for second table KeysAndAttributes authorsTableItems = new KeysAndAttributes(); // Skip setting AttributesToGet property to retrieve all attributes sampleTableItems.WithKeys( // AuthorsTable only has a hash-key, no range-key new Key().WithHashKeyElement(new AttributeValue().WithS("Mark Twain")), new Key().WithHashKeyElement(new AttributeValue().WithS("Booker Taliaferro Washington")) );
This example will construct the BatchGet request from the two earlier-created collections, will issue the call and in case some items are not processed, will attempt to retrieve the remaining items.
// Create a client AmazonDynamoDBClient client = new AmazonDynamoDBClient(); // Construct table-keys mapping Dictionary<string, KeysAndAttributes> requestItems = new Dictionary<string, KeysAndAttributes>(); requestItems["SampleTable"] = sampleTableItems; requestItems["AuthorsTable"] = authorsTableItems; // Construct request BatchGetItemRequest request = new BatchGetItemRequest { RequestItems = requestItems }; BatchGetItemResult result; do { // Issue request and retrieve items result = client.BatchGetItem(request).BatchGetItemResult; // Iterate through responses Dictionary<string, BatchResponse> responses = result.Responses; foreach (string tableName in responses.Keys) { // Get items for each table BatchResponse tableItems = responses[tableName]; // View items List<Dictionary<string, AttributeValue>> items = tableItems.Items; foreach (Dictionary<string, AttributeValue> item in items) { Console.WriteLine("Item:"); foreach (var keyValuePair in item) { Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]", keyValuePair.Key, keyValuePair.Value.S, keyValuePair.Value.N, string.Join(", ", keyValuePair.Value.SS.ToArray()), string.Join(", ", keyValuePair.Value.SS.ToArray())); } } } // Some items may not have been retrieved! // Set RequestItems to the result's UnprocessedKeys and reissue request request.RequestItems = result.UnprocessedKeys; } while (result.UnprocessedKeys.Count > 0);
Object | ||
AmazonWebServiceRequest | ||
BatchGetItemRequest |