The entity i am querying has a HashKey
& a RangeKey
(Number). When i use batchGetItem
on it, i get the following error:
AWS Error Code: ValidationException, AWS Error Message: One or more parameter values were invalid: Mismatching attribute types between location and schema
Schema:
Table: Daily
Hash Key: CustId (String)
Range Key: Dated (Number)
Data:
CustId : VisioNerdy
Dated : 1329071400000
Code:
List<Key> fkeys = new ArrayList<Key>(); //tableName="Daily", keys=["VisioNerdy"], ranges=[1329071400000] Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>(); for(int i = 0; i < keys.size(); i++) { String key = keys.get(i); if(ranges == null) fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key))); else fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key)) .withRangeKeyElement(new AttributeValue().withS(ranges.get(i).toString()))); } requestItems.put(tableName, new KeysAndAttributes().withKeys(fkeys)); BatchGetItemRequest batchGetItemRequest = new BatchGetItemRequest().withRequestItems(requestItems); BatchGetItemResult result = client.batchGetItem(batchGetItemRequest);
Any clues?
The most likely cause of a failed read or a failed write is throttling. For BatchGetItem , one or more of the tables in the batch request does not have enough provisioned read capacity to support the operation. For BatchWriteItem , one or more of the tables does not have enough provisioned write capacity.
The BatchGetItem operation returns the attributes of one or more items from one or more tables. You identify requested items by primary key. A single operation can retrieve up to 16 MB of data, which can contain as many as 100 items.
The DynamoDBMapper class is the entry point to Amazon DynamoDB. It provides access to a DynamoDB endpoint and enables you to access your data in various tables. It also enables you to perform various create, read, update, and delete (CRUD) operations on items, and run queries and scans against tables.
You have defined the range attribute of your Hash and Range Type Primary Key as type Number, yet prepare its attribute value via withS()
as type String for your request:
fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key))
.withRangeKeyElement(new AttributeValue().withS(ranges.get(i).toString())));
Changing withS(String s) to withN(String s) should remedy your problem accordingly (confusingly both methods require a parameter of type String):
fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key))
.withRangeKeyElement(new AttributeValue().withN(ranges.get(i).toString())));
Admittedly, the implicit weak typing of the DynamoDB data types submission based on String parameters only doesn't exactly ease developing ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With