DynamoDB - Batch Extract

DynamoDB - Batch Extract

Batch retrieval operations return the attributes of one or more elements. These operations usually consist of using the primary key to identify the desired element(s). BatchGetItem operations are subject to the restrictions of individual operations as well as their own unique restrictions.

The following queries in batch searches result in rejection:

  • Make a request for more than 100 items.
  • Make a request that exceeds the bandwidth.

Batch retrieval operations perform partial processing of requests that may exceed limits.

For example, a request to retrieve multiple elements large enough to exceed the limits results in a processing portion of the request and an error message indicating the unprocessed portion. When returning raw items, create a deferral algorithm solution to manage this rather than throttle the tables.

BatchGet operations end up being read-consistent, requiring modification to be strongly read-consistent. They also perform searches in parallel.

Note - the procedure for returning goods. DynamoDB does not sort items. It also does not indicate the absence of the requested items. In addition, these requests consume power units.

All BatchGet operations require RequestItems parameters such as read consistency, attribute names, and primary keys.

Response - A successful operation results in an HTTP 200 response that indicates characteristics such as capacity units used, table processing metrics, and any outstanding items.

Batch Downloads with Java

Using Java in BatchGet operations requires creating an instance of the DynamoDB class, an instance of the TableKeysAndAttributes class that describes the list of primary key values ​​for the items, and passing the TableKeysAndAttributes object to the BatchGetItem method .

The following is an example of a BatchGet operation:

DynamoDB dynamoDB = new DynamoDB ( new AmazonDynamoDBClient ( new ProfileCredentialsProvider ()));     

TableKeysAndAttributes forumTableKeysAndAttributes = new TableKeysAndAttributes ( forumTableName );   
forumTableKeysAndAttributes . addHashOnlyPrimaryKeys ( "Title" , "Updates" , "Product Line 1" ); TableKeysAndAttributes threadTableKeysAndAttributes = new TableKeysAndAttributes ( 
   threadTableName );
threadTableKeysAndAttributes . addHashAndRangePrimaryKeys ( "ForumTitle" , "Topic" , "Product Line 1" , "P1 Thread 1" , "Product Line 1" , "P1 Thread 2" , "Product Line 2" , "P2 Thread 1" ); BatchGetItemOutcome outcome = dynamoDB . batchGetItem (  
   forumTableKeysAndAttributes , threadTableKeysAndAttributes );

for ( String tableName : outcome . getTableItems ( ). keySet ( )) { System . out . println ( "Table items " + tableName ); List < Item > items = outcome . getTableItems (). get ( tableName ); for ( Item item : items ) { System . out . println (   
      item ); } } 

You can consider the following larger example.

Note. The following program can use a previously created data source. Before attempting to execute, acquire the supporting libraries and create the necessary data sources (tables with the required characteristics or other referenced sources).

This program also uses the Eclipse IDE, the AWS Credential File, and the AWS Toolkit in the Eclipse AWS Java Project.