5

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?

4
  • Could you please add your (eventually condensed) schema and the code fragment executing your query to ease analysis? Thanks! Commented Feb 13, 2012 at 9:29
  • 1
    Have edited the question to include them. Thanks! Commented Feb 14, 2012 at 2:50
  • You have "if(ranges == null)" but if a Table has a range key, a value is required; you can't omit it. Commented Feb 14, 2012 at 4:49
  • @AdamVandenberg This is a generic code that works for all Tables without or with range key. In this case, if(ranges == null) will not be executed, since "Daily" is executed with "ranges=[1329071400000]". Commented Feb 14, 2012 at 7:05

1 Answer 1

8

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 ;)

Sign up to request clarification or add additional context in comments.

1 Comment

@Mani: Glad I could help - could you please upvote and especially accept the answer, if it solved your problem? This is desired here, both to get your issue out of sight and make room for open problems of others, as well as ensuring users stay motivated to help each other ;) See the FAQ What is reputation? for details - thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.